@default tag: added support for object literal defaults

Default object literals are now stored as a string. In the default
template they are shown with syntax highlighting.
This commit is contained in:
Ernst Haagsman 2013-05-08 21:30:25 +02:00
parent 780637450c
commit 9af5ea424e
5 changed files with 32 additions and 7 deletions

View File

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

View File

@ -195,12 +195,13 @@ h6
font-family: Consolas, "Lucida Console", Monaco, monospace; font-family: Consolas, "Lucida Console", Monaco, monospace;
} }
.details { margin-top: 14px; } .details { margin-top: 14px; border-left: 2px solid #DDD; }
.details dt { width:100px; float:left; border-left: 2px solid #DDD; padding-left: 10px; padding-top: 6px; } .details dt { width:100px; float:left; padding-left: 10px; padding-top: 6px; }
.details dd { margin-left: 50px; } .details dd { margin-left: 50px; }
.details ul { margin: 0; } .details ul { margin: 0; }
.details ul { list-style-type: none; } .details ul { list-style-type: none; }
.details li { margin-left: 30px; padding-top: 6px; } .details li { margin-left: 30px; padding-top: 6px; }
.details pre.prettyprint { margin: 0 }
.description { .description {
margin-bottom: 1em; margin-bottom: 1em;

View File

@ -1,6 +1,13 @@
<?js <?js
var data = obj; var data = obj;
var self = this; var self = this;
var default_object_css = '';
// Check if the default value is an object, if so, apply code highlighting
if (data.defaultvalue && data.defaultobject){
data.defaultvalue = "<pre class=\"prettyprint\"><code>" + data.defaultvalue + "</code></pre>";
default_object_css = ' style="padding-top: 0;" ';
}
?> ?>
<dl class="details"> <dl class="details">
<?js <?js
@ -59,7 +66,9 @@ var self = this;
<?js if (data.defaultvalue) {?> <?js if (data.defaultvalue) {?>
<dt class="tag-default">Default Value:</dt> <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= default_object_css ?>><?js= data.defaultvalue ?></li>
</ul></dd>
<?js } ?> <?js } ?>
<?js if (data.meta) {?> <?js if (data.meta) {?>

View File

@ -31,4 +31,9 @@ var win = getParentWindow();
/** /**
@default @default
*/ */
var header = getHeaders(request); var header = getHeaders(request);
/**
@default
*/
var obj = { value_a : 'a', value_b : 'b' };

View File

@ -5,8 +5,9 @@ describe("@default tag", function() {
rcode = (docSet.getByLongname('rcode') || [])[0], rcode = (docSet.getByLongname('rcode') || [])[0],
rvalid = (docSet.getByLongname('rvalid') || [])[0], rvalid = (docSet.getByLongname('rvalid') || [])[0],
rerrored = (docSet.getByLongname('rerrored') || [])[0], rerrored = (docSet.getByLongname('rerrored') || [])[0],
win = (docSet.getByLongname('win') || [])[0]; win = (docSet.getByLongname('win') || [])[0],
header = (docSet.getByLongname('header') || [])[0]; header = (docSet.getByLongname('header') || [])[0],
obj = docSet.getByLongname('obj')[0];
it('When symbol set to null has a @default tag with no text, the doclet\'s defaultValue property should be: null', function() { 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'); expect(request.defaultvalue).toBe('null');
@ -36,4 +37,9 @@ describe("@default tag", function() {
expect(header.defaultvalue).toBeUndefined(); expect(header.defaultvalue).toBeUndefined();
}); });
}); it('When symbol has a @default tag with an object.', function(){
var expected_value = "{value_a: 'a', value_b: 'b'}";
expect(obj.defaultvalue).toEqual(expected_value);
})
});