Skip to content

Commit

Permalink
feat(build): load passed in config option
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Dec 5, 2016
1 parent 363a108 commit 95435a7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var fs = require('fs'),
formatLint = require('./lib/lint').formatLint,
garbageCollect = require('./lib/garbage_collect'),
lintComments = require('./lib/lint').lintComments,
markdownAST = require('./lib/output/markdown_ast');
markdownAST = require('./lib/output/markdown_ast'),
loadConfig = require('./lib/load_config');

/**
* Build a pipeline of comment handlers.
Expand Down Expand Up @@ -137,6 +138,7 @@ function build(indexes, options, callback) {
*
* @param {Array<string>} indexes files to process
* @param {Object} options options
* @param {string} config path to configuration file to load
* @param {Array<string>} options.external a string regex / glob match pattern
* that defines what external modules will be whitelisted and included in the
* generated documentation.
Expand Down Expand Up @@ -172,6 +174,10 @@ function buildSync(indexes, options) {
options = options || {};
options.hljs = options.hljs || {};

if (typeof options.config === 'string') {
Object.assign(options, loadConfig(options.config));
}

if (!options.access) {
options.access = ['public', 'undefined', 'protected'];
}
Expand Down
29 changes: 29 additions & 0 deletions test/fixture/class.config.output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

# MyClass

This is my class, a demo thing.

**Properties**

- `howMany` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** how many things it contains

## getFoo

Get the number 42

**Parameters**

- `getIt` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether to get the number

Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** forty-two

## getUndefined

Get undefined

Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)** does not return anything.

# Hello

World
4 changes: 4 additions & 0 deletions test/fixture/simple.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
toc:
- MyClass
- name: Hello
description: World
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ test('highlightAuto md output', function (t) {
});
});

test('config', function (t) {
var file = path.join(__dirname, 'fixture', 'class.input.js');
var result = fs.readFileSync(path.join(__dirname, 'fixture', 'class.config.output.md')).toString();
documentation.build([file], {
config: path.join(__dirname, 'fixture', 'simple.config.yml')
}, function (err, out) {
t.ifError(err);
outputMarkdown(out, {}, function (err, md) {
t.ifError(err);

t.equal(md, result, 'rendered markdown is equal');
t.end();
});
});
});

test('multi-file input', function (t) {
documentation.build([
path.join(__dirname, 'fixture', 'simple.input.js'),
Expand Down

0 comments on commit 95435a7

Please sign in to comment.