bem-constructor 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +3 -3
- data/lib/bem-constructor.rb +2 -2
- data/stylesheets/_bem-constructor.scss +6 -0
- data/stylesheets/_error-checks.scss +18 -10
- data/stylesheets/_hack.scss +20 -3
- data/stylesheets/_modifies-element.scss +5 -3
- data/stylesheets/_theme.scss +4 -2
- metadata +2 -3
- data/stylesheets/test.scss +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebdae9d3c028fc32f09e818f79065b4f26facc6f
|
4
|
+
data.tar.gz: f8107c8e18d07ba716a4d5d94902509166cbb176
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfcf0086fa4b32fc43fac20da997396757e135e75d81439f26aef7330aeb8091e39f591d9f330a03c229acbd0508e7b6da5011c8f46facd9607ce54364d9c6c1
|
7
|
+
data.tar.gz: 58ff5071cbbe9457143af0effa1fd4ff06b4a6133f4ed8733c6818eb35f9220fce275be41a2a4ca6876ba8c0d62c020cfb57014b889302812f682ef888a5de3c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ BEM Constructor is a Sass library for building immutable and namespaced BEM-styl
|
|
4
4
|
|
5
5
|
By enforcing a consistent and programatic way of defining objects (blocks, elements and modifiers) it ensures a more structured, robust and secure object codebase that is easy to understand and maintain. Objects defined using the constructor are impossible to modify and reassign by mistake or omission.
|
6
6
|
|
7
|
-
Jump to [
|
7
|
+
Jump to [:hamburger: The Burger Example™](#example) to see the mixins in action.
|
8
8
|
|
9
9
|
## Key ideas
|
10
10
|
|
@@ -94,7 +94,7 @@ Creates a new modifier of the parent block or element. Should always be nested w
|
|
94
94
|
|
95
95
|
### modifies-element($modified-elements...)
|
96
96
|
|
97
|
-
When declaring a block modifier, a state you may need to target and modify some of the block elements too. Use the following mixin to scope the ruleset to those elements.
|
97
|
+
When declaring a block modifier, a theme a state or a hack you may need to target and modify some of the block elements too. Use the following mixin to scope the ruleset to those elements.
|
98
98
|
|
99
99
|
@include modifies-element($modified-elements...) { ... }
|
100
100
|
|
@@ -169,7 +169,7 @@ You can customize them to whatever fits you needs:
|
|
169
169
|
$bem-modifier-separator: '-_-_'; // Defaults to '--'
|
170
170
|
|
171
171
|
|
172
|
-
##<a name="example"></a>
|
172
|
+
##<a name="example"></a> :hamburger: The Burger Example™
|
173
173
|
|
174
174
|
|
175
175
|
*Disclaimer: the following Sass code may not compile into a real burger.*
|
data/lib/bem-constructor.rb
CHANGED
@@ -21,6 +21,12 @@ $bem-element-separator: '__' !default;
|
|
21
21
|
/// @public
|
22
22
|
$bem-modifier-separator: '--' !default;
|
23
23
|
|
24
|
+
/// Throw errors
|
25
|
+
/// @public
|
26
|
+
$bem-throw-errors: true !default;
|
27
|
+
|
28
|
+
|
29
|
+
|
24
30
|
// -----------------------------------------------------------------------------
|
25
31
|
// 2. Imports
|
26
32
|
// -----------------------------------------------------------------------------
|
@@ -21,7 +21,11 @@
|
|
21
21
|
}
|
22
22
|
|
23
23
|
@if not $found {
|
24
|
-
@
|
24
|
+
@if ($bem-throw-error) {
|
25
|
+
@error 'It should be called within #{inspect($objs)}';
|
26
|
+
}
|
27
|
+
|
28
|
+
@return false;
|
25
29
|
}
|
26
30
|
|
27
31
|
@return true;
|
@@ -35,16 +39,20 @@
|
|
35
39
|
/// Checks that it's being created outside all of the passed $objs...
|
36
40
|
@function _should-not-be-called-within($objs...) {
|
37
41
|
|
38
|
-
|
42
|
+
$found: false;
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
@each $obj in $objs {
|
45
|
+
@if map-get($_bem-current-context, $obj) != null {
|
46
|
+
$found: true;
|
47
|
+
}
|
43
48
|
}
|
44
|
-
}
|
45
|
-
@if $found {
|
46
|
-
@error 'It should not be called within #{inspect($objs)}';
|
47
|
-
}
|
48
49
|
|
49
|
-
|
50
|
+
@if $found {
|
51
|
+
@if ($bem-throw-error) {
|
52
|
+
@error 'It should not be called within #{inspect($objs)}';
|
53
|
+
}
|
54
|
+
@return false;
|
55
|
+
}
|
56
|
+
|
57
|
+
@return true;
|
50
58
|
}
|
data/stylesheets/_hack.scss
CHANGED
@@ -5,6 +5,18 @@
|
|
5
5
|
/// Hack namespace prepended to the selector
|
6
6
|
$hack-namespace: '_' !default;
|
7
7
|
|
8
|
+
/// Find the last simple selector in a selector
|
9
|
+
@function _last-simple-selector($selector) {
|
10
|
+
$parsed: selector-parse($selector);
|
11
|
+
|
12
|
+
@if length($parsed) > 1 {
|
13
|
+
@error '`#{$selector}` contains #{length($parsed)} selectors and the `_last-simple-selector()`function accepts only 1.';
|
14
|
+
}
|
15
|
+
$last-simple-selector: nth(nth($parsed, 1), -1);
|
16
|
+
|
17
|
+
@return $last-simple-selector;
|
18
|
+
}
|
19
|
+
|
8
20
|
@function _hack() {
|
9
21
|
|
10
22
|
// You may not hack a hack
|
@@ -13,11 +25,16 @@ $hack-namespace: '_' !default;
|
|
13
25
|
$selector: ();
|
14
26
|
$namespace: if($bem-use-namespaces, $hack-namespace, '');
|
15
27
|
|
16
|
-
|
17
|
-
|
28
|
+
// Check if we are hacking an element modified by a block modifier
|
29
|
+
$is-hack-element: not not map-get($_bem-current-context, 'modifies-element');
|
30
|
+
$selectors: if($is-hack-element, map-get(map-get($_bem-current-context, 'modifies-element'), 'selector'), &);
|
31
|
+
|
32
|
+
// @todo refactor the following code to something more readab
|
33
|
+
@each $s in $selectors {
|
34
|
+
$selector-to-str: inspect(if($is-hack-element, _last-simple-selector($s), nth($s, 1)));
|
18
35
|
$selector-without-dot: str-slice($selector-to-str, 2, -1);
|
19
36
|
$new-selector: '.' + $namespace + $selector-without-dot;
|
20
|
-
$sl: selector-replace($s, nth($s, 1), $new-selector)
|
37
|
+
$sl: selector-replace($s, if($is-hack-element, $selector-to-str, nth($s, 1)), $new-selector);
|
21
38
|
$selector: append($selector, $sl, 'comma');
|
22
39
|
}
|
23
40
|
|
@@ -7,21 +7,21 @@
|
|
7
7
|
/// @param {String | Arglist} $modified-elements - List of elements that should be modified
|
8
8
|
/// @returns The final selector for the element(s) modified by the block modifier
|
9
9
|
|
10
|
-
@function _modifies-element($modified-
|
10
|
+
@function _modifies-element($modified-elements...) {
|
11
11
|
|
12
12
|
$inside-check: should-be-called-within('modifier', 'state');
|
13
13
|
$outside-check: should-not-be-called-within('element');
|
14
14
|
|
15
15
|
$selectors: ();
|
16
16
|
|
17
|
-
@each $element in $modified-
|
17
|
+
@each $element in $modified-elements {
|
18
18
|
$element: map-get(map-get($_bem-current-context, 'block'), 'selector') + $bem-element-separator + $element;
|
19
19
|
$selectors: append($selectors, $element, 'comma');
|
20
20
|
}
|
21
21
|
|
22
22
|
$selector: selector-nest(&, $selectors);
|
23
23
|
|
24
|
-
$set-current: set-current-context('modifies-element', $modified-
|
24
|
+
$set-current: set-current-context('modifies-element', $modified-elements, $selector);
|
25
25
|
|
26
26
|
@return $selector;
|
27
27
|
}
|
@@ -34,4 +34,6 @@
|
|
34
34
|
@at-root #{_modifies-element($modified-elements...)} {
|
35
35
|
@content;
|
36
36
|
}
|
37
|
+
|
38
|
+
$unset-current: unset-current-context('modifies-element');
|
37
39
|
}
|
data/stylesheets/_theme.scss
CHANGED
@@ -14,8 +14,10 @@ $bem-theme-namespace: 't' !default;
|
|
14
14
|
$namespace: if($bem-use-namespaces, $bem-theme-namespace + '-', '');
|
15
15
|
|
16
16
|
@each $theme in $themes {
|
17
|
-
|
18
|
-
|
17
|
+
@each $sel in & {
|
18
|
+
$t: selector-nest('.#{$namespace}#{$theme}', $sel);
|
19
|
+
$selector: append($selector, $t, 'comma');
|
20
|
+
}
|
19
21
|
}
|
20
22
|
|
21
23
|
$set-current: set-current-context('theme', $themes, $selector);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bem-constructor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Guillan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|
@@ -67,7 +67,6 @@ files:
|
|
67
67
|
- stylesheets/logger/_scope-logger.scss
|
68
68
|
- stylesheets/test.css
|
69
69
|
- stylesheets/test.css.map
|
70
|
-
- stylesheets/test.scss
|
71
70
|
homepage: https://github.com/danielguillan/bem-constructor
|
72
71
|
licenses:
|
73
72
|
- MIT
|
data/stylesheets/test.scss
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
@import 'bem-constructor';
|
2
|
-
|
3
|
-
// The Burger Test™
|
4
|
-
|
5
|
-
@include object('burger') {
|
6
|
-
texture: juicy;
|
7
|
-
|
8
|
-
@include element('letuce', 'tomato') {
|
9
|
-
quality: fresh;
|
10
|
-
}
|
11
|
-
|
12
|
-
@include element('cheese') {
|
13
|
-
type: gouda;
|
14
|
-
|
15
|
-
@include modifier('parmigiano') {
|
16
|
-
type: parmigiano;
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
@include element('extra-topping') {
|
21
|
-
ingredient: bacon;
|
22
|
-
}
|
23
|
-
|
24
|
-
@include element('meat') {
|
25
|
-
type: beef;
|
26
|
-
}
|
27
|
-
|
28
|
-
@include modifier('veggie') {
|
29
|
-
texture: smooth;
|
30
|
-
|
31
|
-
@include modifies-element('meat') {
|
32
|
-
type: lentils;
|
33
|
-
}
|
34
|
-
|
35
|
-
@include modifies-element('extra-topping') {
|
36
|
-
ingredient: avocado;
|
37
|
-
|
38
|
-
@include hack() {
|
39
|
-
ingredient: bacon;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
@include theme('mexican') {
|
45
|
-
spicy: hell-yeah;
|
46
|
-
}
|
47
|
-
|
48
|
-
@include state('cold') {
|
49
|
-
taste: terrible;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
// @include scope(test) {
|
54
|
-
// a: shite
|
55
|
-
// }
|
56
|
-
|
57
|
-
// .bem-log {
|
58
|
-
// log: inspect($_bem-log);
|
59
|
-
// }
|