Skip to content

Commit

Permalink
Merging in multi-file relative.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Dec 19, 2017
2 parents 9fdb097 + 0deced3 commit e76d109
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
22 changes: 15 additions & 7 deletions docco.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions docco.litcoffee
Expand Up @@ -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.
Expand All @@ -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
Expand Down
16 changes: 11 additions & 5 deletions index.html
Expand Up @@ -42,7 +42,7 @@ <h1 id="docco">Docco</h1>
source files, with a menu linking to the other pages, saving the whole mess
into a <code>docs</code> folder (configurable).</p>
<p>The <a href="http://github.com/jashkenas/docco">Docco source</a> is available on GitHub,
and is released under the <a href="http://opensource.org/licenses/MIT">MIT license</a>.</p>
and is released under the <a href="http://lillicense.org/v1.html">Lil License</a>.</p>
<p>Docco can be used to process code written in any programming language. If it
doesn’t handle your favorite yet, feel free to
<a href="https://github.com/jashkenas/docco/blob/master/resources/languages.json">add it to the list</a>.
Expand Down Expand Up @@ -238,7 +238,12 @@ <h2 id="main-documentation-generation-functions">Main Documentation Generation F
<div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">write</span> = <span class="hljs-params">(source, sections, config)</span> -&gt;</span>
<span class="hljs-function">
<span class="hljs-title">destination</span> = <span class="hljs-params">(file)</span> -&gt;</span>
path.join(config.output, path.basename(file, path.extname(file)) + <span class="hljs-string">'.html'</span>)</pre></div>
path.join(config.output, path.dirname(file), path.basename(file, path.extname(file)) + <span class="hljs-string">'.html'</span>)
<span class="hljs-function">
<span class="hljs-title">relative</span> = <span class="hljs-params">(file)</span> -&gt;</span>
to = path.dirname(path.resolve(file))
<span class="hljs-keyword">from</span> = path.dirname(path.resolve(destination(source)))
path.join(path.relative(<span class="hljs-keyword">from</span>, to), path.basename(file))</pre></div>



Expand All @@ -251,12 +256,13 @@ <h2 id="main-documentation-generation-functions">Main Documentation Generation F
first = marked.lexer(firstSection.docsText)[<span class="hljs-number">0</span>] <span class="hljs-keyword">if</span> firstSection
hasTitle = first <span class="hljs-keyword">and</span> first.type <span class="hljs-keyword">is</span> <span class="hljs-string">'heading'</span> <span class="hljs-keyword">and</span> first.depth <span class="hljs-keyword">is</span> <span class="hljs-number">1</span>
title = <span class="hljs-keyword">if</span> hasTitle <span class="hljs-keyword">then</span> first.text <span class="hljs-keyword">else</span> 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}

<span class="hljs-built_in">console</span>.log <span class="hljs-string">"docco: <span class="hljs-subst">#{source}</span> -&gt; <span class="hljs-subst">#{destination source}</span>"</span>
fs.writeFileSync destination(source), html</pre></div>
fs.outputFileSync destination(source), html</pre></div>



Expand Down
2 changes: 1 addition & 1 deletion resources/classic/docco.jst
Expand Up @@ -19,7 +19,7 @@
<div id="jump_page">
<% for (var i=0, l=sources.length; i<l; i++) { %>
<% var source = sources[i]; %>
<a class="source" href="<%= path.basename(destination(source)) %>">
<a class="source" href="<%= relative(destination(source)) %>">
<%= path.basename(source) %>
</a>
<% } %>
Expand Down
4 changes: 2 additions & 2 deletions resources/linear/docco.jst
Expand Up @@ -29,8 +29,8 @@
<% for (var i=0, l = sources.length; i < l; i++) { %>
<% var source = sources[i]; %>
<li>
<a class="source" href="<%= path.basename(destination(source)) %>">
<%= path.basename(source) %>
<a class="source" href="<%= relative(destination(source)) %>">
<%= source %>
</a>
</li>
<% } %>
Expand Down
4 changes: 2 additions & 2 deletions resources/parallel/docco.jst
Expand Up @@ -20,8 +20,8 @@
<div id="jump_page">
<% for (var i=0, l=sources.length; i<l; i++) { %>
<% var source = sources[i]; %>
<a class="source" href="<%= path.basename(destination(source)) %>">
<%= path.basename(source) %>
<a class="source" href="<%= relative(destination(source)) %>">
<%= source %>
</a>
<% } %>
</div>
Expand Down

0 comments on commit e76d109

Please sign in to comment.