diff --git a/csstyle.js b/csstyle.js index 6646a4a..f1974bf 100644 --- a/csstyle.js +++ b/csstyle.js @@ -11,6 +11,7 @@ var _ = require('lodash'); module.exports = function (opts){ // symbols are configurable opts = opts || {}; + opts.componentSymbol = opts.componentSymbol || ''; opts.optionSymbol = opts.optionSymbol || '\\--'; opts.partSymbol = opts.partSymbol || '__'; opts.tweakSymbol = opts.tweakSymbol || '\\+'; @@ -68,7 +69,7 @@ module.exports = function (opts){ */ function getAbstraction(selector){ var types = { - component: '.', + component: '.' + opts.componentSymbol, part: opts.partSymbol, option: '.' + opts.optionSymbol, tweak: '#' + opts.rootId + ' .' + opts.tweakSymbol, diff --git a/csstyle.scss b/csstyle.scss index e3940b8..b9ea2fc 100644 --- a/csstyle.scss +++ b/csstyle.scss @@ -5,6 +5,7 @@ // https://twitter.com/geddski // https://github.com/geddski +$csstyle-component-symbol: '' !default; $csstyle-option-symbol: '\\--' !default; $csstyle-part-symbol: '__' !default; $csstyle-tweak-symbol: '\\+' !default; @@ -28,7 +29,7 @@ $csstyle-root-id: 'csstyle' !default; // components @mixin component($names...){ - #{_build_selector(".", $names)}{ + #{_build_selector("." + $csstyle-component-symbol, $names)}{ @content } } diff --git a/spec/csstyle-spec.js b/spec/csstyle-spec.js index 2e00b8a..967cb4f 100644 --- a/spec/csstyle-spec.js +++ b/spec/csstyle-spec.js @@ -183,3 +183,13 @@ describe("regular css", function() { }); }) +describe("custom symbols", function(){ + it("allows projects to customize their styling conventions", function(){ + [ + getSelector('spec/scss/fixtures/custom-symbols.css') + ] + .forEach(function(selector){ + expect(selector.value).toBe(".\\$tweet"); + }) + }); +}); \ No newline at end of file diff --git a/spec/scss/fixtures/custom-symbols.scss b/spec/scss/fixtures/custom-symbols.scss new file mode 100644 index 0000000..ea64c91 --- /dev/null +++ b/spec/scss/fixtures/custom-symbols.scss @@ -0,0 +1,9 @@ +@import '../../../csstyle'; +$csstyle-component-symbol: '\\$'; + +@include component(tweet){ + background: #fff; +} + +// reset symbols for the rest of the tests +$csstyle-component-symbol: ''; \ No newline at end of file