From 8507f83e8889ea6f838113d79877007c27ec55fc Mon Sep 17 00:00:00 2001 From: Michael Mathews Date: Sat, 15 Jan 2011 11:16:29 +0000 Subject: [PATCH] Added support for @access tag. --- modules/jsdoc/tag/dictionary/definitions.js | 16 +++++++++++++++- test/cases/accesstag.js | 13 +++++++++++++ test/runner.js | 1 + test/t/cases/accesstag.js | 21 +++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/cases/accesstag.js create mode 100644 test/t/cases/accesstag.js diff --git a/modules/jsdoc/tag/dictionary/definitions.js b/modules/jsdoc/tag/dictionary/definitions.js index 54bbabd3..22862459 100644 --- a/modules/jsdoc/tag/dictionary/definitions.js +++ b/modules/jsdoc/tag/dictionary/definitions.js @@ -7,7 +7,21 @@ */ (function() { exports.defineTags = function(dictionary) { - + + dictionary.defineTag('access', { + musHaveValue: true, + onTagged: function(doclet, tag) { + if ( /^(private|protected)$/.test(tag.value) ) { + doclet.access = tag.value; + } + else if (tag.value === 'public') { + delete doclet.access; + } + + return true; + } + }); + dictionary.defineTag('borrows', { mustHaveValue: true, onTagged: function(doclet, tag) { diff --git a/test/cases/accesstag.js b/test/cases/accesstag.js new file mode 100644 index 00000000..eebe3f5b --- /dev/null +++ b/test/cases/accesstag.js @@ -0,0 +1,13 @@ +/** @constructor */ +function Thingy() { + + /** @access private */ + var foo = 0; + + /** @access protected */ + this._bar = 1; + + /** @access public */ + this.pez = 2; + +} \ No newline at end of file diff --git a/test/runner.js b/test/runner.js index 4e14cc8a..92c9fafb 100644 --- a/test/runner.js +++ b/test/runner.js @@ -89,6 +89,7 @@ testFile('test/t/cases/modules/data/mod-2.js'); testFile('test/t/cases/alias.js'); testFile('test/t/cases/alias2.js'); +testFile('test/t/cases/accesstag.js'); testFile('test/t/cases/globaltag.js'); report(); diff --git a/test/t/cases/accesstag.js b/test/t/cases/accesstag.js new file mode 100644 index 00000000..02477646 --- /dev/null +++ b/test/t/cases/accesstag.js @@ -0,0 +1,21 @@ +(function() { + var docSet = testhelpers.getDocSetFromFile('test/cases/accesstag.js'), + foo = docSet.getByLongname('Thingy~foo')[0], + _bar = docSet.getByLongname('Thingy#_bar')[0], + pez = docSet.getByLongname('Thingy#pez')[0]; + + //dump(docSet.doclets); + + test('When a symbol has a @private tag, the doclet has a access="private" property.', function() { + assert.equal(foo.access, 'private'); + }); + + test('When a symbol has a @protected tag, the doclet has a access="protected" property.', function() { + assert.equal(_bar.access, 'protected'); + }); + + test('When a symbol has a @public tag, the doclet has no access property.', function() { + assert.equal(typeof pez.access, 'undefined'); + }); + +})(); \ No newline at end of file