Socket
Socket
Sign inDemoInstall

styledocco

Package Overview
Dependencies
81
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.1

99

lib/main.js
(function() {
var buildRootPath, cssPath, currentDir, file, files, findFile, findit, fs, generateSourceHtml, getSections, input, jade, key, langs, link, makeDestination, menu, mkdirp, optimist, options, outputDir, overwriteResources, parser, parts, path, preProcess, readme, renderTemplate, sections, sources, templateDir, writeFile, _, _i, _len;
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;

@@ -22,14 +22,6 @@ fs = require('fs');

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').boolean('overwrite').describe('overwrite', 'Overwrite existing files in target dir').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', 'Template directory')["default"]('tmpl', "" + __dirname + "/../resources/").describe('overwrite', 'Overwrite existing files in target dir').boolean('overwrite').argv;
input = options._[0] || './';
options["in"] = options._[0] || './';
currentDir = "" + (process.cwd()) + "/";
outputDir = options.out;
templateDir = options.tmpl || ("" + __dirname + "/../resources/");
overwriteResources = options.overwrite;
getSections = function(filename) {

@@ -53,48 +45,31 @@ var blocks, data, lang, sections;

makeDestination = function(file) {
return path.join(path.dirname(file), path.basename(file, path.extname(file)) + '.html');
findFile = function(dir, re) {
var _ref;
if (!fs.statSync(dir).isDirectory()) return null;
return (_ref = fs.readdirSync(dir).filter(function(file) {
return file.match(re);
})) != null ? _ref[0] : void 0;
};
buildRootPath = function(str) {
var root;
if (path.dirname(str) === '.') {
root = path.dirname(str);
} else {
root = path.dirname(str).replace(/[^\/]+/g, '..');
}
if (root.slice(-1) !== '/') root += '/';
return root;
};
preProcess = function(filename, cb) {
var lang;
lang = langs.getLanguage(filename);
return lang.compile(filename, cb);
};
renderTemplate = function(templateName, content) {
var template, templateFile;
templateFile = "" + templateDir + templateName + ".jade";
template = fs.readFileSync(templateFile, 'utf-8');
return jade.compile(template, {
filename: templateFile
})(content);
};
generateSourceHtml = function(source, data) {
var dest, render;
dest = makeDestination(source.replace(/readme/i, 'index'));
generateFile = function(source, data) {
var dest, lang, render;
dest = _.makeDestination(source.replace(/readme/i, 'index'));
data.project = {
name: options.name,
menu: menu,
root: buildRootPath(source.replace(/readme/i, 'index'))
root: _.buildRootPath(source.replace(/readme/i, 'index'))
};
render = function(data) {
var html;
html = renderTemplate('docs', data);
console.log("styledocco: " + source + " -> " + (path.join(outputDir, dest)));
var html, template, templateFile;
templateFile = path.join(options.tmpl, 'docs.jade');
template = fs.readFileSync(templateFile, 'utf-8');
html = jade.compile(template, {
filename: templateFile
})(data);
console.log("styledocco: " + source + " -> " + (path.join(options.out, dest)));
return writeFile(dest, html);
};
if (langs.isSupported(source)) {
return preProcess(source, function(err, css) {
lang = langs.getLanguage(source);
return lang.compile(source, function(err, css) {
if (err != null) throw err;

@@ -111,3 +86,3 @@ data.css = css;

writeFile = function(dest, contents) {
dest = path.join(outputDir, dest);
dest = path.join(options.out, dest);
mkdirp.sync(path.dirname(dest));

@@ -117,5 +92,5 @@ return fs.writeFileSync(dest, contents);

mkdirp.sync(outputDir);
mkdirp.sync(options.out);
sources = findit.sync(input);
sources = findit.sync(options["in"]);

@@ -136,3 +111,3 @@ files = sources.filter(function(source) {

name: path.basename(file, path.extname(file)),
href: makeDestination(file)
href: _.makeDestination(file)
};

@@ -148,15 +123,7 @@ parts = file.split('/').splice(1);

findFile = function(dir, re) {
var _ref;
if (!fs.statSync(dir).isDirectory()) return null;
return (_ref = fs.readdirSync(dir).filter(function(file) {
return file.match(re);
})) != null ? _ref[0] : void 0;
};
readme = findFile(options["in"], /^readme/i) || findFile(process.cwd(), /^readme/i) || findFile(options.tmpl, /^readme/i);
readme = findFile(input, /^readme/i) || findFile(currentDir, /^readme/i) || findFile(templateDir, /^readme/i);
sections = getSections(readme);
generateSourceHtml(readme, {
generateFile(readme, {
menu: menu,

@@ -170,6 +137,6 @@ sections: sections,

sections = getSections(file);
return generateSourceHtml(file, {
return generateFile(file, {
menu: menu,
sections: sections,
title: '',
title: file,
description: ''

@@ -179,9 +146,9 @@ });

cssPath = path.join(outputDir, 'docs.css');
cssPath = path.join(options.out, 'docs.css');
if (overwriteResources || !path.existsSync(cssPath)) {
if (options.overwrite || !path.existsSync(cssPath)) {
fs.writeFileSync(cssPath, fs.readFileSync(__dirname + '/../resources/docs.css', 'utf-8'));
console.log("styledocco: writing " + (path.join(outputDir, 'docs.css')));
console.log("styledocco: writing " + (path.join(options.out, 'docs.css')));
}
}).call(this);

@@ -22,3 +22,3 @@ (function() {

formatCode = function(line) {
return "" + line + "\n";
return "" + (line.replace(/(;base64,)[^\)]*/, '$1...')) + "\n";
};

@@ -77,28 +77,22 @@ formatDocs = function(line) {

splitter = function(tot, cur, i) {
var newSection;
newSection = {
docs: [],
code: ''
};
if (tot.length === 0) {
tot.push(cur);
return tot;
splitter = function(sections, cur, i) {
var doc, _i, _len, _ref;
if (sections.length === 0) {
sections.push(cur);
return sections;
}
while (cur.docs.length) {
if (cur.docs[0].type === 'heading' && cur.docs[0].depth <= 2) {
while (cur.docs.length) {
newSection.docs.push(cur.docs.shift());
}
_ref = cur.docs;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
doc = _ref[_i];
if (doc.type === 'heading' && doc.depth <= 2) {
sections.push({
docs: [doc],
code: ''
});
} else {
tot[tot.length - 1].docs.push(cur.docs.shift());
sections[sections.length - 1].docs.push(doc);
}
}
if (newSection.docs.length) {
newSection.code = cur.code;
tot.push(newSection);
} else {
tot[tot.length - 1].code += cur.code;
}
return tot;
sections[sections.length - 1].code += cur.code;
return sections;
};

@@ -105,0 +99,0 @@

(function() {
var path;
path = require('path');
exports.trimNewLines = function(str) {

@@ -7,2 +10,17 @@ return str.replace(/^\n*/, '').replace(/\n*$/, '');

exports.makeDestination = function(file) {
return path.join(path.dirname(file), path.basename(file, path.extname(file)) + '.html');
};
exports.buildRootPath = function(str) {
var root;
if (path.dirname(str) === '.') {
root = path.dirname(str);
} else {
root = path.dirname(str).replace(/[^\/]+/g, '..');
}
if (root.slice(-1) !== '/') root += '/';
return root;
};
}).call(this);

@@ -7,45 +7,30 @@ {

"css",
"documentation"
],
"documentation" ],
"author": "Jacob Rask <jacob@jacobrask.net>",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "http://jacobrask.github.com/styledocco/",
"licenses": [
{
"type": "MIT",
"url": "http://github.com/jacobrask/styledocco/raw/master/LICENSE"
}
],
{ "type": "MIT",
"url": "http://github.com/jacobrask/styledocco/raw/master/LICENSE" } ],
"contributors": [
"Jacob Rask <jacob@jacobrask.net>",
"Mike Brevoort <mike@brevoort.com>",
"Jeremy Ashkenas"
],
"engines": {
"node": ">=0.4.0"
},
"bugs": {
"url": "https://github.com/jacobrask/styledocco/issues"
},
"Jeremy Ashkenas" ],
"engines": { "node": ">=0.4.0" },
"bugs": { "url": "https://github.com/jacobrask/styledocco/issues" },
"repository": {
"type": "git",
"url": "git://github.com/jacobrask/styledocco.git"
},
"url": "git://github.com/jacobrask/styledocco.git" },
"dependencies": {
"findit": "0.x.x",
"highlight.js": "1.1.x",
"jade": "0.17.x",
"marked": "0.2.x",
"mkdirp": "0.x.x",
"optimist": "0.x.x"
},
"optimist": "0.x.x" },
"devDependencies": {
"coffee-script": "1.2.x",
"nodeunit": "0.7.4"
},
"directories": {
"lib": "./lib"
},
"nodeunit": "0.7.x" },
"main": "./lib/main",
"bin": {
"styledocco": "./bin/styledocco"
}
"bin": "./bin/styledocco"
}

@@ -1,14 +0,14 @@

<pre> _______ __ __ _____
```
_______ __ __ _____
| __| |_.--.--| |-----.| \-----.----.----.-----.
|__ | _| | | | -__|| -- | _ | __| __| _ |
|_______|____|___ |__|_____||_____/_____|____|____|_____|
|_____|</pre>
|_____|
```
StyleDocco generates documentation and style guide documents from your stylesheets.
Stylesheet comments will be parsed through [Markdown](http://daringfireball.net/projects/markdown/syntax) and displayed in a generated HTML document. You can write code examples inside [GitHub Markdown](http://github.github.com/github-flavored-markdown/) code fences (<code>```</code>) or prefixed with 4 spacesin your comments, and StyleDocco both renders the HTML and shows the code example.
Stylesheet comments will be parsed through [Markdown](http://en.wikipedia.org/wiki/Markdown) and displayed in a generated HTML document. You can write code examples inside [GitHub Markdown](http://github.github.com/github-flavored-markdown/) code fences (<code>```</code>) or prefixed with 4 spaces in your comments, and StyleDocco both renders the HTML and shows the code example.
The document automatically starts a new section when it encounters a level 1 or 2 heading. Read more about the syntax in the [Markdown guide](http://daringfireball.net/projects/markdown/syntax). Only comments at the beginning of new lines are included, so to exclude something from the style guide, put some whitespace before the comment.
The document is automatically split into new sections when it encounters a level 1 or 2 heading. Read more about the heading syntax in the [Markdown guide](http://daringfireball.net/projects/markdown/syntax). Only comments at the beginning of new lines are included, so to exclude something from the style guide, put some whitespace before the comment.

@@ -26,3 +26,3 @@ If your project includes a `README` file, it will be used as the base for an `index.html`. StyleDocco will also add some default styles to your documentation, but they are easy to modify to make it fit with your project.

or clone the [GitHub repository](https://github.com/jacobrask/styledocco).
or check out this repository.

@@ -46,7 +46,14 @@ StyleDocco is free software, released under the [MIT license](https://raw.github.com/jacobrask/styledocco/master/LICENSE).

/* Provides extra visual weight and identifies the primary action in a set of buttons
```
<button class="btn primary">Primary</button>
``` */
.btn.primary {
background: blue;
color: white;
}
This page is an example itself, as it was generated from the StyleDocco readme file. The [docs](resources/docs.html) file is the documentation of the default StyleDocco CSS file.
Would display the description, a button as well as the example HTML code. The CSS will be included in the `style` element of the document.
An additional example was generated from a modified file of the [Twitter Bootstrap](examples/bootstrap/docs/less/buttons.html) project.
See the `examples` folder for more in-depth examples.

@@ -57,3 +64,1 @@

A lot of the heavy lifting in StyleDocco is done by the excellent [Marked](https://github.com/chjj/marked) module by Christopher Jeffrey. The original [Docco](https://github.com/jashkenas/docco) by Jeremy Ashkenas and [Docco Husky](https://github.com/mbrevoort/docco-husky) by Mike Brevoort were also of great help to this project.
<a href="https://github.com/jacobrask/styledocco" id="styledocco-fork-me"><img style="position:fixed;top:0;right:0;border:0;" src="https://a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub"></a>

@@ -1,1 +0,1 @@

[{"docs":"<p> An example of a reasonbly well written CSS file that you would find in &quot;the wild&quot;, but without any Markdown. \n</p>","code":"body {\n background: white; /* Set background */\n /* Good contrast */\n color: black;\n}p {\n margin: 0; /* Reset margin */\n}"}]
[{"docs":"<p> An example of a reasonbly well written CSS file that you would find in &quot;the wild&quot;, but without any Markdown. \n</p>","code":"<span class=\"tag\">body</span> <span class=\"rules\">{\n <span class=\"rule\"><span class=\"attribute\">background</span>:<span class=\"value\"> white</span>;</span> <span class=\"comment\">/* Set background */</span>\n <span class=\"comment\">/* Good contrast */</span>\n <span class=\"rule\"><span class=\"attribute\">color</span>:<span class=\"value\"> black</span>;</span>\n<span class=\"rule\">}</span></span>\n\n\n<span class=\"tag\">p</span> <span class=\"rules\">{\n <span class=\"rule\"><span class=\"attribute\">margin</span>:<span class=\"value\"> <span class=\"number\">0</span></span>;</span> <span class=\"comment\">/* Reset margin */</span>\n<span class=\"rule\">}</span></span>"}]

@@ -1,7 +0,1 @@

[
{"docs":" # Structured\nAn example of a CSS file using most of StyleDocco's features. \n",
"code":"\nbody {\n background: white;\n color: black;\n}\n\n"},
{"docs":"\nSome more text\n\n## Second level header\nSome random text. \n",
"code":"\np {\n margin: 0;\n}\n\nb {\n font-weight: italic;\n}\n"},
{"docs":" This is in the same section.\n\n```\nAnd here is some code\n```\n\n This is also code\n\n",
"code":"\n"}]
[{"docs":" # Structured\nAn example of a CSS file using most of StyleDocco's features. \n","code":"\nbody {\n background: white;\n color: black;\n}\n\n"},{"docs":"\nSome more text\n\n## Second level header\nSome random text.\n\n## Another section in the same comment block.\n\nSome <b>HTML</b> that should not be escaped.\n\n","code":"\np {\n margin: 0;\n}\n\nb {\n font-weight: italic;\n}\n"},{"docs":" This is in the same section.\n\n```\nAnd here is some code\n```\n\n This is also code\n\n","code":"\n"}]

@@ -1,1 +0,1 @@

[{"docs":"<h1>Structured</h1>\n<p>An example of a CSS file using most of StyleDocco&#39;s features. \n</p>\n<p>Some more text\n\n</p>","code":"body {\n background: white;\n color: black;\n}"},{"docs":"<h2>Second level header</h2>\n<p>Some random text. \n</p>\n<p> This is in the same section.\n\n</p>\n<div class=\"styledocco-example\">And here is some code</div><pre><code><span class=\"keyword\">And</span> here <span class=\"keyword\">is</span> some code</code></pre>\n<div class=\"styledocco-example\">This is also code</div><pre><code>This <span class=\"keyword\">is</span> also code</code></pre>","code":"p {\n margin: 0;\n}\n\nb {\n font-weight: italic;\n}"}]
[{"docs":"<h1>Structured</h1>\n<p>An example of a CSS file using most of StyleDocco&#39;s features. \n</p>\n<p>Some more text\n\n</p>","code":"<span class=\"tag\">body</span> <span class=\"rules\">{\n <span class=\"rule\"><span class=\"attribute\">background</span>:<span class=\"value\"> white</span>;</span>\n <span class=\"rule\"><span class=\"attribute\">color</span>:<span class=\"value\"> black</span>;</span>\n<span class=\"rule\">}</span></span>"},{"docs":"<h2>Second level header</h2>\n<p>Some random text.\n\n</p>","code":""},{"docs":"<h2>Another section in the same comment block.</h2>\n<p>Some <b>HTML</b> that should not be escaped.\n\n</p>\n<p> This is in the same section.\n\n</p>\n<div class=\"styledocco-example\">And here is some code</div><pre><code><span class=\"keyword\">And</span> here <span class=\"keyword\">is</span> some code</code></pre>\n<div class=\"styledocco-example\">This is also code</div><pre><code>This <span class=\"keyword\">is</span> also code</code></pre>","code":"<span class=\"tag\">p</span> <span class=\"rules\">{\n <span class=\"rule\"><span class=\"attribute\">margin</span>:<span class=\"value\"> <span class=\"number\">0</span></span>;</span>\n<span class=\"rule\">}</span></span>\n\n<span class=\"tag\">b</span> <span class=\"rules\">{\n <span class=\"rule\"><span class=\"attribute\">font-weight</span>:<span class=\"value\"> italic</span>;</span>\n<span class=\"rule\">}</span></span>"}]

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc