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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a5f29c158ee72d70d4bea646b71b78f29b18952
4
- data.tar.gz: e9b0a1cc67ad4210e097467dcf88c5acc9f424c8
3
+ metadata.gz: ebdae9d3c028fc32f09e818f79065b4f26facc6f
4
+ data.tar.gz: f8107c8e18d07ba716a4d5d94902509166cbb176
5
5
  SHA512:
6
- metadata.gz: e9f4bcdffc6e15a96e16e33413cf8a193d2084b06d2adb8012d3053f79f710102e57b64f176e4e75452a85ee950f63dd3936caa37641c822f74ea12691d739b3
7
- data.tar.gz: 586343de875a9775945fb9b1a9955f27b9f5abf4a9d16b31b22d641c60486ba8da3aa870ad90845635bdfa8592539387334804b796e34011a59843f560ee4f75
6
+ metadata.gz: cfcf0086fa4b32fc43fac20da997396757e135e75d81439f26aef7330aeb8091e39f591d9f330a03c229acbd0508e7b6da5011c8f46facd9607ce54364d9c6c1
7
+ data.tar.gz: 58ff5071cbbe9457143af0effa1fd4ff06b4a6133f4ed8733c6818eb35f9220fce275be41a2a4ca6876ba8c0d62c020cfb57014b889302812f682ef888a5de3c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.2
2
+
3
+ * Fix wrong selector namespacing when hack() is called within a modifies-element() context
4
+ * Add test suite
5
+
6
+ ## 0.1.1
7
+
8
+ * Fix some copy and paste in Gemspec
9
+
1
10
  ## 0.1.0
2
11
 
3
12
  * Initial release
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 [🍔 The Burger Example™](#example) to see the mixins in action.
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> 🍔 The Burger Example™
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.*
@@ -3,6 +3,6 @@ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
3
3
  Compass::Frameworks.register('bem-constructor', :path => extension_path)
4
4
 
5
5
  module BEMConstructor
6
- VERSION = "0.1.1"
7
- DATE = "2015-03-24"
6
+ VERSION = "0.2.0"
7
+ DATE = "2015-03-26"
8
8
  end
@@ -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
- @error 'It should be called within #{inspect($objs)}';
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
- $found: false;
42
+ $found: false;
39
43
 
40
- @each $obj in $objs {
41
- @if map-get($_bem-current-context, $obj) != null {
42
- $found: true;
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
- @return true;
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
  }
@@ -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
- @each $s in & {
17
- $selector-to-str: inspect(nth($s, 1));
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-element...) {
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-element {
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-element, $selector);
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
  }
@@ -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
- $t: selector-nest('.#{$namespace}#{$theme}', &);
18
- $selector: append($selector, $t, 'comma');
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.1.1
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-24 00:00:00.000000000 Z
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
@@ -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
- // }