Skip to content

Commit

Permalink
Merge a7ff378 into 14b9b08
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksp committed Feb 15, 2016
2 parents 14b9b08 + a7ff378 commit 3a2c0de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ b.state({ hidden: true, error: true }); // 'button is-hidden is-error'
// Setup custom separators
block.setup({
el: '~~',
mod: '-'
mod: '--',
modValue: '-'
});

var b = block('block');

b('element'); // 'block~~element'
b({ mod: 'value' }); // 'block block-mod-value'
b({ mod: 'value' }); // 'block block--mod-value'
```

```js
Expand Down
8 changes: 6 additions & 2 deletions src/bem-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
settings = {
ns: '',
el: '__',
mod: '_'
mod: '_',
modValue: '_'
};

/**
Expand Down Expand Up @@ -59,6 +60,8 @@
separator = settings.mod;
}

var modValueSeparator = settings.modValue;

return Object.keys(obj).reduce(function(array, key) {
var value = obj[key];

Expand All @@ -69,7 +72,8 @@
if ( value === true ) {
array.push(separator + key);
} else {
array.push(separator + key + separator + value);
// Makes block__elem_{modifierKey}_{modifierValue}
array.push(separator + key + modValueSeparator + value);
}

return array;
Expand Down
9 changes: 5 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ describe('Setup custom settings', function() {
block.setup({
ns: 'ns-',
el: '~~',
mod: '-',
mod: '--',
modValue: '-'
});

var b = block('block');
Expand All @@ -175,12 +176,12 @@ describe('Setup custom settings', function() {
).equal('ns-block~~element');
should(
b({ mod: 'value' }).toString()
).equal('ns-block ns-block-mod-value');
).equal('ns-block ns-block--mod-value');
should(
b({ mod: true }).toString()
).equal('ns-block ns-block-mod');
).equal('ns-block ns-block--mod');
should(
b('element', { mod: 'value' }).toString()
).equal('ns-block~~element ns-block~~element-mod-value');
).equal('ns-block~~element ns-block~~element--mod-value');
});
});

0 comments on commit 3a2c0de

Please sign in to comment.