Skip to content

Commit

Permalink
jshint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Oct 9, 2012
1 parent e827fae commit 36ac891
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 115 deletions.
57 changes: 29 additions & 28 deletions lib/fileutils.js
@@ -1,3 +1,4 @@
/*jshint expr: true, latedef: false,loopfunc:true */
/* /*
Selleck Selleck
Copyright (c) 2011 Yahoo! Inc. Copyright (c) 2011 Yahoo! Inc.
Expand All @@ -18,16 +19,28 @@ function copyDirectory(source, dest, overwrite, callback) {
overwrite = null; overwrite = null;
} }


fs.stat(source, afterSourceStat); function afterReadDir(err, files) {

function afterSourceStat(err, stats) {
if (err) { return callback(err); } if (err) { return callback(err); }


if (!stats.isDirectory()) { var pending = files.length,
return callback(new Error("Source is not a directory: " + source)); filename;

while ((filename = files.shift())) {
copyPath(fsPath.join(source, filename), fsPath.join(dest, filename), overwrite, function (err) {
if (err) { return callback(err); }

pending -= 1;

if (!pending) {
callback();
}
});
} }
}


fs.lstat(dest, afterDestStat); function afterMkDir(err) {
if (err && err.code !== 'EEXIST') { return callback(err); }
fs.readdir(source, afterReadDir);
} }


function afterDestStat(err, stats) { function afterDestStat(err, stats) {
Expand All @@ -47,33 +60,22 @@ function copyDirectory(source, dest, overwrite, callback) {


afterMkDir(); afterMkDir();
} else { } else {
fs.mkdir(dest, 0755, afterMkDir); fs.mkdir(dest, parseInt('0755', 8), afterMkDir);
} }
} }


function afterMkDir(err) { function afterSourceStat(err, stats) {
if (err && err.code !== 'EEXIST') { return callback(err); }
fs.readdir(source, afterReadDir);
}

function afterReadDir(err, files) {
if (err) { return callback(err); } if (err) { return callback(err); }


var pending = files.length, if (!stats.isDirectory()) {
filename; return callback(new Error("Source is not a directory: " + source));
}


while ((filename = files.shift())) { fs.lstat(dest, afterDestStat);
copyPath(fsPath.join(source, filename), fsPath.join(dest, filename), overwrite, function (err) { }
if (err) { return callback(err); }


pending -= 1; fs.stat(source, afterSourceStat);


if (!pending) {
callback();
}
});
}
}
} }
exports.copyDirectory = copyDirectory; exports.copyDirectory = copyDirectory;


Expand Down Expand Up @@ -107,7 +109,7 @@ function copyFile(source, dest, overwrite, callback) {
} }


nodeUtil.pump(fs.createReadStream(source), nodeUtil.pump(fs.createReadStream(source),
fs.createWriteStream(dest, {mode: 0655}), callback); fs.createWriteStream(dest, {mode: parseInt('0655', 8)}), callback);
}); });
}); });
} }
Expand All @@ -134,8 +136,7 @@ Known issues:
@param {Error} err @param {Error} err
**/ **/
function copyPath(source, dest, overwrite, callback) { function copyPath(source, dest, overwrite, callback) {
var destStats = statSync(dest), var sourceStats = statSync(source);
sourceStats = statSync(source);


// Allow callback as third arg. // Allow callback as third arg.
if (typeof overwrite === 'function') { if (typeof overwrite === 'function') {
Expand Down
46 changes: 24 additions & 22 deletions lib/higgins.js
@@ -1,3 +1,4 @@
/*jshint expr: true, latedef: false, bitwise: false */
/* /*
Selleck Selleck
Copyright (c) 2011 Yahoo! Inc. Copyright (c) 2011 Yahoo! Inc.
Expand Down Expand Up @@ -30,6 +31,29 @@ Higgins.render = function (html) {
return new Higgins(html).render(); return new Higgins(html).render();
}; };


// -- Private Functions --------------------------------------------------------

/**
Normalizes the initial indentation of the given _content_ so that the first line
is unindented, and all other lines are unindented to the same degree as the
first line. So if the first line has four spaces at the beginning, then all
lines will be unindented four spaces.
@method unindent
@param {String} content Text to unindent.
@return {String} Unindented text.
@private
**/
function unindent(content) {
var indent = content.match(/^(\s+)/);

if (indent) {
content = content.replace(new RegExp('^' + indent[1], 'gm'), '');
}

return content;
}

Higgins.prototype = { Higgins.prototype = {
// -- Public Functions ----------------------------------------------------- // -- Public Functions -----------------------------------------------------
render: function () { render: function () {
Expand Down Expand Up @@ -250,25 +274,3 @@ Higgins.prototype = {


module.exports = Higgins; module.exports = Higgins;


// -- Private Functions --------------------------------------------------------

/**
Normalizes the initial indentation of the given _content_ so that the first line
is unindented, and all other lines are unindented to the same degree as the
first line. So if the first line has four spaces at the beginning, then all
lines will be unindented four spaces.
@method unindent
@param {String} content Text to unindent.
@return {String} Unindented text.
@private
**/
function unindent(content) {
var indent = content.match(/^(\s+)/);

if (indent) {
content = content.replace(new RegExp('^' + indent[1], 'gm'), '');
}

return content;
}
84 changes: 43 additions & 41 deletions lib/selleck.js
@@ -1,3 +1,4 @@
/*jshint expr: true, latedef: false */
/* /*
Selleck Selleck
Copyright (c) 2011 Yahoo! Inc. Copyright (c) 2011 Yahoo! Inc.
Expand Down Expand Up @@ -76,7 +77,7 @@ function createOutputDir(outDir) {
} }
} else { } else {
// TODO: mkdir -p // TODO: mkdir -p
fs.mkdirSync(outDir, 0755); fs.mkdirSync(outDir, parseInt('0755', 8));
} }
} }
exports.createOutputDir = createOutputDir; exports.createOutputDir = createOutputDir;
Expand Down Expand Up @@ -124,6 +125,43 @@ function findDocs(dir, docs) {
} }
exports.findDocs = findDocs; exports.findDocs = findDocs;


/**
@method writePages
**/
function writePages(outDir, options, callback) {
var ext = options['out-ext'],
toWrite = util.size(options.pages);

if (!toWrite) { return callback(); }

function finish(err) {
if (err) { return callback(err); }

if (!(toWrite -= 1)) {
callback();
}
}

// Render each page to HTML and write it to the output directory.
util.each(options.pages, function (source, name) {
var view = new options.viewClass(options.meta, name),
layout = options.layouts[view.layout];

render(source, view, layout, options.partials, function (err, html) {
if (err) { return callback(err); }

if (options.dumpViews) {
fs.writeFile(path.join(outDir, name + '.json'),
JSON.stringify(view, null, 2), 'utf8');
}

fs.writeFile(path.join(outDir, name + ext), html, 'utf8', finish);
});
});

}
exports.writePages = writePages;

/** /**
@method generate @method generate
@param {String} inDir Input directory containing docs and assets to generate. @param {String} inDir Input directory containing docs and assets to generate.
Expand Down Expand Up @@ -286,10 +324,10 @@ exports.isProjectDirectory = isProjectDirectory;
/** /**
Logs a message to stdout or stderr, with an optional log level. Logs a message to stdout or stderr, with an optional log level.
@method log @method log
@param {String} message A message to write to the console. @param {String} message A message to write to the console.
@param {String} [level] A short string describing the type of message. @param {String} [level] A short string describing the type of message.
If the level is 'error', Selleck logs the message to stderr. If the level is 'error', Selleck logs the message to stderr.
Otherwise, Selleck logs the message to stdout. Otherwise, Selleck logs the message to stdout.
The default level is 'info'. The default level is 'info'.
**/ **/
Expand All @@ -311,8 +349,7 @@ exports.log = log;
@param {Object} options Merged options. @param {Object} options Merged options.
**/ **/
function prepare(inDir, options, callback) { function prepare(inDir, options, callback) {
var compiled = {}, var meta = {},
meta = {},
type = options.component ? 'component' : 'project'; type = options.component ? 'component' : 'project';


if (options && options.skipLoad) { if (options && options.skipLoad) {
Expand Down Expand Up @@ -458,38 +495,3 @@ function render(source, view, layout, partials, callback) {
} }
exports.render = render; exports.render = render;


/**
@method writePages
**/
function writePages(outDir, options, callback) {
var ext = options['out-ext'],
toWrite = util.size(options.pages);

if (!toWrite) { return callback(); }

// Render each page to HTML and write it to the output directory.
util.each(options.pages, function (source, name) {
var view = new options.viewClass(options.meta, name),
layout = options.layouts[view.layout];

render(source, view, layout, options.partials, function (err, html) {
if (err) { return callback(err); }

if (options.dumpViews) {
fs.writeFile(path.join(outDir, name + '.json'),
JSON.stringify(view, null, 2), 'utf8');
}

fs.writeFile(path.join(outDir, name + ext), html, 'utf8', finish);
});
});

function finish(err) {
if (err) { return callback(err); }

if (!(toWrite -= 1)) {
callback();
}
}
}
exports.writePages = writePages;
6 changes: 4 additions & 2 deletions lib/server.js
Expand Up @@ -46,6 +46,8 @@ module.exports = function (config) {
if (!component.meta.examples) { return; } if (!component.meta.examples) { return; }


component.meta.examples.forEach(function (example) { component.meta.examples.forEach(function (example) {
/*jshint expr: true*/
//TODO FIX
example.componentName || (example.componentName = component.meta.name); example.componentName || (example.componentName = component.meta.name);


if (!example.modules) { return; } if (!example.modules) { return; }
Expand Down Expand Up @@ -134,7 +136,7 @@ module.exports = function (config) {
options.layouts = selleck.getLayouts(config.theme); options.layouts = selleck.getLayouts(config.theme);
options.partials = selleck.getPartials(config.theme); options.partials = selleck.getPartials(config.theme);


selleck.prepare(projectPath, options, function (err, options, compiled) { selleck.prepare(projectPath, options, function (err, options) {
if (err) { return next(err); } if (err) { return next(err); }


options.meta.components = util.values(components).sort(function (a, b) { options.meta.components = util.values(components).sort(function (a, b) {
Expand Down Expand Up @@ -185,7 +187,7 @@ module.exports = function (config) {
selleck.getPartials(projectPath) selleck.getPartials(projectPath)
); );


selleck.prepare(docPath, options, function (err, options, compiled) { selleck.prepare(docPath, options, function (err, options) {
if (err) { return next(err); } if (err) { return next(err); }


if (options.meta.examples) { if (options.meta.examples) {
Expand Down
44 changes: 23 additions & 21 deletions lib/util.js
Expand Up @@ -50,27 +50,6 @@ function escapeHTML(html) {
} }
exports.escapeHTML = escapeHTML; exports.escapeHTML = escapeHTML;


/**
Returns a new object containing a deep merge of the enumerable properties of all
passed objects. Properties in later arguments take precedence over properties
with the same name in earlier arguments. Object values are deep-cloned. Array
values are _not_ deep-cloned.
@method merge
@param {object} obj* One or more objects to merge.
@return {object} New object with merged values from all other objects.
**/
function merge() {
var args = Array.prototype.slice.call(arguments),
target = {};

args.unshift(target);
mix.apply(this, args);

return target;
}
exports.merge = merge;

/** /**
Like `merge()`, but augments the first passed object with a deep merge of the Like `merge()`, but augments the first passed object with a deep merge of the
enumerable properties of all other passed objects, rather than returning a enumerable properties of all other passed objects, rather than returning a
Expand All @@ -94,6 +73,8 @@ function mix() {
value = source[key]; value = source[key];


if (value && typeof value === 'object' && !Array.isArray(value)) { if (value && typeof value === 'object' && !Array.isArray(value)) {
/*jshint expr: true*/
//TODO FIX
typeof target[key] === 'object' || (target[key] = {}); typeof target[key] === 'object' || (target[key] = {});
mix(target[key], value); mix(target[key], value);
} else { } else {
Expand All @@ -106,6 +87,27 @@ function mix() {
} }
exports.mix = mix; exports.mix = mix;


/**
Returns a new object containing a deep merge of the enumerable properties of all
passed objects. Properties in later arguments take precedence over properties
with the same name in earlier arguments. Object values are deep-cloned. Array
values are _not_ deep-cloned.
@method merge
@param {object} obj* One or more objects to merge.
@return {object} New object with merged values from all other objects.
**/
function merge() {
var args = Array.prototype.slice.call(arguments),
target = {};

args.unshift(target);
mix.apply(this, args);

return target;
}
exports.merge = merge;

/** /**
If _obj_ is an array, returns `obj.length`. If _obj_ is an object, returns the If _obj_ is an array, returns `obj.length`. If _obj_ is an object, returns the
number of enumerable properties. number of enumerable properties.
Expand Down
2 changes: 1 addition & 1 deletion lib/view/index.js
Expand Up @@ -21,7 +21,7 @@ function View(data, templateName) {
util.mix(this, this.pages[this.templateName]); util.mix(this, this.pages[this.templateName]);
} else { } else {
/* /*
Template name was not found in this pages list, so walk all the pages and Template name was not found in this pages list, so walk all the pages and
see if any of them contain this example. If it does, then see if any of them contain this example. If it does, then
mix the data in and reset the `self.examples` before the mix the data in and reset the `self.examples` before the
below code mixes them. below code mixes them.
Expand Down

0 comments on commit 36ac891

Please sign in to comment.