Merge pull request #2643 from ahocevar/interface-externs

Handle interfaces in the generate-externs task
This commit is contained in:
Andreas Hocevar
2014-08-28 13:22:15 +02:00
4 changed files with 31 additions and 10 deletions

View File

@@ -11,6 +11,7 @@
},
"plugins": [
"config/jsdoc/info/api-plugin",
"config/jsdoc/info/define-plugin"
"config/jsdoc/info/define-plugin",
"config/jsdoc/info/interface-plugin"
]
}

View File

@@ -0,0 +1,16 @@
/**
* Handle the interface annotation.
* @param {Object} dictionary The tag dictionary.
*/
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;
}
});
};

View File

@@ -28,6 +28,7 @@ exports.publish = function(data, opts) {
[
{define: {isObject: true}},
{api: {isString: true}},
{'interface': {is: true}},
function() {
return this.meta && (/[\\\/]externs$/).test(this.meta.path);
}
@@ -40,6 +41,7 @@ exports.publish = function(data, opts) {
var defines = [];
var typedefs = [];
var externs = [];
var interfaces = [];
docs.filter(function(doc) {
var include = true;
var constructor = doc.memberof;
@@ -126,7 +128,7 @@ exports.publish = function(data, opts) {
return true;
});
}
var target = isExterns ? externs : symbols;
var target = isExterns ? externs : (doc.interface ? interfaces : symbols);
target.push(symbol);
}
});
@@ -136,7 +138,8 @@ exports.publish = function(data, opts) {
symbols: symbols,
defines: defines,
typedefs: typedefs,
externs: externs
externs: externs,
interfaces: interfaces
}, null, 2));
};

View File

@@ -18,10 +18,8 @@ function getInfo(callback) {
callback(new Error('Trouble generating info: ' + err.message));
return;
}
var typedefs = require('../build/info.json').typedefs;
var symbols = require('../build/info.json').symbols;
var externs = require('../build/info.json').externs;
callback(null, typedefs, symbols, externs);
var info = require('../build/info.json');
callback(null, info.typedefs, info.symbols, info.externs, info.interfaces);
});
}
@@ -31,10 +29,11 @@ function getInfo(callback) {
* @param {Array.<Object>} typedefs List of typedefs.
* @param {Array.<Object>} symbols List of symbols.
* @param {Array.<Object>} externs List of externs.
* @param {Array.<Object>} externs List of interfaces.
* @param {string|undefined} namespace Target object for exported symbols.
* @return {string} Export code.
*/
function generateExterns(typedefs, symbols, externs) {
function generateExterns(typedefs, symbols, externs, interfaces) {
var lines = [];
var processedSymbols = {};
var constructors = {};
@@ -128,6 +127,8 @@ function generateExterns(typedefs, symbols, externs) {
externs.forEach(processSymbol);
interfaces.forEach(processSymbol);
symbols.forEach(processSymbol);
typedefs.forEach(function(typedef) {
@@ -152,10 +153,10 @@ function generateExterns(typedefs, symbols, externs) {
function main(callback) {
async.waterfall([
getInfo,
function(typedefs, symbols, externs, done) {
function(typedefs, symbols, externs, interfaces, done) {
var code, err;
try {
code = generateExterns(typedefs, symbols, externs);
code = generateExterns(typedefs, symbols, externs, interfaces);
} catch (e) {
err = e;
}