Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #70 from kss-node/pull-30-rebased

Update Handlebars.js to resolve HTML entities problem
  • Loading branch information...
commit 0000e2b0134289b02358331bddfd0efa49a44aea 2 parents 1e3b6a0 + f6b01a3
@JohnAlbin JohnAlbin authored
Showing with 35 additions and 41 deletions.
  1. +34 −40 bin/kss-node
  2. +1 −1  package.json
View
74 bin/kss-node
@@ -15,7 +15,7 @@ var kss = require(__dirname + '/../lib/kss.js'),
fs = require('fs'),
template, styleguide,
generatePage, generateStylesheet,
- options = {
+ config = {
templateDirectory: __dirname + '/../lib/template',
sourceDirectory: __dirname + '/../demo',
destinationDirectory: process.cwd() + '/styleguide'
@@ -87,42 +87,42 @@ if (argv.init) {
return;
}
-options.sourceDirectory = path.relative(process.cwd(), argv['_'][0]);
+config.sourceDirectory = path.relative(process.cwd(), argv['_'][0]);
if (argv['_'].length > 1) {
- options.destinationDirectory = path.relative(process.cwd(), argv['_'][1]);
+ config.destinationDirectory = path.relative(process.cwd(), argv['_'][1]);
}
if (argv.template) {
- options.templateDirectory = path.relative(process.cwd(), argv.template);
+ config.templateDirectory = path.relative(process.cwd(), argv.template);
}
console.log('');
console.log('Generating your KSS Styleguide!');
console.log('');
-console.log(' * Source: ' + path.resolve(options.sourceDirectory));
-console.log(' * Destination: ' + path.resolve(options.destinationDirectory));
-console.log(' * Template: ' + path.resolve(options.templateDirectory));
+console.log(' * Source: ' + path.resolve(config.sourceDirectory));
+console.log(' * Destination: ' + path.resolve(config.destinationDirectory));
+console.log(' * Template: ' + path.resolve(config.templateDirectory));
console.log('');
// Compile the Handlebars template
-template = fs.readFileSync(options.templateDirectory + '/index.html', 'utf8');
+template = fs.readFileSync(config.templateDirectory + '/index.html', 'utf8');
template = handlebars.compile(template);
// Create a new "styleguide" directory and copy the contents
// of "public" over.
try {
- fs.mkdirSync(options.destinationDirectory);
+ fs.mkdirSync(config.destinationDirectory);
} catch (e) {}
wrench.copyDirSyncRecursive(
- options.templateDirectory + '/public',
- options.destinationDirectory + '/public'
+ config.templateDirectory + '/public',
+ config.destinationDirectory + '/public'
);
// Generate the static HTML pages in the next tick, i.e. after the other functions have
// been defined and handlebars helpers set up.
process.nextTick(function() {
console.log('...compiling KSS styles');
- less.render('@import "' + path.relative(process.cwd(), options.destinationDirectory) + '/public/kss.less";', function(err, css) {
+ less.render('@import "' + path.relative(process.cwd(), config.destinationDirectory) + '/public/kss.less";', function(err, css) {
if (err) {
console.error(err);
throw err;
@@ -131,11 +131,11 @@ process.nextTick(function() {
css = cleanCss.process(css);
// Write the compiled LESS styles from the template.
- fs.writeFileSync(options.destinationDirectory + '/public/kss.css', css, 'utf8');
+ fs.writeFileSync(config.destinationDirectory + '/public/kss.css', css, 'utf8');
console.log('...parsing your styleguide');
- kss.traverse(options.sourceDirectory, {
+ kss.traverse(config.sourceDirectory, {
multiline : true,
markdown : true,
markup : true,
@@ -243,7 +243,7 @@ generateStylesheet = function(argv) {
saveStylesheet = function(buffer) {
buffer = cleanCss.process(buffer.toString());
fs.writeFileSync(
- options.destinationDirectory + '/public/style.css',
+ config.destinationDirectory + '/public/style.css',
buffer, 'utf8'
);
};
@@ -256,7 +256,7 @@ generatePage = function(styleguide, sections, root, pages, sectionRoots) {
styleguide.section(root) ? styleguide.section(root).header() : 'Unnamed',
']'
);
- fs.writeFileSync(options.destinationDirectory + '/section-'+root+'.html',
+ fs.writeFileSync(config.destinationDirectory + '/section-'+root+'.html',
template({
styleguide: styleguide,
sections: jsonSections(sections),
@@ -273,14 +273,14 @@ generatePage = function(styleguide, sections, root, pages, sectionRoots) {
generateIndex = function(styleguide, sections, pages, sectionRoots) {
try {
console.log('...generating styleguide overview');
- fs.writeFileSync(options.destinationDirectory + '/index.html',
+ fs.writeFileSync(config.destinationDirectory + '/index.html',
template({
styleguide: styleguide,
sectionRoots: sectionRoots,
sections: jsonSections(sections),
rootNumber: 0,
argv: argv || {},
- overview: marked(fs.readFileSync(options.sourceDirectory + '/styleguide.md', 'utf8'))
+ overview: marked(fs.readFileSync(config.sourceDirectory + '/styleguide.md', 'utf8'))
})
);
} catch(e) {
@@ -318,29 +318,28 @@ jsonModifiers = function(modifiers) {
* Equivalent to the {#if} block helper with multiple arguments.
*/
handlebars.registerHelper('ifAny', function() {
- var argLength = arguments.length - 2,
- content = arguments[argLength + 1],
+ var numItems = arguments.length - 1,
+ options = arguments[numItems],
success = true;
- for (var i = 0; i < argLength; i += 1) {
+ for (var i = 0; i < numItems; i += 1) {
if (!arguments[i]) {
success = false;
break;
}
}
- return success ? content(this) : content.inverse(this);
+ return success ? options.fn(this) : options.inverse(this);
});
/**
* Returns a single section, found by its reference number
* @param {String|Number} reference The reference number to search for.
*/
-handlebars.registerHelper('section', function(reference) {
+handlebars.registerHelper('section', function(reference, options) {
var section = styleguide.section(reference);
- if (!section) return false;
- return arguments[arguments.length-1](section.data);
+ return section ? options.fn(section.data) : false;
});
/**
@@ -348,7 +347,7 @@ handlebars.registerHelper('section', function(reference) {
* a query for all children and descendants of that reference.
* @param {Mixed} query The section query
*/
-handlebars.registerHelper('eachSection', function(query) {
+handlebars.registerHelper('eachSection', function(query, options) {
var sections,
i, l, buffer = "";
@@ -360,7 +359,7 @@ handlebars.registerHelper('eachSection', function(query) {
l = sections.length;
for (i = 0; i < l; i += 1) {
- buffer += arguments[arguments.length-1](sections[i].data);
+ buffer += options.fn(sections[i].data);
}
return buffer;
@@ -369,7 +368,7 @@ handlebars.registerHelper('eachSection', function(query) {
/**
* Loop over each section root, i.e. each section only one level deep.
*/
-handlebars.registerHelper('eachRoot', function() {
+handlebars.registerHelper('eachRoot', function(options) {
var sections,
i, l, buffer = "";
@@ -378,7 +377,7 @@ handlebars.registerHelper('eachRoot', function() {
l = sections.length;
for (i = 0; i < l; i += 1) {
- buffer += arguments[arguments.length-1](sections[i].data);
+ buffer += options.fn(sections[i].data);
}
return buffer;
@@ -393,34 +392,29 @@ handlebars.registerHelper('eachRoot', function() {
* ANYTHING ELSE
* {{/refDepth}}
*/
-handlebars.registerHelper('whenDepth', function(depth, context) {
- if (!(context && this.refDepth)) {
+handlebars.registerHelper('whenDepth', function(depth, options) {
+ if (!this.refDepth) {
return '';
}
- if (depth == this.refDepth) {
- return context(this);
- }
- if (context.inverse) {
- return context.inverse(this);
- }
+ return (depth == this.refDepth) ? options.fn(this) : options.inverse(this);
});
/**
* Similar to the {#eachSection} helper, however will loop over each modifier
* @param {Object} section Supply a section object to loop over it's modifiers. Defaults to the current section.
*/
-handlebars.registerHelper('eachModifier', function(section) {
+handlebars.registerHelper('eachModifier', function(options) {
var modifiers, i, l, buffer = '';
// Default to current modifiers, but allow supplying a custom section
- if (section.data) modifiers = section.data.modifiers;
+ if (options.data) modifiers = options.data.modifiers;
modifiers = modifiers || this.modifiers || false;
if (!modifiers) return {};
l = modifiers.length;
for (i = 0; i < l; i++) {
- buffer += arguments[arguments.length-1](modifiers[i].data || '');
+ buffer += options.fn(modifiers[i].data || '');
}
return buffer;
});
View
2  package.json
@@ -21,7 +21,7 @@
"dependencies": {
"marked": "0.1.x",
"natural": "0.0.65",
- "handlebars": "1.3.0",
+ "handlebars": "1.3.x",
"wrench": "1.3.x",
"less": "1.x.x",
"stylus": "0.46.x",
Please sign in to comment.
Something went wrong with that request. Please try again.