Skip to content

Commit

Permalink
Documentation update and new feature for <at> relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
gabiezur committed Dec 4, 2016
1 parent b2b0f8b commit 499689c
Show file tree
Hide file tree
Showing 53 changed files with 1,538 additions and 598 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.scss]
indent_style = space
indent_size = 2
16 changes: 10 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
.idea
.sass-cache
.sassdocrc

node_modules
sassdoc
.idea/
.sass-cache/
test/.sass-cache/
node_modules/
gh-pages/
coverage/

**/.DS_Store
.sassdocrc
/style.scss
/style.css
*.map

yarn.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sass-bem

> **Important!** Changed `with` mixin and it will now get siblings with `~` sign. If you want to get first sibling with `+` sign, you can use `next` mixin.
> **Please upgrade to version 2.6.0**, we have some great features. Thanks to @szalonna and @MartinN3 resolved issue in documentation and updated some mixins.
[![Bower](https://img.shields.io/bower/v/zgabievi/sass-bem.svg?style=flat-square)](http://bower.io/search/?q=sass-bem)
[![NPM](https://img.shields.io/npm/v/sass-bem.svg?style=flat-square)](https://www.npmjs.com/package/sass-bem)
Expand Down
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.5.3",
"version": "2.6.0",
"main": "_bem.scss",
"description": "Amazing package for sass to write bem classes, with namespaces and more advanced features.",
"authors": [
Expand Down
63 changes: 28 additions & 35 deletions functions/_bem-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,32 @@
/// @returns {Number} - Index of separators

@function bem-index($string) {
$e_index: null;
$m_index: null;

//
@if (str-index($string, unquote("#{$bem-element-separator}")) != null) {
$e_index: str-index($string, unquote("#{$bem-element-separator}"));
}

//
@if (str-index($string, unquote("#{$bem-modifier-separator}")) != null) {
$m_index: str-index($string, unquote("#{$bem-modifier-separator}"));
}

//
@if (str-index($string, ".is") != null) {
$m_index: str-index($string, ".is");
}

//
@if (str-index($string, ".js") != null) {
$m_index: str-index($string, ".js");
}

//
@if (str-index($string, ".has") != null) {
$m_index: str-index($string, ".has");
}

//
@if (str-index($string, ":") != null) {
$m_index: str-index($string, ":");
}

//
@return math-min($e_index, $m_index, 0);
$e_index: null;
$m_index: null;

@if (str-index($string, unquote("#{$bem-element-separator}")) != null) {
$e_index: str-index($string, unquote("#{$bem-element-separator}"));
}

@if (str-index($string, unquote("#{$bem-modifier-separator}")) != null) {
$m_index: str-index($string, unquote("#{$bem-modifier-separator}"));
}

@if (str-index($string, ".is") != null) {
$m_index: str-index($string, ".is");
}

@if (str-index($string, ".js") != null) {
$m_index: str-index($string, ".js");
}

@if (str-index($string, ".has") != null) {
$m_index: str-index($string, ".has");
}

@if (str-index($string, ":") != null) {
$m_index: str-index($string, ":");
}

@return math-min($e_index, $m_index, 0);
}
43 changes: 20 additions & 23 deletions functions/_explode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@
/// @returns {List} - List of exploded string

@function explode($string, $separator) {
$list: ();
$length: str-length($string);

//
@for $i from 1 through $length {
$index: str-index($string, $separator);

//
@if str-length($string) >= 1 and $index == null {
$list: append($list, $string);
$string: '';
}

//
@if type-of($index) == number {
$each: str-slice($string, 0, ($index - 1));
$list: append($list, $each);
$string: str-slice($string, ($index + 1), $length);
}
}

@return $list;
}
$list: ();
$length: str-length($string);

@for $i from 1 through $length {
$index: str-index($string, $separator);

@if str-length($string) >= 1 and $index == null {
$list: append($list, $string);
$string: '';
}

@if type-of($index) == number {
$each: str-slice($string, 0, ($index - 1));
$list: append($list, $each);
$string: str-slice($string, ($index + 1), $length);
}
}

@return $list;
}
19 changes: 8 additions & 11 deletions functions/_get-block.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
/// @returns {String} - Block element

@function get-block($selector) {
$block: str-slice($selector, 2, bem-index($selector) - 1);

//
@while (is-block($block) == false) {

//
$block: str-slice($block, 0, bem-index($block) - 1);
}

@return $block;
}
$block: str-slice($selector, 2, bem-index($selector) - 1);

@while (is-block($block) == false) {
$block: str-slice($block, 0, bem-index($block) - 1);
}

@return $block;
}
4 changes: 2 additions & 2 deletions functions/_has-pseudo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
/// @returns {Boolean}
@function has-pseudo($selector) {
@return str-index($selector, ":") != null;
}
@return str-index($selector, ":") != null;
}
12 changes: 6 additions & 6 deletions functions/_has-state.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
/// @returns {Boolean}
@function has-state($selector) {
$separator_is: unquote(".is#{$bem-state-separator}");
$separator_js: unquote(".js#{$bem-state-separator}");
$separator_has: unquote(".has#{$bem-state-separator}");

@return str-index($selector, $separator_is) != null or str-index($selector, $separator_js) != null or str-index($selector, $separator_has) != null;
}
$separator_is: unquote(".is#{$bem-state-separator}");
$separator_js: unquote(".js#{$bem-state-separator}");
$separator_has: unquote(".has#{$bem-state-separator}");
@return str-index($selector, $separator_is) != null or str-index($selector, $separator_js) != null or str-index($selector, $separator_has) != null;
}
33 changes: 14 additions & 19 deletions functions/_implode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@
/// @returns {String} - Imploded list

@function implode($list, $glue: '', $is-nested: false) {
$result: null;

//
@for $i from 1 through length($list) {
$e: nth($list, $i);

//
@if type-of($e) == list {
$result: unquote("#{$result}#{implode($e, $glue, true)}");
}

//
@else {
$result: if($i != length($list) or $is-nested, unquote("#{$result}#{$e}#{$glue}"), unquote("#{$result}#{$e}"));
}
}

@return $result;
}
$result: null;

@for $i from 1 through length($list) {
$e: nth($list, $i);

@if type-of($e) == list {
$result: unquote("#{$result}#{implode($e, $glue, true)}");
} @else {
$result: if($i != length($list) or $is-nested, unquote("#{$result}#{$e}#{$glue}"), unquote("#{$result}#{$e}"));
}
}

@return $result;
}
2 changes: 1 addition & 1 deletion functions/_is-block.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
/// @returns {Boolean}
@function is-block($selector) {
@return (not is-element($selector) and not is-modifier($selector) and not has-state($selector) and not has-pseudo($selector));
@return not is-element($selector) and not is-modifier($selector) and not has-state($selector) and not has-pseudo($selector);
}
7 changes: 4 additions & 3 deletions functions/_is-element.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/// @returns {Boolean}
@function is-element($selector) {
$separator: unquote("#{$bem-element-separator}");
@return str-index($selector, $separator) != null;
}
$separator: unquote("#{$bem-element-separator}");

@return str-index($selector, $separator) != null;
}
7 changes: 4 additions & 3 deletions functions/_is-modifier.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/// @returns {Boolean}
@function is-modifier($selector) {
$separator: unquote("#{$bem-modifier-separator}");
@return str-index($selector, $separator) != null;
}
$separator: unquote("#{$bem-modifier-separator}");

@return str-index($selector, $separator) != null;
}
45 changes: 20 additions & 25 deletions functions/_math-min.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,26 @@
///
/// @param {String} $a - First number to be checked
/// @param {String} $n - Second number to be checked
/// @param {String} $default - Default number to be returned if min wasn't found
/// @param {String} $default [0] - Default number to be returned if min wasn't found
///
/// @returns {Number} - Minimum number from two of them

@function math-min($a, $b, $default) {
$min: $default;

//
@if ($a == null) {

//
@if ($b != null) {
$min: $b;
}
} @else if ($b == null) {
$min: $a;
} @else {

//
@if ($a <= $b) {
$min: $a;
} @else {
$min: $b;
}
}

@return $min;
}
@function math-min($a, $b, $default: 0) {
$min: $default;

@if ($a == null) {
@if ($b != null) {
$min: $b;
}
} @else if ($b == null) {
$min: $a;
} @else {
@if ($a <= $b) {
$min: $a;
} @else {
$min: $b;
}
}

@return $min;
}
30 changes: 12 additions & 18 deletions functions/_splice.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@
/// @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;
}
$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;
}
17 changes: 8 additions & 9 deletions functions/_str-replace.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
/// @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;
}
$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;
}
Loading

0 comments on commit 499689c

Please sign in to comment.