Skip to content

Commit

Permalink
Add --css and --js options to include URLs of CSS/JS files. #152
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAlbin committed Jan 17, 2015
1 parent ea00b4a commit bef4da5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -32,6 +32,10 @@ Options:
[default: "*.css|*.less|*.sass|*.scss|*.styl|*.stylus"]
--custom Process a custom property name when parsing KSS comments
--css Specify the URL of a CSS file to include in the style guide
--js Specify the URL of a JavaScript file to include in the style
guide
--source Source directory to parse for KSS comments
--destination Destination directory of generated style guide
[default: "styleguide"]
Expand Down
32 changes: 29 additions & 3 deletions bin/kss-node
Expand Up @@ -53,6 +53,15 @@ argv = yargs
default : '*.css|*.less|*.sass|*.scss|*.styl|*.stylus'
})

.options('css', {
string : true,
describe : 'Specify the URL of a CSS file to include in the style guide'
})
.options('js', {
string : true,
describe : 'Specify the URL of a JavaScript file to include in the style guide'
})

.options('custom', {
string : true,
describe : 'Process a custom property name when parsing KSS comments'
Expand Down Expand Up @@ -180,10 +189,16 @@ else if (!("helpers" in yargs.argv) && !config.helpers) {
argv.helpers = argv.template + '/helpers';
}
argv.helpers = path.resolve(argv.helpers);
// Make custom an array.
// Make these options an array.
if (typeof argv.custom == "string") {
argv.custom = [argv.custom];
}
if (typeof argv.css == "string") {
argv.css = [argv.css];
}
if (typeof argv.js == "string") {
argv.js = [argv.js];
}

console.log('');
console.log('Generating your KSS style guide!');
Expand Down Expand Up @@ -327,7 +342,9 @@ process.nextTick(function() {
// Renders the handlebars template for a section and saves it to a file.
generatePage = function(styleguide, sections, root, sectionRoots) {
var filename = '', files,
homepageText = false;
homepageText = false,
styles = '',
scripts = '';

if (root == 'styleguide.homepage') {
filename = 'index.html';
Expand Down Expand Up @@ -356,14 +373,23 @@ generatePage = function(styleguide, sections, root, sectionRoots) {
']'
);
}
// Create the HTML to load the optional CSS and JS.
for (var key in argv.css) {
styles = styles + '<link rel="stylesheet" href="' + argv.css[key] + '">\n';
}
for (var key in argv.js) {
scripts = scripts + '<script src="' + argv.js[key] + '"></script>\n';
}
fs.writeFileSync(argv.destination + '/' + filename,
template({
styleguide: styleguide,
sectionRoots: sectionRoots,
sections: jsonSections(sections),
rootName: root,
argv: argv || {},
homepage: homepageText
homepage: homepageText,
styles: styles,
scripts: scripts
})
);
};
Expand Down
4 changes: 3 additions & 1 deletion lib/template/index.html
Expand Up @@ -13,7 +13,7 @@

<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Serif">
<link rel="stylesheet" href="public/kss.css">
<link rel="stylesheet" href="public/style.css">
{{{styles}}}
</head>
<body id="kss-node">

Expand Down Expand Up @@ -174,5 +174,7 @@
</script>
{{/if}}

{{{scripts}}}

</body>
</html>

0 comments on commit bef4da5

Please sign in to comment.