Skip to content

Commit 0a1de4f

Browse files
jfirebaughtmcw
authored andcommitted
Theme API 2.0
1 parent b756c0c commit 0a1de4f

File tree

12 files changed

+55
-311
lines changed

12 files changed

+55
-311
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ lets you run `documentation` as a [Gulp](http://gulpjs.com/) build task.
5050
* [Node API](docs/NODE_API.md): documentation.js's self-generated documentation
5151
* [FAQ](docs/FAQ.md)
5252

53-
* [Theming HTML](docs/THEME_HTML.md): tips for theming documentation output in HTML
53+
* [Theming](docs/THEMING.md): tips for theming documentation output in HTML
5454
* [See also](docs/SEE_ALSO.md): a list of projects similar to documentation.js
5555

5656
## User Guide

docs/THEME_HTML.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/THEMING.md

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
This assumes you have node.js installed:
1+
Documentation.js supports customizable themes for HTML output. A theme is a Node.js
2+
module that exports a single function with the following signature:
23

3-
First install dev-documentation:
4-
5-
```
6-
npm install -g [email protected]
74
```
5+
/**
6+
* @function
7+
* @param {Array<Object>} comments - an array of comments to be output
8+
* @param {Object} options - theme options
9+
* @param {ThemeCallback} callback - see below
10+
*/
811
9-
Get a JSDoc-documented project to test against:
10-
12+
/**
13+
* @callback ThemeCallback
14+
* @param {?Error} error
15+
* @param {?Array<vinyl.File>} output
16+
*/
1117
```
12-
git clone [email protected]:mapbox/mapbox-gl-js.git
13-
```
14-
15-
Get a checkout of the default style
1618

17-
```
18-
[email protected]:documentationjs/documentation-theme-default.git
19-
```
20-
21-
Now start theming
22-
23-
```
24-
dev-documentation mapbox-gl-js/js/mapbox-gl.js -t ./documentation-theme-default/
25-
```
19+
The theme function should call the callback with either an error, if one occurs,
20+
or an array of [vinyl](https://github.com/gulpjs/vinyl) `File` objects.
2621

27-
If you have [LiveReload](https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei) installed, you can enable it and it'll automatically refresh the page when you edit the theme.
22+
The theme is free to implement HTML generation however it chooses. See
23+
[the default theme](https://github.com/documentationjs/documentation-theme-default/)
24+
for some ideas.

lib/get_template.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

lib/html_helpers.js

Lines changed: 0 additions & 151 deletions
This file was deleted.

lib/output/html.js

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
'use strict';
22

3-
var File = require('vinyl'),
4-
vfs = require('vinyl-fs'),
5-
concat = require('concat-stream'),
6-
Handlebars = require('handlebars'),
7-
walk = require('../walk'),
8-
getTemplate = require('../get_template'),
9-
resolveTheme = require('../resolve_theme'),
10-
helpers = require('../html_helpers'),
3+
var walk = require('../walk'),
4+
path = require('path'),
115
hljs = require('highlight.js');
126

137
/**
@@ -49,38 +43,17 @@ function highlight(comment, options) {
4943
*
5044
* @param {Array<Object>} comments parsed comments
5145
* @param {Object} options Options that can customize the output
52-
* @param {string} [options.theme] Name of a module used for an HTML theme.
46+
* @param {string} [options.theme='documentation-theme-default'] Name of a module used for an HTML theme.
5347
* @param {Function} callback called with array of results as vinyl-fs objects
5448
* @returns {undefined} calls callback
5549
* @name html
5650
*/
5751
module.exports = function makeHTML(comments, options, callback) {
5852
options = options || {};
5953
comments = walk(comments, highlight, options);
60-
61-
var themeModule = resolveTheme(options.theme);
62-
var pageTemplate = getTemplate(Handlebars, themeModule, 'index.hbs');
63-
64-
Handlebars.registerPartial('section',
65-
getTemplate(Handlebars, themeModule, 'section.hbs'));
66-
67-
var paths = comments.map(function (comment) {
68-
return comment.path.join('.');
69-
}).filter(function (path) {
70-
return path;
71-
});
72-
73-
helpers(Handlebars, paths);
74-
75-
// push assets into the pipeline as well.
76-
vfs.src([themeModule + '/assets/**'], { base: themeModule })
77-
.pipe(concat(function (files) {
78-
callback(null, files.concat(new File({
79-
path: 'index.html',
80-
contents: new Buffer(pageTemplate({
81-
docs: comments,
82-
options: options
83-
}), 'utf8')
84-
})));
85-
}));
54+
var theme = require('documentation-theme-default');
55+
if (options.theme) {
56+
theme = require(path.resolve(process.cwd(), options.theme));
57+
}
58+
theme(comments, options, callback);
8659
};

lib/resolve_theme.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@
1515
"concat-stream": "^1.5.0",
1616
"debounce": "^1.0.0",
1717
"doctrine": "^0.7.1",
18-
"documentation-theme-default": "^1.0.2",
18+
"documentation-theme-default": "documentationjs/documentation-theme-default#themes-2.0",
1919
"events": "^1.1.0",
2020
"extend": "^3.0.0",
2121
"get-comments": "^1.0.1",
2222
"github-url-from-git": "^1.4.0",
23-
"globals-docs": "^2.1.0",
24-
"handlebars": "^3.0.0",
2523
"highlight.js": "^8.4.0",
2624
"js-yaml": "^3.3.1",
2725
"jsdoc-inline-lex": "^1.0.1",
2826
"mdast": "^2.0.0",
29-
"mdast-html": "^1.2.1",
3027
"mdast-toc": "^1.1.0",
3128
"micromatch": "^2.1.6",
3229
"mime": "^1.3.4",
@@ -42,7 +39,6 @@
4239
"vfile": "^1.1.2",
4340
"vfile-reporter": "^1.4.1",
4441
"vfile-sort": "^1.0.0",
45-
"vinyl": "^0.5.0",
4642
"vinyl-fs": "^1.0.0",
4743
"yargs": "^3.31.0"
4844
},

test/bin.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ test('write to html', function (t) {
207207
}, false);
208208
}, options);
209209

210+
test('write to html with custom theme', function (t) {
211+
212+
var dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
213+
fs.mkdirSync(dstDir);
214+
215+
documentation(['build -t fixture/custom_theme --shallow fixture/internal.input.js -f html -o ' + dstDir], {},
216+
function (err, data) {
217+
t.error(err);
218+
t.equal(data, '');
219+
t.ok(fs.readFileSync(path.join(dstDir, 'index.html'), 'utf8'), 'Hello world');
220+
t.end();
221+
}, false);
222+
}, options);
223+
210224
test('write to html, highlightAuto', function (t) {
211225

212226
var fixture = 'fixture/auto_lang_hljs/multilanguage.input.js',

0 commit comments

Comments
 (0)