mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Merge pull request #419 from ErnstHaagsman/default-tag-objects
@default tag: added support for object literal defaults
This commit is contained in:
commit
1fb2fe0d90
@ -251,6 +251,10 @@ exports.defineTags = function(dictionary) {
|
||||
// TODO: handle escaped quotes in values
|
||||
doclet.defaultvalue = 'null';
|
||||
}
|
||||
else if (doclet.meta.code.type === 'OBJECTLIT') {
|
||||
doclet.defaultvalue = String(doclet.meta.code.node.toSource());
|
||||
doclet.defaultvaluetype = 'object';
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -195,12 +195,14 @@ h6
|
||||
font-family: Consolas, "Lucida Console", Monaco, monospace;
|
||||
}
|
||||
|
||||
.details { margin-top: 14px; }
|
||||
.details dt { width:100px; float:left; border-left: 2px solid #DDD; padding-left: 10px; padding-top: 6px; }
|
||||
.details { margin-top: 14px; border-left: 2px solid #DDD; }
|
||||
.details dt { width:100px; float:left; padding-left: 10px; padding-top: 6px; }
|
||||
.details dd { margin-left: 50px; }
|
||||
.details ul { margin: 0; }
|
||||
.details ul { list-style-type: none; }
|
||||
.details li { margin-left: 30px; padding-top: 6px; }
|
||||
.details pre.prettyprint { margin: 0 }
|
||||
.details .object-value { padding-top: 0; }
|
||||
|
||||
.description {
|
||||
margin-bottom: 1em;
|
||||
|
||||
@ -1,6 +1,13 @@
|
||||
<?js
|
||||
var data = obj;
|
||||
var self = this;
|
||||
var defaultObjectClass = '';
|
||||
|
||||
// Check if the default value is an object, if so, apply code highlighting
|
||||
if (data.defaultvalue && data.defaultvaluetype === 'object') {
|
||||
data.defaultvalue = "<pre class=\"prettyprint\"><code>" + data.defaultvalue + "</code></pre>";
|
||||
defaultObjectClass = ' class="object-value"';
|
||||
}
|
||||
?>
|
||||
<dl class="details">
|
||||
<?js
|
||||
@ -59,7 +66,9 @@ var self = this;
|
||||
|
||||
<?js if (data.defaultvalue) {?>
|
||||
<dt class="tag-default">Default Value:</dt>
|
||||
<dd class="tag-default"><ul class="dummy"><li><?js= data.defaultvalue ?></li></ul></dd>
|
||||
<dd class="tag-default"><ul class="dummy">
|
||||
<li<?js= defaultObjectClass ?>><?js= data.defaultvalue ?></li>
|
||||
</ul></dd>
|
||||
<?js } ?>
|
||||
|
||||
<?js if (data.meta) {?>
|
||||
|
||||
13
test/fixtures/defaulttag.js
vendored
13
test/fixtures/defaulttag.js
vendored
@ -32,3 +32,16 @@ var win = getParentWindow();
|
||||
@default
|
||||
*/
|
||||
var header = getHeaders(request);
|
||||
|
||||
/**
|
||||
@default
|
||||
*/
|
||||
var obj = { value_a : 'a', value_b : 'b' };
|
||||
|
||||
/**
|
||||
* @default
|
||||
*/
|
||||
var multilineObject = {
|
||||
value_a : 'a',
|
||||
value_b : 'b'
|
||||
};
|
||||
|
||||
@ -5,8 +5,10 @@ describe("@default tag", function() {
|
||||
rcode = (docSet.getByLongname('rcode') || [])[0],
|
||||
rvalid = (docSet.getByLongname('rvalid') || [])[0],
|
||||
rerrored = (docSet.getByLongname('rerrored') || [])[0],
|
||||
win = (docSet.getByLongname('win') || [])[0];
|
||||
header = (docSet.getByLongname('header') || [])[0];
|
||||
win = (docSet.getByLongname('win') || [])[0],
|
||||
header = (docSet.getByLongname('header') || [])[0],
|
||||
obj = docSet.getByLongname('obj')[0],
|
||||
multilineObject = docSet.getByLongname('multilineObject')[0];
|
||||
|
||||
it('When symbol set to null has a @default tag with no text, the doclet\'s defaultValue property should be: null', function() {
|
||||
expect(request.defaultvalue).toBe('null');
|
||||
@ -36,4 +38,14 @@ describe("@default tag", function() {
|
||||
expect(header.defaultvalue).toBeUndefined();
|
||||
});
|
||||
|
||||
it('When symbol has a @default tag with an object, the doclet\'s defaultValue property should contain the stringified object', function() {
|
||||
var expected_value = "{value_a: 'a', value_b: 'b'}";
|
||||
expect(obj.defaultvalue).toEqual(expected_value);
|
||||
});
|
||||
|
||||
it('When symbol has a @default tag with a multiline object, the doclet\'s defaultValue property should contain the properly stringified object', function() {
|
||||
var expected_value = "{value_a: 'a', value_b: 'b'}";
|
||||
expect(obj.defaultvalue).toEqual(expected_value);
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user