@default tag with object literals

Changed boolean 'doclet.defaultobject' to 'doclet.defaultvaluetype' field. Improved unit testing and fixed template.
This commit is contained in:
Ernst Haagsman 2013-05-15 10:54:55 +02:00
parent 9af5ea424e
commit 70109a2956
5 changed files with 24 additions and 9 deletions

View File

@ -251,9 +251,9 @@ exports.defineTags = function(dictionary) {
// TODO: handle escaped quotes in values
doclet.defaultvalue = 'null';
}
else if (doclet.meta.code.type === 'OBJECTLIT'){
else if (doclet.meta.code.type === 'OBJECTLIT') {
doclet.defaultvalue = String(doclet.meta.code.node.toSource());
doclet.defaultobject = true;
doclet.defaultvaluetype = 'object';
}
}
}

View File

@ -202,6 +202,7 @@ h6
.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;

View File

@ -1,12 +1,12 @@
<?js
var data = obj;
var self = this;
var default_object_css = '';
var defaultObjectClass = '';
// Check if the default value is an object, if so, apply code highlighting
if (data.defaultvalue && data.defaultobject){
if (data.defaultvalue && data.defaultvaluetype === 'object') {
data.defaultvalue = "<pre class=\"prettyprint\"><code>" + data.defaultvalue + "</code></pre>";
default_object_css = ' style="padding-top: 0;" ';
defaultObjectClass = ' class="object-value"';
}
?>
<dl class="details">
@ -67,7 +67,7 @@ if (data.defaultvalue && data.defaultobject){
<?js if (data.defaultvalue) {?>
<dt class="tag-default">Default Value:</dt>
<dd class="tag-default"><ul class="dummy">
<li<?js= default_object_css ?>><?js= data.defaultvalue ?></li>
<li<?js= defaultObjectClass ?>><?js= data.defaultvalue ?></li>
</ul></dd>
<?js } ?>

View File

@ -37,3 +37,11 @@ var header = getHeaders(request);
@default
*/
var obj = { value_a : 'a', value_b : 'b' };
/**
* @default
*/
var multilineObject = {
value_a : 'a',
value_b : 'b'
};

View File

@ -7,7 +7,8 @@ describe("@default tag", function() {
rerrored = (docSet.getByLongname('rerrored') || [])[0],
win = (docSet.getByLongname('win') || [])[0],
header = (docSet.getByLongname('header') || [])[0],
obj = docSet.getByLongname('obj')[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');
@ -37,9 +38,14 @@ describe("@default tag", function() {
expect(header.defaultvalue).toBeUndefined();
});
it('When symbol has a @default tag with an object.', function(){
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);
});
});