Can you explain how a more complex example would be documented in this way? For example...
myNamespace.Myobject = {
/**
* ?
*/
defaults: {
a: {
aa: {
aaa: true
},
aa2: function(options){
returns {
aaa2: false
};
}
},
b: "Hit the light",
c: true
}
};
> 2 + 3. Literal object as function argument and as value returned by
> function:
>
> myNamespace.Myobject = {
> /**
> * @param {Object} options
> * @attribute {String} msg Message
> * @attribute {Boolean} [auto=true] True to auto send message,
> false otherwise
> * @returns {Object} Message status
> * @attribute {Boolean} success
> * @attribute {String} status Status description
> */
> foo: function (options) {...}
> };
>
>
>
> Support for @default tag would be welcome as well on each level.
> Tag name "@attribute" is only an example.
>
Can you show how the @default tag would be used in this specific example?
$ jsdoc scripts/properties.js -X
-- file: scripts/properties.js --
/** @namespace */
myobject = {
/** @attr */
defaults: {
/** @attr */
a: {
/** @attr */
aa: {
/** @attr */
aaa: true
},
/** @attr */
aa2: function(options){
return {
aaa2: false
};
}
},
/** @attr */
b: "Hit the light",
/** @attr */
c: true
}
};
----
You'll find that JSDoc does a decent job of understanding that code. It describes the defaults.a.aa2 symbol you mentioned like so:
{
"comment": "/** @attr */",
"meta": {
"lineno": 6,
"filename": "scripts/properties.js",
"code": {
"id": "astnode522583802",
"name": "aa2",
"type": "FUNCTION",
"node": <Object>,
"value": "FUNCTION"
}
},
"tags": [
{
"originalTitle": "attr",
"title": "attr",
"text": ""
}
],
"kind": "function",
"name": "aa2",
"memberof": "myobject.defaults.a",
"scope": "static",
"longname": "myobject.defaults.a.aa2"
}
Looks like it got the namepath right "myobject.defaults.a.aa2", the fact that it is a function, and the fact that it is a static member of "myobject.defaults.a". So we have this much functionality available to us today.
Consider that the model representing your source code.
The question, for me, is the view. How do you display documentation for that whole tree of symbols? Should myobject.defaults.a have it's own page with a list of all it's properties? What about the properties of those properties? Do they each get their own pages too? or should everything go on a single page? (At some point I suppose it becomes more succinct to just look at the source code directly.)
One could imagine what amounts to a JSON-viewer like [this](http://olivierlabs.com/jason/screenshots.html) where you can keep opening deeper and deeper branches of that JSON tree. Some nicely polished version of that might make a very popular template, I don't know. It's a slippery slope though. You've said it's reasonable to stop at one level deep. But I'd bet you would hear someone else say a better limit is "one more," whatever level we pick.
[Google use an @enum tag](http://code.google.com/closure/compiler/docs/js-for-compiler.html) that is sorta-kinda like this, though the properties are documented as a group of related constants. [JSDoc Toolkit has a @property tag](http://code.google.com/p/jsdoc-toolkit/wiki/TagProperty) that is similar too.
By the way, you can already [document nested properties of params](http://code.google.com/p/jsdoc-toolkit/wiki/TagParam#Parameters_With_Properties) in JSDoc Toolkit. I'm not opposed to adding a similar feature for returned values, but it would have to be compatible and symmetrical with @params. And the trouble with that is that returned values don't have names, so it will require some fudging to make it look like the same pattern that @param uses. For example:
/**
* @param {Object} options The options object.
* @param {Region} options.searchArea The area to search in.
* @param {string} options.targetDescription The name of the target to search for.
*
* @return {Object} The coordinates of the current target.
* @return {number} return.x The x value.
* @return {number} return.y The y value.
*/
function find(options) {
return { x: 0, y: 0};
}
I wonder what the other users on this list think.
Michael Mathews
mic...@gmail.com
> --
> You received this message because you are subscribed to the Google Groups "JSDoc Users" group.
> To post to this group, send email to jsdoc...@googlegroups.com.
> To unsubscribe from this group, send email to jsdoc-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jsdoc-users?hl=en.
>
But, that can't be gleaned from the code. I think the tag has to tell
the template how to render it by classifying the types and assigning a
tag for each, or to repurpose @kind or another similar tag.
For instance, if we consider the first type, where it is all consumed
and modified at once a "container" and the other type, which is handled
piecemeal, a "hash", then you could document it as follows:
/** @container taskContainer */
myobject = {
/** @hash defaults (would document as taskContainer.defaults */
defaults: {
/** @hash a */
a: {
/** @hash aa */
aa: {
/** when true, your hair will fall out */
aaa: true
},
/** returns an object (would you document the return here? or on the return line?) */
aa2: function(options){
return {
aaa2: false
};
}
},
/** blah (no need to decorate further, rhino will tell us this is child of taskContainer)
*/
b: "Hit the light",
/** blah
*/
c: true
}
};
Of course, the terms "hash" and "container" were just used to
illustrate the concept. Hash is definitely not the right term, but
container might work long term.
When presenting the template, just follow the logic, each container will
contain all contents that are not hashes, classes, namespaces, etc on
one page. Each hash will gets its own page and link from the documented
member's attribute, giving it a type of the named @hash and a link to
the docs for the hash. It leaves the programmer in control of how to
navigate the symbols and that may make the ultimate solution to this
problem simpler.
It does, however, pollute the tag namespace. And I don't think it solves
for documenting returned containers easily.
I've added a ticket for this, you may follow or comment on it here:
https://github.com/micmath/jsdoc/issues/34
In regards to the other points: @param already allows for nested properties to be documented. Supporting nested properties of @returns would require some new proposal and I've already made one in this thread; if it is agreeable please comment and create a ticket for that as well.
Michael Mathews
mic...@gmail.com