From b758d9279037a7a45418df7b3d39f01913bc0851 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Fri, 11 Apr 2014 14:32:18 +0200 Subject: [PATCH] Use symbols.json for determining the API Also to get rid of regular expression parsing, instead of collecting exports for observables from the source files, we use the 'observable' annotations. --- apidoc/plugins/exports.js | 43 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/apidoc/plugins/exports.js b/apidoc/plugins/exports.js index b0e25ce603..7d2f147269 100644 --- a/apidoc/plugins/exports.js +++ b/apidoc/plugins/exports.js @@ -8,25 +8,12 @@ var api = []; var unexported = []; +var observablesByClass = {}; function collectExports(source) { - var i, ii, symbol, property; - var syms = source.match(/goog\.exportSymbol\([^\)]*\)/g); - if (syms) { - i = 0; ii = syms.length; - for (; i < ii; ++i) { - symbol = syms[i].match(/'([^']*)'/)[1]; - api.push(symbol); - } - } - var props = source.match(/goog\.exportProperty\([^\)]*\)/g); - if (props) { - i = 0; ii = props.length; - for (; i < ii; ++i) { - property = props[i].match(/[^,]*,[^,]*,\r?\n? *([^\)]*)\)/)[1] - .replace('.prototype.', '#'); - api.push(property); - } + var symbols = JSON.parse(source).symbols; + for (var i = 0, ii = symbols.length; i < ii; ++i) { + api.push(symbols[i].name); } } @@ -44,18 +31,12 @@ function collectOliExports(source) { var encoding = env.conf.encoding || 'utf8'; var fs = require('jsdoc/fs'); -collectExports(fs.readFileSync('build/exports.js', encoding)); +collectExports(fs.readFileSync('build/symbols.json', encoding)); collectOliExports(fs.readFileSync('externs/oli.js', encoding)); exports.handlers = { - beforeParse: function(e) { - if (/\.js$/.test(e.filename)) { - collectExports(e.source); - } - }, - newDoclet: function(e) { var i, ii, j, jj; if (e.doclet.meta.filename == "olx.js" && e.doclet.longname != 'olx') { @@ -87,6 +68,12 @@ exports.handlers = { } } } + if (e.doclet.observables) { + var observables = observablesByClass[e.doclet.longname] = []; + for (i = e.doclet.observables.length - 1; i >= 0; --i) { + observables.push(e.doclet.observables[i].name); + } + } }, parseComplete: function(e) { @@ -109,6 +96,14 @@ exports.handlers = { } var fqn = doclet.longname; if (fqn) { + var getterOrSetter = fqn.match(/([^#]*)#[gs]et(.*)/); + if (getterOrSetter) { + var observables = observablesByClass[getterOrSetter[1]]; + if (observables && observables.indexOf(getterOrSetter[2].toLowerCase()) > -1) { + // Always document getters/setters of observables + 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);