Skip to content

Commit

Permalink
support custom symbols for components
Browse files Browse the repository at this point in the history
this also lets teams easily namespace everything in a project
  • Loading branch information
geddski committed Jun 12, 2015
1 parent 7342c79 commit e19b5a3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion csstyle.js
Expand Up @@ -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 || '\\+';
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion csstyle.scss
Expand Up @@ -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;
Expand All @@ -28,7 +29,7 @@ $csstyle-root-id: 'csstyle' !default;

// components
@mixin component($names...){
#{_build_selector(".", $names)}{
#{_build_selector("." + $csstyle-component-symbol, $names)}{
@content
}
}
Expand Down
10 changes: 10 additions & 0 deletions spec/csstyle-spec.js
Expand Up @@ -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");
})
});
});
9 changes: 9 additions & 0 deletions 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: '';

0 comments on commit e19b5a3

Please sign in to comment.