styledocco
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -51,3 +51,3 @@ (function() { | ||
} else { | ||
preCmd = "" + this.preprocessor.cmd + " " + (args.join(' ')) + " " + filename; | ||
preCmd = "" + this.preprocessor.cmd + " " + (this.preprocessor.args.join(' ')) + " " + filename; | ||
} | ||
@@ -54,0 +54,0 @@ return exec(preCmd, function(err, stdout, stderr) { |
(function() { | ||
var cssPath, file, files, findFile, findit, fs, generateFile, getSections, jade, key, langs, link, menu, mkdirp, optimist, options, parser, parts, path, readme, sections, sources, writeFile, _, _i, _len; | ||
var cssFile, cssFileOut, file, files, findit, fs, generateFile, getSections, jade, key, langs, link, menu, mkdirp, optimist, options, parser, parts, path, readme, sections, sources, templateFile, writeFile, _, _i, _len; | ||
@@ -8,4 +8,2 @@ fs = require('fs'); | ||
mkdirp = require('mkdirp'); | ||
findit = require('findit'); | ||
@@ -15,2 +13,4 @@ | ||
mkdirp = require('mkdirp'); | ||
optimist = require('optimist'); | ||
@@ -24,15 +24,18 @@ | ||
options = optimist.usage('Usage: $0 [options] [INPUT]').describe('name', 'Name of the project').alias('n', 'name').demand('name').describe('out', 'Output directory').alias('o', 'out')["default"]('out', 'docs').describe('tmpl', 'Template directory')["default"]('tmpl', "" + __dirname + "/../resources/").describe('overwrite', 'Overwrite existing files in target dir').boolean('overwrite').describe('nocss', 'Hide CSS code pane').boolean('nocss')["default"]('nocss', false).describe('preprocessor', 'Custom preprocessor command').argv; | ||
options = optimist.usage('Usage: $0 [options] [INPUT]').describe('name', 'Name of the project').alias('n', 'name').demand('name').describe('out', 'Output directory').alias('o', 'out')["default"]('out', 'docs').describe('tmpl', 'Custom template directory')["default"]('tmpl', path.resolve(__dirname, '../resources/')).describe('overwrite', 'Overwrite existing files in target dir').boolean('overwrite').describe('preprocessor', 'Custom preprocessor command').argv; | ||
options["in"] = options._[0] || './'; | ||
templateFile = path.existsSync(path.join(options.tmpl, 'docs.jade')) ? path.join(options.tmpl, 'docs.jade') : path.resolve(__dirname, '../resources/docs.jade'); | ||
cssFile = path.existsSync(path.join(options.tmpl, 'docs.css')) ? path.join(options.tmpl, 'docs.css') : path.resolve(__dirname, '../resources/docs.css'); | ||
getSections = function(filename) { | ||
var blocks, data, lang, sections; | ||
data = fs.readFileSync(filename, "utf-8"); | ||
var data, lang; | ||
lang = langs.getLanguage(filename); | ||
data = fs.readFileSync(filename, 'utf-8'); | ||
if (lang != null) { | ||
blocks = parser.extractBlocks(lang, data); | ||
sections = parser.makeSections(blocks); | ||
return parser.makeSections(parser.extractBlocks(lang, data)); | ||
} else { | ||
sections = parser.makeSections([ | ||
return parser.makeSections([ | ||
{ | ||
@@ -44,18 +47,4 @@ docs: data, | ||
} | ||
return sections; | ||
}; | ||
findFile = function(dir, re) { | ||
var file, _ref; | ||
if (!fs.statSync(dir).isDirectory()) return null; | ||
file = (_ref = fs.readdirSync(dir).filter(function(file) { | ||
return file.match(re); | ||
})) != null ? _ref[0] : void 0; | ||
if (file != null) { | ||
return path.join(dir, file); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
generateFile = function(source, data) { | ||
@@ -68,8 +57,6 @@ var dest, lang, render; | ||
menu: menu, | ||
root: _.buildRootPath(source), | ||
nocss: options.nocss | ||
root: _.buildRootPath(source) | ||
}; | ||
render = function(data) { | ||
var html, template, templateFile; | ||
templateFile = path.join(options.tmpl, 'docs.jade'); | ||
var html, template; | ||
template = fs.readFileSync(templateFile, 'utf-8'); | ||
@@ -101,8 +88,6 @@ html = jade.compile(template, { | ||
mkdirp.sync(options.out); | ||
sources = findit.sync(options["in"]); | ||
files = sources.filter(function(source) { | ||
if (source.match(/(\/|^)\./)) return false; | ||
if (source.match(/(\/|^)\.[^\.]/)) return false; | ||
if (source.match(/(\/|^)_.*\.s[ac]ss$/)) return false; | ||
@@ -123,3 +108,3 @@ if (!langs.isSupported(source)) return false; | ||
parts = file.split('/').splice(1); | ||
key = parts.length > 1 ? parts[0] : './'; | ||
key = (parts[0] != null) || './'; | ||
if (menu[key] != null) { | ||
@@ -132,6 +117,8 @@ menu[key].push(link); | ||
readme = findFile(options["in"], /^readme/i) || findFile(process.cwd(), /^readme/i) || findFile(options.tmpl, /^readme/i); | ||
readme = _.findFile(options["in"], /^readme/i) || _.findFile(process.cwd(), /^readme/i) || _.findFile(options.tmpl, /^readme/i) || path.resolve(__dirname, '../resources/README.md'); | ||
sections = getSections(readme); | ||
mkdirp.sync(options.out); | ||
generateFile(readme, { | ||
@@ -154,9 +141,9 @@ menu: menu, | ||
cssPath = path.join(options.out, 'docs.css'); | ||
cssFileOut = path.join(options.out, 'docs.css'); | ||
if (options.overwrite || !path.existsSync(cssPath)) { | ||
fs.writeFileSync(cssPath, fs.readFileSync(path.join(options.tmpl, 'docs.css'), 'utf-8')); | ||
console.log("styledocco: writing " + (path.join(options.out, 'docs.css'))); | ||
if (options.overwrite || !path.existsSync(cssFileOut)) { | ||
fs.writeFileSync(cssFileOut, fs.readFileSync(cssFile, 'utf-8')); | ||
console.log("styledocco: writing " + cssFileOut); | ||
} | ||
}).call(this); |
(function() { | ||
var path; | ||
var fs, path; | ||
fs = require('fs'); | ||
path = require('path'); | ||
@@ -25,2 +27,15 @@ | ||
exports.findFile = function(dir, re) { | ||
var file, _ref; | ||
if (!fs.statSync(dir).isDirectory()) return null; | ||
file = (_ref = fs.readdirSync(dir).filter(function(file) { | ||
return file.match(re); | ||
})) != null ? _ref[0] : void 0; | ||
if (file != null) { | ||
return path.join(dir, file); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
}).call(this); |
{ | ||
"name": "styledocco", | ||
"description": "Generate a style guide from your stylesheets.", | ||
"description": "Generate style guides and documentation from your stylesheets.", | ||
"keywords": [ | ||
@@ -9,3 +9,3 @@ "styleguide", | ||
"author": "Jacob Rask <jacob@jacobrask.net>", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"homepage": "http://jacobrask.github.com/styledocco/", | ||
@@ -12,0 +12,0 @@ "licenses": [ |
@@ -43,3 +43,2 @@ ``` | ||
* `--overwrite` Overwrite existing files (`docs.css`) in target directory. *(default: false)* | ||
* `--nocss` Hide CSS code pane. *(default: false)* | ||
* `--preprocessor` Custom preprocessor command. *(optional)* (ex: `--preprocessor "scss --load-path=deps/"`) | ||
@@ -46,0 +45,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
342194
51
1533
75
4