Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update lib/index page

  • Loading branch information...
commit f42cc992c6ac43a0db90aa3bb8b3e7b02dcd4032 1 parent 47590f5
@justindujardin justindujardin authored
Showing with 47 additions and 42 deletions.
  1. +9 −7 index.html
  2. +38 −35 lib/docco.js
View
16 index.html
@@ -2,7 +2,8 @@
documentation generator. It produces HTML
that displays your comments alongside your code. Comments are passed through
<a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a>, and code is
-passed through <a href="http://pygments.org/">Pygments</a> syntax highlighting.
+passed through <a href="http://pygments.org/">Pygments</a> syntax highlighting, if it
+is present on the system.
This page is the result of running Docco against its own source file.</p>
<p>If you install Docco, you can run it from the command-line:</p>
@@ -101,13 +102,14 @@
<span class="nx">save</span> <span class="nx">docsText</span><span class="p">,</span> <span class="nx">codeText</span>
<span class="nx">sections</span></pre></div></div> </li> <li id="section-5"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div>
-<p>Highlights a single chunk of CoffeeScript code, using <strong>Pygments</strong> over stdio,
-and runs the text of its corresponding comment through <strong>Markdown</strong>, using
-<a href="http://attacklab.net/showdown/">Showdown.js</a>.</p>
+<p>Highlights parsed sections of code, using <strong>Pygments</strong> over stdio,
+and runs the text of their corresponding comments through <strong>Markdown</strong>, using
+<a href="http://attacklab.net/showdown/">Showdown.js</a>. If Pygments is not present
+on the system, output the code in plain text.</p>
-<p>We process the entire file in single calls to Pygments and Showdown by inserting
-little marker comments between each section and then splitting the result string
-wherever our markers occur.</p>
+<p>We process all sections with single calls to Pygments and Showdown, by
+inserting marker comments between each section and then splitting the result
+string wherever the marker occurs.</p>
</div> <div class="content"><div class="highlight"><pre><span class="nv">highlight = </span><span class="nf">(source, sections, callback) -&gt;</span>
<span class="nv">language = </span><span class="nx">getLanguage</span> <span class="nx">source</span>
View
73 lib/docco.js
@@ -1,11 +1,14 @@
+// Generated by CoffeeScript 1.4.0
(function() {
- var commander, defaults, document, ensureDirectory, exec, ext, fs, generateDocumentation, generateHtml, getLanguage, getResource, highlight, highlightEnd, highlightStart, htmlEscape, key, l, languages, parse, path, resolveSource, run, showdown, spawn, template, value, version, _ref, _ref2;
- var __hasProp = Object.prototype.hasOwnProperty, __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (__hasProp.call(this, i) && this[i] === item) return i; } return -1; };
+ var commander, defaults, document, ensureDirectory, exec, ext, fs, generateDocumentation, generateHtml, getLanguage, getResource, highlight, highlightEnd, highlightStart, htmlEscape, key, l, languages, parse, path, resolveSource, run, showdown, spawn, template, value, version, _ref, _ref1,
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
generateDocumentation = function(source, config, callback) {
return fs.readFile(source, function(error, buffer) {
var code, sections;
- if (error) throw error;
+ if (error) {
+ throw error;
+ }
code = buffer.toString();
sections = parse(source, code);
return highlight(source, sections, function() {
@@ -70,10 +73,12 @@
pygments.stderr.on('data', function() {});
pygments.stdin.on('error', function() {});
pygments.stdout.on('data', function(result) {
- if (result) return output += result;
+ if (result) {
+ return output += result;
+ }
});
pygments.on('exit', function() {
- var codeFragments, docsFragments, i, section, _len;
+ var codeFragments, docsFragments, i, _i, _len;
output = output.replace(highlightStart, '').replace(highlightEnd, '');
if (output === '') {
codeFragments = (function() {
@@ -89,7 +94,7 @@
codeFragments = output.split(language.codeSplitHtml);
}
docsFragments = showdown.makeHtml(docs).split(language.docsSplitHtml);
- for (i = 0, _len = sections.length; i < _len; i++) {
+ for (i = _i = 0, _len = sections.length; _i < _len; i = ++_i) {
section = sections[i];
section.codeHtml = highlightStart + codeFragments[i] + highlightEnd;
section.docsHtml = docsFragments[i];
@@ -157,22 +162,9 @@
return languages[path.extname(source)];
};
- ensureDirectory = function(dir, cb, made) {
- var mode;
- if (made == null) made = null;
- mode = parseInt('0777', 8);
- return fs.mkdir(dir, mode, function(er) {
- if (!er) return cb(null, made || dir);
- if (er.code === 'ENOENT') {
- return ensureDirectory(path.dirname(dir), function(er, made) {
- if (er) {
- return cb(er, made);
- } else {
- return ensureDirectory(dir, cb, made);
- }
- });
- }
- return cb(er, made);
+ ensureDirectory = function(dir, callback) {
+ return exec("mkdir -p " + dir, function() {
+ return callback();
});
};
@@ -193,7 +185,9 @@
};
run = function(args) {
- if (args == null) args = process.argv;
+ if (args == null) {
+ args = process.argv;
+ }
commander.version(version).usage("[options] <filePattern ...>").option("-c, --css [file]", "use a custom css file", defaults.css).option("-o, --output [path]", "use a custom output path", defaults.output).option("-t, --template [file]", "use a custom .jst template", defaults.template).parse(args).name = "docco";
if (commander.args.length) {
return document(commander.args.slice(), commander);
@@ -203,9 +197,13 @@
};
document = function(sources, options, callback) {
- var config, doccoStyles, key, m, resolved, src, value, _i, _j, _len, _len2;
- if (options == null) options = {};
- if (callback == null) callback = null;
+ var config, doccoStyles, key, m, resolved, src, value, _i, _j, _len, _len1;
+ if (options == null) {
+ options = {};
+ }
+ if (callback == null) {
+ callback = null;
+ }
config = {};
for (key in defaults) {
value = defaults[key];
@@ -225,7 +223,7 @@
config.sources = resolved.filter(function(source) {
return getLanguage(source);
}).sort();
- for (_j = 0, _len2 = resolved.length; _j < _len2; _j++) {
+ for (_j = 0, _len1 = resolved.length; _j < _len1; _j++) {
m = resolved[_j];
if (__indexOf.call(config.sources, m) < 0) {
console.log("docco: skipped unknown type (" + m + ")");
@@ -238,7 +236,9 @@
fs.writeFileSync(path.join(config.output, path.basename(config.css)), doccoStyles);
files = config.sources.slice();
nextFile = function() {
- if ((callback != null) && !files.length) callback();
+ if ((callback != null) && !files.length) {
+ callback();
+ }
if (files.length) {
return generateDocumentation(files.shift(), config, nextFile);
}
@@ -249,7 +249,9 @@
resolveSource = function(source) {
var file, file_path, files, regex, regex_str;
- if (!source.match(/([\*\?])/)) return source;
+ if (!source.match(/([\*\?])/)) {
+ return source;
+ }
regex_str = path.basename(source).replace(/\./g, "\\$&").replace(/\*/, ".*").replace(/\?/, ".");
regex = new RegExp('^(' + regex_str + ')$');
file_path = path.dirname(source);
@@ -259,24 +261,25 @@
_results = [];
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
- if (file.match(regex)) _results.push(path.join(file_path, file));
+ if (file.match(regex)) {
+ _results.push(path.join(file_path, file));
+ }
}
return _results;
})();
};
- _ref2 = {
+ _ref1 = {
run: run,
document: document,
parse: parse,
resolveSource: resolveSource,
version: version,
defaults: defaults,
- languages: languages,
- ensureDirectory: ensureDirectory
+ languages: languages
};
- for (key in _ref2) {
- value = _ref2[key];
+ for (key in _ref1) {
+ value = _ref1[key];
exports[key] = value;
}
Please sign in to comment.
Something went wrong with that request. Please try again.