Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'justind/windows'

  • Loading branch information...
commit 0fcc55c08c18e88dbf524d573a57405b3659b62b 2 parents 9fe9d5f + 2b2641e
@justindujardin justindujardin authored
View
3  Cakefile
@@ -8,8 +8,9 @@ option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
option '-w', '--watch', 'continually build the docco library'
task 'build', 'build the docco library', (options) ->
- coffee = spawn 'coffee', ['-c' + (if options.watch then 'w' else ''), '-o', 'lib', 'src']
+ coffee = spawn 'node', ['./node_modules/coffee-script/bin/coffee','-c' + (if options.watch then 'w' else ''), '-o', 'lib', 'src']
coffee.stdout.on 'data', (data) -> console.log data.toString().trim()
+ coffee.stderr.on 'data', (data) -> console.log data.toString().trim()
task 'install', 'install the `docco` command into /usr/local (or --prefix)', (options) ->
base = options.prefix or '/usr/local'
View
13 README
@@ -12,9 +12,7 @@ documentation generator. For more information, see:
http://jashkenas.github.com/docco/
-$ docco
-
- Usage: docco [options] <filePattern ...>
+Usage: docco [options] <filePattern ...>
Options:
@@ -22,4 +20,11 @@ $ docco
-V, --version output the version number
-c, --css [file] use a custom css file
-o, --output [path] use a custom output path
- -t, --template [file] use a custom .jst template
+ -t, --template [file] use a custom .jst template
+
+Building and Testing:
+
+ npm install
+ cake build
+ cake test
+
View
35 lib/docco.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.3.3
(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, _ref1,
+ var commander, defaults, document, ensureDirectory, exec, ext, fs, generateDocumentation, generateHtml, getLanguage, getResource, highlight, highlightEnd, highlightStart, 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) {
@@ -70,8 +70,15 @@
}
return _results;
})()).join(language.docsSplitText);
- pygments.stderr.on('data', function() {});
- pygments.stdin.on('error', function() {});
+ pygments.stderr.on('data', function(error) {
+ if (error) {
+ return console.error(error.toString());
+ }
+ });
+ pygments.stdin.on('error', function(error) {
+ console.error('Could not use Pygments to highlight the source.');
+ return process.exit(1);
+ });
pygments.stdout.on('data', function(result) {
if (result) {
return output += result;
@@ -80,19 +87,7 @@
pygments.on('exit', function() {
var codeFragments, docsFragments, i, _i, _len;
output = output.replace(highlightStart, '').replace(highlightEnd, '');
- if (output === '') {
- codeFragments = (function() {
- var _i, _len, _results;
- _results = [];
- for (_i = 0, _len = sections.length; _i < _len; _i++) {
- section = sections[_i];
- _results.push(htmlEscape(section.codeText));
- }
- return _results;
- })();
- } else {
- codeFragments = output.split(language.codeSplitHtml);
- }
+ codeFragments = output.split(language.codeSplitHtml);
docsFragments = showdown.makeHtml(docs).split(language.docsSplitHtml);
for (i = _i = 0, _len = sections.length; _i < _len; i = ++_i) {
section = sections[i];
@@ -107,10 +102,6 @@
}
};
- htmlEscape = function(string) {
- return string.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g, '&#x2F;');
- };
-
generateHtml = function(source, sections, config) {
var dest, destination, html, title;
destination = function(filepath) {
@@ -154,7 +145,7 @@
l.commentFilter = /(^#![/]|^\s*#\{)/;
l.codeSplitText = "\n" + l.symbol + "DIVIDER\n";
l.codeSplitHtml = RegExp("\\n*<span\\sclass=\"c1?\">" + l.symbol + "DIVIDER<\\/span>\\n*");
- l.docsSplitText = "\n#" + l.name + "DOCDIVIDER\n";
+ l.docsSplitText = "\n# " + l.name + "DOCDIVIDER\n";
l.docsSplitHtml = RegExp("<h1>" + l.name + "DOCDIVIDER</h1>");
}
@@ -163,7 +154,7 @@
};
ensureDirectory = function(dir, callback) {
- return exec("mkdir -p " + dir, function() {
+ return fs.mkdir(dir, function() {
return callback();
});
};
View
6 package.json
@@ -15,7 +15,11 @@
"lib" : "./lib"
},
"dependencies": {
- "commander" : ">=0.5.2"
+ "commander": ">=0.5.2"
+ },
+ "devDependencies": {
+ "coffee-script": "1.1.3",
+ "rimraf" :">=2.0.2"
},
"main" : "./lib/docco",
"bin": {
View
11 src/docco.coffee
@@ -216,8 +216,14 @@ for ext, l of languages
getLanguage = (source) -> languages[path.extname(source)]
# Ensure that the destination directory exists.
-ensureDirectory = (dir, callback) ->
- exec "mkdir -p #{dir}", -> callback()
+ensureDirectory = (dir, cb, made=null) ->
+ mode = parseInt '0777', 8
+ fs.mkdir dir, mode, (er) ->
+ return cb null, made || dir if not er
+ if er.code == 'ENOENT'
+ return ensureDirectory path.dirname(dir), (er, made) ->
+ if er then cb er, made else ensureDirectory dir, cb, made
+ cb er, made
# Micro-templating, originally by John Resig, borrowed by way of
# [Underscore.js](http://documentcloud.github.com/underscore/).
@@ -328,4 +334,5 @@ exports[key] = value for key, value of {
version : version
defaults : defaults
languages : languages
+ ensureDirectory: ensureDirectory
}
View
26 test/tests.coffee
@@ -1,7 +1,7 @@
-{spawn, exec} = require 'child_process'
path = require 'path'
fs = require 'fs'
+rimraf = require 'rimraf'
# Determine the test and resources paths
testPath = path.dirname fs.realpathSync(__filename)
@@ -12,8 +12,9 @@ resourcesPath = path.normalize path.join(testPath,"/../resources")
# is equal to what is expected.
testDoccoRun = (testName,sources,options=null,callback=null) ->
destPath = path.join dataPath, testName
- cleanup = (callback) -> exec "rm -rf #{destPath}", callback
- cleanup ->
+ cleanup = (callback) -> rimraf destPath, callback
+ cleanup (error) ->
+ eq not error, true, "path cleaned up properly"
options?.output = destPath
Docco.document sources, options, ->
files = []
@@ -83,12 +84,12 @@ test "single line comment parsing", ->
# *Kick off the first language test*
testNextLanguage languageKeys.slice()
-
+
# **URL references should resolve across sections**
#
# Resolves [Issue 100](https://github.com/jashkenas/docco/issues/100)
test "url references", ->
- exec "mkdir -p #{dataPath}", ->
+ Docco.ensureDirectory dataPath, ->
sourceFile = "#{dataPath}/_urlref.coffee"
fs.writeFileSync sourceFile, [
"# Look at this link to [Google][]!",
@@ -99,8 +100,21 @@ test "url references", ->
].join('\n')
outPath = path.join dataPath, "_urlreferences"
outFile = "#{outPath}/_urlref.html"
- exec "rm -rf #{outPath}", ->
+ rimraf outPath, (error) ->
+ eq not error, true
Docco.document [sourceFile], output: outPath, ->
contents = fs.readFileSync(outFile).toString()
count = contents.match ///<a\shref="http://www.google.com">Google</a>///g
eq count.length, 2, "find expected (2) resolved url references"
+# **Paths should be recursively created if needed**
+#
+# ensureDirectory should properly create complex output paths.
+test "create complex paths that do not exist", ->
+ exist = fs.existsSync or path.existsSync
+ outputPath = path.join dataPath, 'complex/path/that/doesnt/exist'
+ rimraf outputPath, (error) ->
+ eq not error, true
+ Docco.ensureDirectory outputPath, ->
+ equal exist(outputPath), true, 'created output path'
+ stat = fs.statSync outputPath
+ equal stat.isDirectory(), true, "target is directory"
Please sign in to comment.
Something went wrong with that request. Please try again.