add exception/throws to default tag list for Markdown plugin (#736)

Plus some test refactoring.

Thanks to @otakustay for suggesting this change.
This commit is contained in:
Jeff Williams 2014-11-07 15:17:52 -08:00
parent 8f1d892fbf
commit 36065d22e8
4 changed files with 75 additions and 36 deletions

View File

@ -1,4 +1,3 @@
/*global env: true */
/** /**
* @overview Translate doclet descriptions from MarkDown into HTML. * @overview Translate doclet descriptions from MarkDown into HTML.
* @module plugins/markdown * @module plugins/markdown
@ -7,8 +6,16 @@
*/ */
'use strict'; 'use strict';
var conf = env.conf.markdown; var config = global.env.conf.markdown || {};
var defaultTags = [ 'classdesc', 'description', 'params', 'properties', 'returns', 'see']; var defaultTags = [
'classdesc',
'description',
'exceptions',
'params',
'properties',
'returns',
'see'
];
var hasOwnProp = Object.prototype.hasOwnProperty; var hasOwnProp = Object.prototype.hasOwnProperty;
var parse = require('jsdoc/util/markdown').getParser(); var parse = require('jsdoc/util/markdown').getParser();
var tags = []; var tags = [];
@ -58,12 +65,12 @@ function process(doclet) {
} }
// set up the list of "tags" (properties) to process // set up the list of "tags" (properties) to process
if (conf && conf.tags) { if (config.tags) {
tags = conf.tags.slice(); tags = config.tags.slice();
} }
// set up the list of default tags to exclude from processing // set up the list of default tags to exclude from processing
if (conf && conf.excludeTags) { if (config.excludeTags) {
excludeTags = conf.excludeTags.slice(); excludeTags = config.excludeTags.slice();
} }
defaultTags.forEach(function(tag) { defaultTags.forEach(function(tag) {
if (excludeTags.indexOf(tag) === -1 && tags.indexOf(tag) === -1) { if (excludeTags.indexOf(tag) === -1 && tags.indexOf(tag) === -1) {

24
plugins/test/fixtures/markdown.js vendored Normal file
View File

@ -0,0 +1,24 @@
'use strict';
/**
* @see [Nowhere](http://nowhere.com)
*/
function foo() {}
/**
* @see AnObject#myProperty
*/
function bar() {}
/**
* @classdesc My class.
* @description My class.
* @exception {Error} Some error.
* @param {string} myParam - My parameter.
* @property {string} value - Value of myParam.
* @return {MyClass} Class instance.
* @see [Example Inc.](http://example.com)
*/
function MyClass(myParam) {
this.value = myParam;
}

View File

@ -1,11 +0,0 @@
/**
* @see [Nowhere](http://nowhere.com)
*/
function foo() {
}
/**
* @see AnObject#myProperty
*/
function bar() {
}

View File

@ -1,17 +1,35 @@
/*global describe: true, env: true, expect: true, it: true, jasmine: true */ 'use strict';
var path = require('jsdoc/path'); var path = require('jsdoc/path');
describe("markdown plugin", function() { describe('markdown plugin', function() {
//TODO
});
describe("markdown see tag support", function() {
var pluginPath = 'plugins/markdown'; var pluginPath = 'plugins/markdown';
var pluginPathResolved = path.join(env.dirname, pluginPath); var pluginPathResolved = path.join(global.env.dirname, pluginPath);
var plugin = require(pluginPathResolved); var plugin = require(pluginPathResolved);
var docSet = jasmine.getDocSetFromFile('plugins/test/fixtures/seetag-markdown.js'); var docSet = jasmine.getDocSetFromFile('plugins/test/fixtures/markdown.js');
// TODO: more tests; refactor the plugin so multiple settings can be tested
it('should process the correct tags by default', function() {
var myClass = docSet.getByLongname('MyClass')[0];
plugin.handlers.newDoclet({ doclet: myClass });
[
myClass.classdesc,
myClass.description,
myClass.exceptions[0].description,
myClass.params[0].description,
myClass.properties[0].description,
myClass.returns[0].description,
myClass.see
].forEach(function(value) {
// if we processed the value, it should be wrapped in a <p> tag
expect( /^<p>(?:.+)<\/p>$/.test(value) ).toBe(true);
});
});
describe('@see tag support', function() {
var foo = docSet.getByLongname('foo')[0]; var foo = docSet.getByLongname('foo')[0];
var bar = docSet.getByLongname('bar')[0]; var bar = docSet.getByLongname('bar')[0];
@ -27,3 +45,4 @@ describe("markdown see tag support", function() {
expect(bar.see[0]).toEqual('AnObject#myProperty'); expect(bar.see[0]).toEqual('AnObject#myProperty');
}); });
}); });
});