Include symbols from oli.js using interface and implements tags

Instead of regex parsing, we define tags for interface and
implements.
This commit is contained in:
Andreas Hocevar
2014-04-11 23:02:49 +02:00
committed by Tim Schaub
parent b758d92790
commit aaf6101d0f
3 changed files with 35 additions and 16 deletions

View File

@@ -1,6 +1,5 @@
/*
* This plugin parses externs/oli.js as well as goog.exportSymbol and
* goog.exportProperty calls to build a list of API symbols and properties.
* This plugin removes unexported symbols from the documentation.
* Unexported modules linked from @param or @fires will be marked unexported,
* and the documentation will not contain the constructor. Everything else is
* marked undocumented, which will remove it from the docs.
@@ -17,22 +16,9 @@ function collectExports(source) {
}
}
function collectOliExports(source) {
var oli = source.match(/[^\{]oli\.([^;^ ]*);? ?/g);
if (oli) {
i = 0; ii = oli.length;
for (; i < ii; ++i) {
property = 'ol.' + oli[i].match(/oli.([^;]*)/)[1]
.replace('.prototype.', '#');
unexported.push(property);
}
}
}
var encoding = env.conf.encoding || 'utf8';
var fs = require('jsdoc/fs');
collectExports(fs.readFileSync('build/symbols.json', encoding));
collectOliExports(fs.readFileSync('externs/oli.js', encoding));
exports.handlers = {
@@ -42,6 +28,9 @@ exports.handlers = {
if (e.doclet.meta.filename == "olx.js" && e.doclet.longname != 'olx') {
api.push(e.doclet.longname);
}
if (e.doclet.longname.indexOf('oli.') === 0) {
unexported.push(e.doclet.longname.replace(/^oli\./, 'ol.'));
}
if (api.indexOf(e.doclet.longname) > -1) {
var names, name;
var params = e.doclet.params;
@@ -87,7 +76,7 @@ exports.handlers = {
doclet.properties = [];
}
doclet.properties.unshift(propertyDoclet);
e.doclets.splice(i, 1)
e.doclets.splice(i, 1);
}
}
}
@@ -104,6 +93,11 @@ exports.handlers = {
continue;
}
}
if (doclet.memberof && doclet.memberof.indexOf('oli.') === 0 &&
unexported.indexOf(doclet.memberof) > -1) {
// Always document members of referenced oli interfaces
continue;
}
doclet.unexported = (api.indexOf(fqn) === -1 && unexported.indexOf(fqn) !== -1);
if (api.indexOf(fqn) === -1 && unexported.indexOf(fqn) === -1) {
e.doclets.splice(j, 1);

View File

@@ -0,0 +1,23 @@
var util = require('util');
exports.defineTags = function(dictionary) {
var classTag = dictionary.lookUp('class');
dictionary.defineTag('interface', {
mustHaveValue: false,
onTagged: function(doclet, tag) {
classTag.onTagged.apply(this, arguments);
doclet.interface = true;
}
});
dictionary.defineTag('implements', {
mustHaveValue: true,
onTagged: function(doclet, tag) {
if (!doclet.implements) {
doclet.implements = [];
}
doclet.implements.push(tag.value.match(/^{(.*)}$/)[1]);
}
});
};