From 0deced331dd284ffbb6f28f61a17d7ea8ee3ca7a Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 6 Jun 2015 18:25:00 +0800 Subject: [PATCH] allow multiple files with the same name - taken from the source of @karlspalding on #236 - fixes #303 - closes #236 --- docco.js | 20 ++++++++++++++------ docco.litcoffee | 14 ++++++++++---- resources/classic/docco.jst | 2 +- resources/linear/docco.jst | 4 ++-- resources/parallel/docco.jst | 4 ++-- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/docco.js b/docco.js index 68c94f17..931744aa 100644 --- a/docco.js +++ b/docco.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.9.1 +// Generated by CoffeeScript 1.9.3 (function() { var Docco, _, buildMatchers, commander, configure, defaults, document, format, fs, getLanguage, highlightjs, languages, marked, parse, path, run, version, write, slice = [].slice; @@ -132,9 +132,15 @@ }; write = function(source, sections, config) { - var destination, first, firstSection, hasTitle, html, title; + var css, destination, first, firstSection, hasTitle, html, relative, title; destination = function(file) { - return path.join(config.output, path.basename(file, path.extname(file)) + '.html'); + return path.join(config.output, path.dirname(file), path.basename(file, path.extname(file)) + '.html'); + }; + relative = function(file) { + var from, to; + to = path.dirname(path.resolve(file)); + from = path.dirname(path.resolve(destination(source))); + return path.join(path.relative(from, to), path.basename(file)); }; firstSection = _.find(sections, function(section) { return section.docsText.length > 0; @@ -144,17 +150,19 @@ } hasTitle = first && first.type === 'heading' && first.depth === 1; title = hasTitle ? first.text : path.basename(source); + css = relative(path.join(config.output, path.basename(config.css))); html = config.template({ sources: config.sources, - css: path.basename(config.css), + css: css, title: title, hasTitle: hasTitle, sections: sections, path: path, - destination: destination + destination: destination, + relative: relative }); console.log("docco: " + source + " -> " + (destination(source))); - return fs.writeFileSync(destination(source), html); + return fs.outputFileSync(destination(source), html); }; defaults = { diff --git a/docco.litcoffee b/docco.litcoffee index d15f3fa7..17ee6c31 100644 --- a/docco.litcoffee +++ b/docco.litcoffee @@ -195,7 +195,12 @@ and rendering it to the specified output path. write = (source, sections, config) -> destination = (file) -> - path.join(config.output, path.basename(file, path.extname(file)) + '.html') + path.join(config.output, path.dirname(file), path.basename(file, path.extname(file)) + '.html') + + relative = (file) -> + to = path.dirname(path.resolve(file)) + from = path.dirname(path.resolve(destination(source))) + path.join(path.relative(from, to), path.basename(file)) The **title** of the file is either the first heading in the prose, or the name of the source file. @@ -205,12 +210,13 @@ name of the source file. first = marked.lexer(firstSection.docsText)[0] if firstSection hasTitle = first and first.type is 'heading' and first.depth is 1 title = if hasTitle then first.text else path.basename source + css = relative path.join(config.output, path.basename(config.css)) - html = config.template {sources: config.sources, css: path.basename(config.css), - title, hasTitle, sections, path, destination,} + html = config.template {sources: config.sources, css, + title, hasTitle, sections, path, destination, relative} console.log "docco: #{source} -> #{destination source}" - fs.writeFileSync destination(source), html + fs.outputFileSync destination(source), html Configuration diff --git a/resources/classic/docco.jst b/resources/classic/docco.jst index bc956dbe..ad137b13 100644 --- a/resources/classic/docco.jst +++ b/resources/classic/docco.jst @@ -19,7 +19,7 @@
<% for (var i=0, l=sources.length; i <% var source = sources[i]; %> - + <%= path.basename(source) %> <% } %> diff --git a/resources/linear/docco.jst b/resources/linear/docco.jst index c536828b..ec73e66b 100644 --- a/resources/linear/docco.jst +++ b/resources/linear/docco.jst @@ -29,8 +29,8 @@ <% for (var i=0, l = sources.length; i < l; i++) { %> <% var source = sources[i]; %>
  • - - <%= path.basename(source) %> + + <%= source %>
  • <% } %> diff --git a/resources/parallel/docco.jst b/resources/parallel/docco.jst index 1cea1ab5..d4375522 100644 --- a/resources/parallel/docco.jst +++ b/resources/parallel/docco.jst @@ -20,8 +20,8 @@
    <% for (var i=0, l=sources.length; i <% var source = sources[i]; %> - - <%= path.basename(source) %> + + <%= source %> <% } %>