Skip to content

Commit

Permalink
shortcodes and advanced parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
zgabievi committed Apr 6, 2016
1 parent 9c7ccd7 commit d0015ca
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 16 deletions.
4 changes: 4 additions & 0 deletions _bem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
@import "functions/get-block";
@import "functions/has-state";
@import "functions/has-pseudo";
@import "functions/str-replace";
@import "functions/is-modifier";
@import "functions/is-element";
@import "functions/is-block";
@import "functions/math-min";
@import "functions/explode";
@import "functions/implode";
@import "functions/splice";

// Helpers
@import "helpers/block-selector";
Expand All @@ -31,6 +33,8 @@
@import "helpers/theme-selector";
@import "helpers/scope-selector";
@import "helpers/state-selector";
@import "helpers/pseudo-selector";
@import "helpers/states-selector";
@import "helpers/hack-selector";
@import "helpers/test-selector";

Expand Down
11 changes: 10 additions & 1 deletion _config.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ $bem: (
'test': "qa",
'theme': "t",
'utility': "u",
),
'shortcodes': (
'ab': ('before', 'after')
)
) !default;

Expand Down Expand Up @@ -110,4 +113,10 @@ $bem-theme-namespace: map-get(map-get($bem, 'namespace'), 'theme') !default;
///
/// @type String

$bem-utility-namespace: map-get(map-get($bem, 'namespace'), 'utility') !default;
$bem-utility-namespace: map-get(map-get($bem, 'namespace'), 'utility') !default;

/// Shortcodes list for parsing.
///
/// @type List

$bem-shortcodes: map-get($bem, 'shortcodes') !default;
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-bem",
"version": "2.4.6",
"version": "2.5.0",
"main": "_bem.scss",
"description": "Collection of BEM Mixins & Helpers",
"authors": [
Expand Down
31 changes: 31 additions & 0 deletions functions/_splice.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@charset "UTF-8";

/// Unset item from list.
///
/// @access private
///
/// @param {List} $list - List from where will be removed
/// @param {String} $value - What to be removed
/// @param {Boolean} $recursive [false] - List is nested or not
///
/// @returns {List}
@function splice($list, $value, $recursive: false) {
$result: ();

//
@for $i from 1 through length($list) {

//
@if type-of(nth($list, $i)) == list and $recursive {
$result: append($result, remove(nth($list, $i), $value, $recursive));
}

//
@else if nth($list, $i) != $value {
$result: append($result, nth($list, $i));
}
}

@return $result;
}
22 changes: 22 additions & 0 deletions functions/_str-replace.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@charset "UTF-8";

/// Replace string with another string.
///
/// @access private
///
/// @param {String} $string - String from which will be replaced
/// @param {String} $search - String which will be removed
/// @param {String} $replace [''] - String which will be placed
///
/// @returns {String}
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);

//
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}

@return $string;
}
8 changes: 7 additions & 1 deletion helpers/_element-selector.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// @access private
///
/// @param {String} $element - Name of element that will come after ".[block]__"
/// @param {Boolean} $nested - If element is nested with another element
/// @param {Boolean} $nested [false] - If element is nested with another element
///
/// @returns {String} - .[block]__[element]
///
Expand Down Expand Up @@ -61,3 +61,9 @@
@function e-selector($element) {
@return element-selector($element);
}

/// @alias element-selector

@function ee-selector($element) {
@return element-selector($element, true);
}
73 changes: 73 additions & 0 deletions helpers/_pseudo-selector.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@charset "UTF-8";

/// Pseudo selector with end of first-of-type.
///
/// @access private
///
/// @returns {String} - &:first-of-type
///
/// @see {mixin} first

@function first-selector() {
@return unquote("&:first-of-type");
}

/// Pseudo selector with end of last-of-type.
///
/// @access private
///
/// @returns {String} - &:last-of-type
///
/// @see {mixin} last

@function last-selector() {
@return unquote("&:last-of-type");
}

/// Pseudo selector with end of nth-child(even).
///
/// @access private
///
/// @returns {String} - &:nth-child(even)
///
/// @see {mixin} even

@function even-selector() {
@return unquote("&:nth-child(even)");
}

/// Pseudo selector with end of nth-child(odd).
///
/// @access private
///
/// @returns {String} - &:nth-child(odd)
///
/// @see {mixin} odd

@function odd-selector() {
@return unquote("&:nth-child(odd)");
}

/// Pseudo selector with end of before.
///
/// @access private
///
/// @returns {String} - &::before
///
/// @see {mixin} before

@function before-selector() {
@return unquote("&::before");
}

/// Pseudo selector with end of after.
///
/// @access private
///
/// @returns {String} - &::after
///
/// @see {mixin} after

@function after-selector() {
@return unquote("&::after");
}
92 changes: 92 additions & 0 deletions helpers/_states-selector.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@charset "UTF-8";

/// Pseudo selector with end of hover.
///
/// @access private
///
/// @returns {String} - &:hover
///
/// @see {mixin} hover

@function hover-selector() {
@return unquote("&:hover");
}

/// Pseudo selector with end of focus.
///
/// @access private
///
/// @returns {String} - &:focus
///
/// @see {mixin} focus

@function focus-selector() {
@return unquote("&:focus");
}

/// Pseudo selector with end of active.
///
/// @access private
///
/// @returns {String} - &:active
///
/// @see {mixin} active

@function active-selector() {
@return unquote("&:active");
}

/// Pseudo selector with end of checked.
///
/// @access private
///
/// @returns {String} - &:checked
///
/// @see {mixin} checked

@function checked-selector() {
@return unquote("&:checked");
}

/// Selector with state of disabled.
///
/// @access private
///
/// @returns {String} - &[disabled]
///
/// @see {mixin} disabled

@function disabled-selector() {
@return unquote("&[disabled]");
}

/// Selector with state of readonly.
///
/// @access private
///
/// @returns {String} - &[readonly]
///
/// @see {mixin} readonly

@function readonly-selector() {
@return unquote("&[readonly]");
}

/// Selector with state of contenteditable.
///
/// @access private
///
/// @returns {String} - &[contenteditable='true']
///
/// @see {mixin} contenteditable

@function contenteditable-selector() {
@return unquote("&[contenteditable='true']");
}


/// @alias contenteditable-selector

@function editable-selector() {
@return contenteditable-selector();
}
2 changes: 1 addition & 1 deletion mixins/_element.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// Element selector, that is generated from parent block
///
/// @param {String} $element - Name of element that will come after ".[block]__"
/// @param {Boolean} $nested - If element is nested with other element
/// @param {Boolean} $nested [false] - If element is nested with other element
///
/// @example scss - Usage
/// @include block('list') {
Expand Down
Loading

0 comments on commit d0015ca

Please sign in to comment.