Skip to content

Commit e76d109

Browse files
committed
Merging in multi-file relative.
2 parents 9fdb097 + 0deced3 commit e76d109

File tree

6 files changed

+41
-21
lines changed

6 files changed

+41
-21
lines changed

docco.js

+15-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docco.litcoffee

+10-4
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ and rendering it to the specified output path.
195195
write = (source, sections, config) ->
196196
197197
destination = (file) ->
198-
path.join(config.output, path.basename(file, path.extname(file)) + '.html')
198+
path.join(config.output, path.dirname(file), path.basename(file, path.extname(file)) + '.html')
199+
200+
relative = (file) ->
201+
to = path.dirname(path.resolve(file))
202+
from = path.dirname(path.resolve(destination(source)))
203+
path.join(path.relative(from, to), path.basename(file))
199204
200205
The **title** of the file is either the first heading in the prose, or the
201206
name of the source file.
@@ -205,12 +210,13 @@ name of the source file.
205210
first = marked.lexer(firstSection.docsText)[0] if firstSection
206211
hasTitle = first and first.type is 'heading' and first.depth is 1
207212
title = if hasTitle then first.text else path.basename source
213+
css = relative path.join(config.output, path.basename(config.css))
208214
209-
html = config.template {sources: config.sources, css: path.basename(config.css),
210-
title, hasTitle, sections, path, destination,}
215+
html = config.template {sources: config.sources, css,
216+
title, hasTitle, sections, path, destination, relative}
211217
212218
console.log "docco: #{source} -> #{destination source}"
213-
fs.writeFileSync destination(source), html
219+
fs.outputFileSync destination(source), html
214220
215221

216222
Configuration

index.html

+11-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ <h1 id="docco">Docco</h1>
4242
source files, with a menu linking to the other pages, saving the whole mess
4343
into a <code>docs</code> folder (configurable).</p>
4444
<p>The <a href="http://github.com/jashkenas/docco">Docco source</a> is available on GitHub,
45-
and is released under the <a href="http://opensource.org/licenses/MIT">MIT license</a>.</p>
45+
and is released under the <a href="http://lillicense.org/v1.html">Lil License</a>.</p>
4646
<p>Docco can be used to process code written in any programming language. If it
4747
doesn’t handle your favorite yet, feel free to
4848
<a href="https://github.com/jashkenas/docco/blob/master/resources/languages.json">add it to the list</a>.
@@ -238,7 +238,12 @@ <h2 id="main-documentation-generation-functions">Main Documentation Generation F
238238
<div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">write</span> = <span class="hljs-params">(source, sections, config)</span> -&gt;</span>
239239
<span class="hljs-function">
240240
<span class="hljs-title">destination</span> = <span class="hljs-params">(file)</span> -&gt;</span>
241-
path.join(config.output, path.basename(file, path.extname(file)) + <span class="hljs-string">'.html'</span>)</pre></div>
241+
path.join(config.output, path.dirname(file), path.basename(file, path.extname(file)) + <span class="hljs-string">'.html'</span>)
242+
<span class="hljs-function">
243+
<span class="hljs-title">relative</span> = <span class="hljs-params">(file)</span> -&gt;</span>
244+
to = path.dirname(path.resolve(file))
245+
<span class="hljs-keyword">from</span> = path.dirname(path.resolve(destination(source)))
246+
path.join(path.relative(<span class="hljs-keyword">from</span>, to), path.basename(file))</pre></div>
242247

243248

244249

@@ -251,12 +256,13 @@ <h2 id="main-documentation-generation-functions">Main Documentation Generation F
251256
first = marked.lexer(firstSection.docsText)[<span class="hljs-number">0</span>] <span class="hljs-keyword">if</span> firstSection
252257
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>
253258
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
259+
css = relative path.join(config.output, path.basename(config.css))
254260

255-
html = config.template {sources: config.sources, css: path.basename(config.css),
256-
title, hasTitle, sections, path, destination,}
261+
html = config.template {sources: config.sources, css,
262+
title, hasTitle, sections, path, destination, relative}
257263

258264
<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>
259-
fs.writeFileSync destination(source), html</pre></div>
265+
fs.outputFileSync destination(source), html</pre></div>
260266

261267

262268

resources/classic/docco.jst

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div id="jump_page">
2020
<% for (var i=0, l=sources.length; i<l; i++) { %>
2121
<% var source = sources[i]; %>
22-
<a class="source" href="<%= path.basename(destination(source)) %>">
22+
<a class="source" href="<%= relative(destination(source)) %>">
2323
<%= path.basename(source) %>
2424
</a>
2525
<% } %>

resources/linear/docco.jst

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<% for (var i=0, l = sources.length; i < l; i++) { %>
3030
<% var source = sources[i]; %>
3131
<li>
32-
<a class="source" href="<%= path.basename(destination(source)) %>">
33-
<%= path.basename(source) %>
32+
<a class="source" href="<%= relative(destination(source)) %>">
33+
<%= source %>
3434
</a>
3535
</li>
3636
<% } %>

resources/parallel/docco.jst

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
<div id="jump_page">
2121
<% for (var i=0, l=sources.length; i<l; i++) { %>
2222
<% var source = sources[i]; %>
23-
<a class="source" href="<%= path.basename(destination(source)) %>">
24-
<%= path.basename(source) %>
23+
<a class="source" href="<%= relative(destination(source)) %>">
24+
<%= source %>
2525
</a>
2626
<% } %>
2727
</div>

0 commit comments

Comments
 (0)