forked from sourcey/moxygen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
107 lines (91 loc) · 3.02 KB
/
index.js
File metadata and controls
107 lines (91 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* Original work Copyright (c) 2016 Philippe FERDINAND
* Modified work Copyright (c) 2016 Kam Low
*
* @license MIT
**/
'use strict';
var path = require('path');
var util = require('util');
var doxyparser = require('./src/parser');
var templates = require('./src/templates');
var helpers = require('./src/helpers');
module.exports = {
/**
* Default options values.
**/
defaultOptions: {
directory: null, /** Location of the doxygen files **/
output: 'api.md', /** Output file **/
groups: false, /** Output doxygen groups separately **/
noindex: false, /** Disable generation of the index. Does not work with `groups` option **/
anchors: true, /** Generate anchors for internal links **/
language: 'cpp', /** Programming language **/
templates: 'templates', /** Templates directory **/
filters: {
members: [
'define',
'enum',
// 'enumvalue',
'func',
// 'variable',
'public-attrib',
'public-func',
'public-static-func',
'protected-attrib',
'protected-func'
],
compounds: [
'namespace',
'class',
'struct',
'union',
'typedef',
// 'file'
]
}
},
/**
* Parse files and render the output.
**/
run: function (options) {
// Sanitize options
if (options.groups == options.output.indexOf('%s') === -1)
throw "The `output` file parameter must contain an '%s' for group name " +
"substitution when `groups` are enabled."
if (options.templates == this.defaultOptions.templates)
options.templates = path.join(__dirname, 'templates', options.language);
// Load templates
templates.registerHelpers(options);
templates.load(options.templates);
// Parse files
doxyparser.loadIndex(options, function (err, root) {
if (err)
throw err;
// Output groups
if (options.groups) {
var groups = root.toArray('compounds', 'group');
if (!groups.length)
throw "You have enabled `groups` output, but no groups were " +
"located in your doxygen XML files."
groups.forEach(function (group) {
group.filterChildren(options.filters, group.id);
var compounds = group.toFilteredArray('compounds');
compounds.unshift(group); // insert group at top
var contents = templates.renderArray(compounds);
helpers.writeFile(util.format(options.output, group.name), contents);
});
}
// Output single file
else {
root.filterChildren(options.filters);
var compounds = root.toFilteredArray('compounds');
if (!options.noindex)
compounds.unshift(root); // insert root at top if index is enabled
var contents = templates.renderArray(compounds);
contents.push('Generated by [Moxygen](https://sourcey.com/moxygen)')
helpers.writeFile(options.output, contents);
}
});
}
}