From e560f529c6e80b590b8207bca66d841b0103b18c Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 27 Aug 2014 16:13:12 +0200 Subject: [PATCH] Handle interfaces in the generate-externs task --- config/jsdoc/info/conf.json | 3 ++- config/jsdoc/info/interface-plugin.js | 16 ++++++++++++++++ config/jsdoc/info/publish.js | 7 +++++-- tasks/generate-externs.js | 15 ++++++++------- 4 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 config/jsdoc/info/interface-plugin.js diff --git a/config/jsdoc/info/conf.json b/config/jsdoc/info/conf.json index e1c181a914..51c3048bc5 100644 --- a/config/jsdoc/info/conf.json +++ b/config/jsdoc/info/conf.json @@ -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" ] } diff --git a/config/jsdoc/info/interface-plugin.js b/config/jsdoc/info/interface-plugin.js new file mode 100644 index 0000000000..1da619a3fe --- /dev/null +++ b/config/jsdoc/info/interface-plugin.js @@ -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; + } + }); + +}; diff --git a/config/jsdoc/info/publish.js b/config/jsdoc/info/publish.js index 5d0eca556b..b8e456007e 100644 --- a/config/jsdoc/info/publish.js +++ b/config/jsdoc/info/publish.js @@ -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; @@ -118,7 +120,7 @@ exports.publish = function(data, opts) { return true; }); } - var target = isExterns ? externs : symbols; + var target = isExterns ? externs : (doc.interface ? interfaces : symbols); target.push(symbol); } }); @@ -128,7 +130,8 @@ exports.publish = function(data, opts) { symbols: symbols, defines: defines, typedefs: typedefs, - externs: externs + externs: externs, + interfaces: interfaces }, null, 2)); }; diff --git a/tasks/generate-externs.js b/tasks/generate-externs.js index c93472d5dd..178a716ef2 100644 --- a/tasks/generate-externs.js +++ b/tasks/generate-externs.js @@ -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.} typedefs List of typedefs. * @param {Array.} symbols List of symbols. * @param {Array.} externs List of externs. + * @param {Array.} 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 = {}; @@ -126,6 +125,8 @@ function generateExterns(typedefs, symbols, externs) { externs.forEach(processSymbol); + interfaces.forEach(processSymbol); + symbols.forEach(processSymbol); typedefs.forEach(function(typedef) { @@ -150,10 +151,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; }