From 2fd185c966474d4c2dfaba6568dce7576d383060 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 10 Apr 2013 01:44:40 +0200 Subject: [PATCH] Only document the exported API, not every symbol There is more work to be done, because this filters out more than desired, and we don't have events documented yet. --- build.py | 1 + doc/conf.json | 6 +++- doc/plugins/exports.js | 70 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 doc/plugins/exports.js diff --git a/build.py b/build.py index c2c5685a2b..b94352bd28 100755 --- a/build.py +++ b/build.py @@ -572,6 +572,7 @@ virtual('doc', 'build/jsdoc-%(BRANCH)s-timestamp' % vars(variables)) @target('build/jsdoc-%(BRANCH)s-timestamp' % vars(variables), 'host-resources', + 'build/src/external/src/exports.js', 'build/src/external/src/types.js', SRC, SHADER_SRC, ifind('doc/template')) def jsdoc_BRANCH_timestamp(t): t.run('%(JSDOC)s', '-c', 'doc/conf.json', 'src', 'doc/index.md', diff --git a/doc/conf.json b/doc/conf.json index 986a90ec61..842c424266 100644 --- a/doc/conf.json +++ b/doc/conf.json @@ -11,7 +11,11 @@ "includePattern": ".+\\.js(doc)?$", "excludePattern": "(^|\\/|\\\\)_" }, - "plugins": [ "plugins/markdown", "doc/plugins/inheritdoc" ], + "plugins": [ + "plugins/markdown", + "doc/plugins/inheritdoc", + "doc/plugins/exports" + ], "markdown": { "parser": "gfm" }, diff --git a/doc/plugins/exports.js b/doc/plugins/exports.js new file mode 100644 index 0000000000..d7c1848fae --- /dev/null +++ b/doc/plugins/exports.js @@ -0,0 +1,70 @@ +var api = []; + +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 encoding = env.conf.encoding || 'utf8'; +var fs = require('jsdoc/fs'); + +collectExports(fs.readFileSync('build/src/external/src/exports.js', encoding)); + +var types = fs.readFileSync('build/src/external/src/types.js', encoding); +collectExports(types); +var typedefs = types.match(/goog\.provide\('[^']*'\)/g); +var typedef, namespace; +for (var i = 0, ii = typedefs.length; i < ii; ++ i) { + typedef = typedefs[i].match(/'([^']*)'/)[1]; + api.push(typedef); + namespace = typedef.substr(0, typedef.lastIndexOf('.')); + if (api.indexOf(namespace) === -1) { + api.push(namespace); + } +} + + +exports.handlers = { + + beforeParse: function(e) { + if (/\.js$/.test(e.filename)) { + collectExports(e.source); + } + }, + + newDoclet: function(e) { + var fqn = e.doclet.longname; + if (fqn) { + if (api.indexOf(fqn) === -1) { + e.doclet.undocumented = true; + } + } + } + +}; + + +exports.nodeVisitor = { + + visitNode: function(node, e, parser, currentSourceName) { + if (e.code) { + //console.log(e.source); + } + } +}; \ No newline at end of file