Skip to content

Commit 981a315

Browse files
committed
Fix and test relative theme loading
1 parent c708f25 commit 981a315

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

lib/output/html.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var walk = require('../walk'),
4+
path = require('path'),
45
hljs = require('highlight.js');
56

67
/**
@@ -50,5 +51,9 @@ function highlight(comment, options) {
5051
module.exports = function makeHTML(comments, options, callback) {
5152
options = options || {};
5253
comments = walk(comments, highlight, options);
53-
require(options.theme || 'documentation-theme-default')(comments, options, callback);
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);
5459
};

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',

test/fixture/custom_theme/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var File = require('vinyl');
2+
3+
/**
4+
* This is a theme only used by documentation to test custom theme
5+
* support.
6+
*/
7+
module.exports = function(comments, options, callback) {
8+
return callback(null, [new File({
9+
base: '/',
10+
path: '/index.html',
11+
contents: new Buffer('Hello world')
12+
})]);
13+
};

0 commit comments

Comments
 (0)