Skip to content

Commit

Permalink
Move precompilers from bin/kss-node to lib/kss.js
Browse files Browse the repository at this point in the history
Means precompiler masks will be included by default.
Fixed an tiny issue with processing string masks too :)
  • Loading branch information
hughsk committed Dec 1, 2012
1 parent 4c9cacc commit 632c9fe
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bin/kss-node
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

var kss = require(__dirname + '/../lib/kss.js'),
preCompiler = require(__dirname + '/../lib/precompiler.js')(),
preCompiler = kss.precompilers,
handlebars = require('handlebars'),
cleanCss = require('clean-css'),
optimist = require('optimist'),
Expand Down
13 changes: 8 additions & 5 deletions lib/kss.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var walk = require('./walk.js'),
KssSection = require('./kss_section.js'),
KssStyleguide = require('./kss_styleguide.js'),
KssModifier = require('./kss_modifier.js'),
precompilers = require('./precompiler')(),
path = require('path'),
fs = require('fs'),
util = require('util'),
Expand All @@ -13,7 +14,7 @@ var walk = require('./walk.js'),
isDeprecated, isExperimental, hasPrefix,
commentExpressions = {
single: /\s*?\/\/(.*?)$/g,
multiStart: /\/\*(.*?)$/,
multiStart: /\/\*\!?(.*?)$/,
multiFinish: /\*\//,
multiBeforeFinish: /(.*?)\*\//
};
Expand All @@ -37,14 +38,15 @@ traverse = function(directory, options, callback) {
throw new Error('No callback supplied for KSS.traverse!');
}

// Mask to search for particular file types - defaults to precompiler masks,
// or CSS and LESS only.
options.mask = options.mask || precompilers.mask || /\.css|\.less/;

// Mask to search for particular file types - defaults to CSS and LESS only.
options.mask = options.mask || /\.css|\.less/;

// If the mask is a string, convert it into a RegExp
if (!(options.mask instanceof RegExp)) {
options.mask = new RegExp(
options.mask.replace(/\*/g, '.*')
'(?:' + options.mask.replace(/\*/g, '.*') + ')$'
);
}

Expand Down Expand Up @@ -477,5 +479,6 @@ module.exports = {
traverse: traverse,
KssStyleguide: KssStyleguide,
KssSection: KssSection,
KssModifier: KssModifier
KssModifier: KssModifier,
precompilers: precompilers
};
39 changes: 39 additions & 0 deletions test/fixtures-styles/style.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// A button suitable for giving stars to someone.
//
// Testing indentation for Markdown code.
//
// :hover - Subtle hover highlight.
// .stars-given - A highlight indicating you've already given a star.
// .stars-given:hover - Subtle hover highlight on top of stars-given styling.
// .disabled - Dims the button to indicate it cannot be used.
//
// Styleguide 2.1.3.
a.button.star{
background:#ddd;

&.star-given{

}
&.disabled{
...
}
}

// A button suitable for giving stars to someone.
//
// :hover - Subtle hover highlight.
// .stars-given - A highlight indicating you've already given a star.
// .stars-given:hover - Subtle hover highlight on top of stars-given styling.
// .disabled - Dims the button to indicate it cannot be used.
//
// Styleguide 2.1.4.
a.button.star{
background:#ddd;

&.star-given{

}
&.disabled{
...
}
}
39 changes: 39 additions & 0 deletions test/fixtures-styles/style.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// A button suitable for giving stars to someone.
//
// Testing indentation for Markdown code.
//
// :hover - Subtle hover highlight.
// .stars-given - A highlight indicating you've already given a star.
// .stars-given:hover - Subtle hover highlight on top of stars-given styling.
// .disabled - Dims the button to indicate it cannot be used.
//
// Styleguide 2.1.3.
a.button.star{
background:#ddd;

&.star-given{

}
&.disabled{
...
}
}

// A button suitable for giving stars to someone.
//
// :hover - Subtle hover highlight.
// .stars-given - A highlight indicating you've already given a star.
// .stars-given:hover - Subtle hover highlight on top of stars-given styling.
// .disabled - Dims the button to indicate it cannot be used.
//
// Styleguide 2.1.4.
a.button.star{
background:#ddd;

&.star-given{

}
&.disabled{
...
}
}
39 changes: 39 additions & 0 deletions test/fixtures-styles/style.stylus
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// A button suitable for giving stars to someone.
//
// Testing indentation for Markdown code.
//
// :hover - Subtle hover highlight.
// .stars-given - A highlight indicating you've already given a star.
// .stars-given:hover - Subtle hover highlight on top of stars-given styling.
// .disabled - Dims the button to indicate it cannot be used.
//
// Styleguide 2.1.3.
a.button.star{
background:#ddd;

&.star-given{

}
&.disabled{
...
}
}

// A button suitable for giving stars to someone.
//
// :hover - Subtle hover highlight.
// .stars-given - A highlight indicating you've already given a star.
// .stars-given:hover - Subtle hover highlight on top of stars-given styling.
// .disabled - Dims the button to indicate it cannot be used.
//
// Styleguide 2.1.4.
a.button.star{
background:#ddd;

&.star-given{

}
&.disabled{
...
}
}
7 changes: 5 additions & 2 deletions test/kss.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ suite('#traverse', function() {
}, 'Only works when included at the beginning of a paragraph/header', { multiline: true});
});
suite('.experimental', function() {

common.testSection('Experimental: Spacing above and below', 'sections-status.less', function(section) {
assert.ok(section.data.experimental);
}, 'Still works with vertical line space', { multiline: true});
Expand Down Expand Up @@ -341,6 +341,9 @@ suite('#traverse', function() {
suite('Default', function() {
common.shouldFindFile('style.css', {}, true);
common.shouldFindFile('style.less', {}, true);
common.shouldFindFile('style.stylus', {}, true);
common.shouldFindFile('style.styl', {}, true);
common.shouldFindFile('style.sass', {}, true);
common.shouldFindFile('includes/buttons.less', {}, true);
common.shouldFindFile('includes/buttons.js', {}, false);
});
Expand Down Expand Up @@ -426,7 +429,7 @@ suite('#traverse', function() {
assert.equal(section.data.header, 'Misspelt Styleguide 4');
}, 'Style guide', { typos: true });
});

suite('Experimental', function() {
common.testSection('Experimental: In Header', 'sections-status.less', function(section) {
assert.ok(section.data.experimental);
Expand Down

0 comments on commit 632c9fe

Please sign in to comment.