Skip to content

Commit

Permalink
Added an option to strip path prefixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
elaberge committed Nov 4, 2020
1 parent 0589898 commit 642a0ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions docco.js

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

9 changes: 7 additions & 2 deletions docco.litcoffee
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ and rendering it to the specified output path.
write = (source, sections, config) ->
destination = (file) ->
path.join(config.output, path.dirname(file), path.basename(file, path.extname(file)) + '.html')
path.join(config.output, path.dirname(file).replace(config.prefix, ''), path.basename(file, path.extname(file)) + '.html')
relative = (file) ->
to = path.dirname(path.resolve(file))
Expand All @@ -216,9 +216,10 @@ name of the source file.
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))
prefix = config.prefix
html = config.template {sources: config.sources, css,
title, hasTitle, sections, path, destination, relative}
title, hasTitle, sections, path, destination, relative, prefix}
console.log "docco: #{source} -> #{destination source}"
fs.outputFileSync destination(source), html
Expand All @@ -233,6 +234,7 @@ user-specified options.
defaults =
layout: 'parallel'
output: 'docs'
prefix: ''
template: null
css: null
extension: null
Expand All @@ -248,6 +250,8 @@ source files for languages for which we have definitions.
config.languages = buildMatchers config.languages
config.prefix = new RegExp "^#{config.prefix}(\/?)"
The user is able to override the layout file used with the `--template` parameter.
In this case, it is also neccessary to explicitly specify a stylesheet file.
These custom templates are compiled exactly like the predefined ones, but the `public` folder
Expand Down Expand Up @@ -341,6 +345,7 @@ Parse options using [Commander](https://github.com/visionmedia/commander.js).
.option('-L, --languages [file]', 'use a custom languages.json', _.compose JSON.parse, fs.readFileSync)
.option('-l, --layout [name]', 'choose a layout (parallel, linear or classic)', c.layout)
.option('-o, --output [path]', 'output to a given folder', c.output)
.option('-p, --prefix [path]', 'trim file prefix', c.prefix)
.option('-c, --css [file]', 'use a custom css file', c.css)
.option('-t, --template [file]', 'use a custom .jst template', c.template)
.option('-e, --extension [ext]', 'assume a file extension for all inputs', c.extension)
Expand Down
2 changes: 1 addition & 1 deletion resources/parallel/docco.jst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<% for (var i=0, l=sources.length; i<l; i++) { %>
<% var source = sources[i]; %>
<a class="source" href="<%= relative(destination(source)) %>">
<%= source %>
<%= source.replace(prefix, '') %>
</a>
<% } %>
</div>
Expand Down

0 comments on commit 642a0ec

Please sign in to comment.