Parser
class
new Parser()
The class that parses the dox tags.
class Parser {
constructor(options) {
if (options) {
this.options = options;
this.start();
}
}
start
method
Parser.prototype.start()
Starts the parser.
start() {
var {
source,
extension,
blacklist
} = this.options;
// Parse the files
this.files = Parser.parse(source, extension, blacklist);
}
parse
method
Parser.parse()
Option name | Type | Description |
---|---|---|
source | String, Array | The source(s) to parse |
extension | String | The file extension |
ignore | Array | The files to ignore |
return | Array | The parsed files |
Parses the source
static parse(source, extension, ignore) {
if (_.isArray(source)) {
return source.map(doc => {
var targetName = doc.name + '.' + extension;
if (!doc.targetName) doc.targetName = targetName;
doc.symbols = Symbol.structure(doc.dox, doc.targetName);
return doc;
});
} else {
source = Path.resolve(process.cwd(), source);
let files = Dir.collectFiles(source, {
ignore
});
return files.map(file => {
var dox = Parser.parseComments(Path.join(source, file));
var targetName = file + '.' + extension;
return {
name: file.replace(/\\/g, '/'),
targetName: targetName.replace(/\\/g, '/'),
dox,
symbols: Symbol.structure(dox, targetName)
};
});
}
}
parseComments
method
Parser.parseComments()
Option name | Type | Description |
---|---|---|
filepath | string | The path to the source |
return | object | Returns a JSON representation of the tags as an array |
Parses the source's comments using dox.
static parseComments(filepath) {
var json = null;
try {
json = dox.parseComments(File.readFileSync(filepath).toString(), {
raw: false
});
} catch (error) {
console.error('Doxx [error]:', error);
return [];
}
return json.filter(Parser.shouldPass).map(Symbol.map);
}
JSFiddle
shouldPass
method
Parser.shouldPass()
Option name | Type | Description |
---|---|---|
symbol | Object | symbol to check against |
return | Boolean | true if the symbol is not private nor must be ignored |
Tests if a symbol should be ignored or not.
static shouldPass(symbol) {
if (symbol.isPrivate) {
return false;
}
if (symbol.ignore) {
return false;
} // Only for coffeescript
return symbol.tags.filter(function(tag) {
return tag.type === 'private' || tag.type === 'ignore';
}).length === 0;
}
}
export default Parser;