Skip to content

Commit

Permalink
Well Documented
Browse files Browse the repository at this point in the history
  • Loading branch information
zgabievi committed Mar 12, 2016
1 parent 9e059f7 commit 70fbd65
Show file tree
Hide file tree
Showing 46 changed files with 1,218 additions and 701 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
.sass-cache

node_modules
gulpfile.js
config.json

/style.scss
/style.css
Expand Down
59 changes: 12 additions & 47 deletions _bem.scss
Original file line number Diff line number Diff line change
@@ -1,51 +1,16 @@
$bem: (
element: '__',
modifier: '--',
state: '-'
) !default;
// SASS-BEM 2.4.0
// http://sass-bem.zgabievi.io/
// Copyright 2016 Zura Gabievi.
// MIT License

$bem-debug: false !default;
// Configuration
@import "config";

// functions
@import "functions/bem-index";
@import "functions/get-block";
@import "functions/has-state";
@import "functions/is-modifier";
@import "functions/is-element";
@import "functions/is-block";
@import "functions/math-min";
@import "functions/explode";
@import "functions/to-string";
// Functions
@import "functions/all";

// selectors
@import "helpers/block-selector";
@import "helpers/element-selector";
@import "helpers/modifier-selector";
@import "helpers/relations-selector";
@import "helpers/object-selector";
@import "helpers/component-selector";
@import "helpers/utility-selector";
@import "helpers/theme-selector";
@import "helpers/scope-selector";
@import "helpers/state-selector";
@import "helpers/hack-selector";
@import "helpers/test-selector";
// Helpers
@import "helpers/all";

// mixins
@import "mixins/block";
@import "mixins/element";
@import "mixins/modifier";
@import "mixins/relations";
@import "mixins/states";
@import "mixins/pseudo";
@import "mixins/parse";

// oocss
@import "mixins/object";
@import "mixins/component";
@import "mixins/utility";
@import "mixins/theme";
@import "mixins/scope";
@import "mixins/state";
@import "mixins/hack";
@import "mixins/test";
// Mixins
@import "mixins/all";
113 changes: 113 additions & 0 deletions _config.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
@charset "UTF-8";

/// Default sass-bem configuration settings.
///
/// @type map
///
/// @prop {boolean} debug [false] - Turn debug mode on/off. To get outlines on selectors.
///
/// @prop {boolean} separator.element [__] - Element separator from parent block.
///
/// @prop {boolean} separator.modifier [--] - Modifier separator from parent block.
///
/// @prop {boolean} separator.state [-] - States separator from parent block.
///
/// @prop {boolean} namespace.component [c] - Component selector namespace.
///
/// @prop {boolean} namespace.hack [_] - Hack selector namespace.
///
/// @prop {boolean} namespace.object [o] - Object selector namespace.
///
/// @prop {boolean} namespace.scope [s] - Scope selector namespace.
///
/// @prop {boolean} namespace.test [qa] - Test selector namespace.
///
/// @prop {boolean} namespace.theme [t] - Theme selector namespace.
///
/// @prop {boolean} namespace.utility [u] - Utility selector namespace.
///
/// @access public

$bem: (
'debug': false,
'separator': (
'element': "__",
'modifier': "--",
'state': "-",
),
'namespace': (
'component': "c",
'hack': "_",
'object': "o",
'scope': "s",
'test': "qa",
'theme': "t",
'utility': "u",
)
) !default;

/// Turn debug mode on/off. To get outlines on selectors.
///
/// @type Bool

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

/// Element separator from parent block.
///
/// @type String

$bem-element-separator: map-get(map-get($bem, 'separator'), 'element') !default;

/// Modifier separator from parent block.
///
/// @type String

$bem-modifier-separator: map-get(map-get($bem, 'separator'), 'modifier') !default;

/// States separator from parent block.
///
/// @type String

$bem-state-separator: map-get(map-get($bem, 'separator'), 'state') !default;

/// Component selector namespace.
///
/// @type String

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

/// Hack selector namespace.
///
/// @type String

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

/// Object selector namespace.
///
/// @type String

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

/// Scope selector namespace.
///
/// @type String

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

/// Test selector namespace.
///
/// @type String

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

/// Theme selector namespace.
///
/// @type String

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

/// Utility selector namespace.
///
/// @type String

$bem-utility-namespace: map-get(map-get($bem, 'namespace'), 'utility') !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.3.3",
"version": "2.4.0",
"main": "_bem.scss",
"description": "Collection of BEM Mixins & Helpers",
"authors": [
Expand Down
15 changes: 15 additions & 0 deletions functions/_all.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
////
/// @group Functions
///
/// @access private
////

@import "bem-index";
@import "get-block";
@import "has-state";
@import "is-modifier";
@import "is-element";
@import "is-block";
@import "math-min";
@import "explode";
@import "implode";
35 changes: 24 additions & 11 deletions functions/_bem-index.scss
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
//
@charset "UTF-8";

/// Get index of separator.
///
/// @access private
///
/// @param {String} $string - Name of selector, where we should find separator
///
/// @requires math-min
/// @requires $bem-element-separator
/// @requires $bem-modifier-separator
///
/// @returns {Number} - Index of separators

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

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

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

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

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

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

//
Expand Down
12 changes: 11 additions & 1 deletion functions/_explode.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
//
@charset "UTF-8";

/// Explode string to get list of strings.
///
/// @access private
///
/// @param {String} $string - String which should be exploded
/// @param {String} $separator - Separator which will explode string to pieces
///
/// @returns {List} - List of exploded string

@function explode($string, $separator) {
$list: ();
$length: str-length($string);
Expand Down
17 changes: 14 additions & 3 deletions functions/_get-block.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
//
@function get-block($element) {
@return str-slice($element, 2, bem-index($element) - 1);
@charset "UTF-8";

/// Get block element from selector.
///
/// @access private
///
/// @param {String} $selector - Selector, from where we will take block
///
/// @requires bem-index
///
/// @returns {String} - Block element

@function get-block($selector) {
@return str-slice($selector, 2, bem-index($selector) - 1);
}
19 changes: 15 additions & 4 deletions functions/_has-state.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
//
@charset "UTF-8";

/// Check if selector contains state.
///
/// @access private
///
/// @param {String} $selector - Selector, which we will check for state
///
/// @requires $bem-state-separator
///
/// @returns {Bool}
@function has-state($selector) {
$separator_is: unquote(".is#{map-get($bem, state)}");
$separator_js: unquote(".js#{map-get($bem, state)}");
$separator_has: unquote(".has#{map-get($bem, state)}");
$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 and str-index($selector, $separator_js) != null and str-index($selector, $separator_has) != null;
}
32 changes: 32 additions & 0 deletions functions/_implode.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@charset "UTF-8";

/// Implode list to get string.
///
/// @access private
///
/// @param {List} $list - List which will be imploded
/// @param {String} $glue [''] - Separator which will glue list
/// @param {Bool} $is-nested - List is nested or not
///
/// @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;
}
15 changes: 14 additions & 1 deletion functions/_is-block.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
//
@charset "UTF-8";

/// Check if selector is block.
///
/// @access private
///
/// @param {String} $selector - Selector, which we will check for block
///
/// @requires is-element
/// @requires is-modifier
/// @requires has-state
///
/// @returns {Bool}
@function is-block($selector) {
@return (not is-element($selector) and not is-modifier($selector) and not has-state($selector));
}
Loading

0 comments on commit 70fbd65

Please sign in to comment.