YUIDoc's syntax should be familiar if you've used
Javadoc, JSDoc, Doxygen, or other documentation generator tools.
YUIDoc relies on tags such as @param
or @return
embedded in comment blocks
that start with /**
and end with */
. See comment styles for more information.
It includes a small number of tags for documenting specific YUI features,
but most tags are generic enough to use with any object-oriented language.
IMPORTANT: YUIDoc only parses YUIDoc comment blocks, not source code. This keeps YUIDoc relatively simple and language agnostic. However, it also means you must declare everything to YUIDoc explicitly. A code snippet will not display as a "method" or "class" until you describe it as such. A corollary is that YUIDoc will never generate empty, "stub" doc entries for API members that lack comment blocks.
Basic Requirements
A given comment block must contain one (and only one)
primary tag such as @class
or @method
,
and zero or more secondary tags
such as @param
, @type
, and @extends
.
Some secondary tags can be used in any comment block,
while others only make sense alongside a particular primary tag.
A source tree must contain at least one comment block with a @module
tag.
Each module must have at least one comment block with a @class
tag.
Each class may then have zero or more comment blocks with
an attribute
, @class
, @event
, @method
, or @property
tag.
Primary Tags
Each comment block must have one (and only one) of the following tags:
Name | Example | Description |
---|---|---|
module |
/** * Provides the base Widget class... * * @module widget */ |
Indicates that the block describes a group of related classes.
For example, YUI's YUIDoc requires you to provide at least one module per source tree. Since there isn't always an obvious place to insert module documentation in JavaScript source, the convention is to declare your module at the top of the file that contains your module's "primary" or "base" class.
See also:
|
main |
/** * Provides more features for the widget module... * * @module widget * @submodule widget-foo * @main widget */ |
When YUIDoc parses a module's directory, there may be several files in this directory that
provides documentation for that module and it's submodules. YUIDoc will attempt to determine
which module contains the main description for this module. If it has trouble doing that,
you can add a |
class |
/** * A utility that brokers HTTP requests... * * @class IO * @constructor */ function IO (config) { |
Indicates that the block describes a class.
In JavaScript, this is generally an object with a constructor function.
The value of YUIDoc expects methods, properties, attributes, and events to belong to a class,
so in general you must provide at least one class for each module in your source tree.
A A
See also:
|
element |
/** * This is the foo element description... * * @element x-foo */ |
Indicates that the block describes a Custom Element.
The
See also:
|
method |
/** * Returns this model's attributes as... * * @method toJSON * @return {Object} Copy of ... */ toJSON: function () { |
Indicates that the block describes a method for the current class.
By default, the "current" class is the last class that YUIDoc parsed, but
you can reset this with the A
See also:
|
event |
/** * Fired when an error occurs... * * @event error * @param {String} msg A description of... */ var EVT_ERROR = 'error', |
Indicates that the block describes a custom event that the class can fire
at some interesting moment of code execution.
An Ideally, an |
property |
/** * Template for this view's container... * * @property containerTemplate * @type String * @default "<div/>" */ containerTemplate: '<div/>', |
Indicates that the block describes a property belonging to the current class. As with methods, a
See also:
|
attribute |
/** * Indicates whether this Widget * has been rendered... * * @attribute rendered * @readOnly * @default false * @type boolean */ ATTRS[RENDERED] = { |
[YUI-specific] Indicates that the block describes a managed configuration attribute.
An attribute is an object created and managed by the YUI
An If you specify a
See also: |
Secondary tags
After choosing one of the five primary tags, you can further document a module, class, method, event or property with one or more of the following secondary tags.
Name | Example | Description |
---|---|---|
submodule |
/** * @module app * @submodule view */ |
Specifies that the module is actually a submodule of some parent module.
For example, the In YUI, submodules enable you to make very fine-grained choices about loading code.
For example, the
See also:
|
namespace |
/** * @namespace Test.Mock */ |
Specifies a class's namespace.
The Supplying a
See also:
|
extends |
/** * @class View * @constructor * @extends Base */ |
Specifies that the class inherits members from a parent class,
perhaps using
See also:
|
config |
/** * @config docScrollX * @type Number */ |
[YUI-specific] Alias for |
constructor |
/** * @class IO * @constructor */ |
Indicates that the class is instantiable
(created with the |
static |
/** * YUI user agent detection... * * @class UA * @static */ |
Indicates that the method or class is static:
A
See also:
|
final |
/** * Identifies state changes * originating from... * * @property SRC_REPLACE * @type String * @static * @final */ |
Indicates that the property or attribute is a constant and should not be changed.
See also:
|
readOnly |
/** * The current default button * as configured through... * * @attribute defaultButton * @type Node * @default null * @readOnly */ |
[YUI-specific] Indicates that the attribute is configured with the
Sometimes used with properties, as an alias for
See also:
|
writeOnce |
/** * Diameter of the circular * background object. Other * objects scale accordingly. * Set this only before * rendering. * * @attribute diameter * @type {Number} number of px * in diameter * @default 100 * @writeOnce */ |
[YUI-specific] Indicates that the attribute is configured with the
See also:
|
optional |
/** * An optional attribute, * not required for proper * use. * * @attribute extras * @type {Object} extra data * @optional */ |
[YUI-specific] Indicates that the attribute is not required to be provided for proper use of this class.
See also:
|
required |
/** * A required attribute * that is required for proper * use, module will likely fail * if this is not provided. * * @attribute url * @type {String} url to fetch remote data from * @required */ |
[YUI-specific] Indicates that the attribute is required to be provided for proper use of this class.
See also:
|
*param |
/** * @param {String} name An * Attribute name or * object property path. */ /** * @param {Object} [options] Data * to be mixed into the event * facade of the `change` * event(s) for these attributes. * @param {Boolean} [options.silent] * If `true`, no `change` event * will be fired. */ |
Defines a parameter for an ordinary
The
As shown in the example, you can also nest
See also:
|
return |
/** * @method generateClientId * @return {String} Unique clientId. */ |
Specifies a method's return value.
A |
throws |
/** * @method generateClientId * @throws {Error} An error. */ |
Specifies an error which method throws.
A |
for |
/** * Some inner class 'foo'... * * @class foo * @for OuterClass */ /** * Some method 'bar' * disconnected from * its class 'FarawayClass'... * * @method bar * @for FarawayClass */ |
Sets YUIDoc's class scope. Using To close an inner class, add If you are not inside an inner class,
using |
type |
/** * @type String */ /** * @type HTMLElement|Node|String */ |
Specifies the type of a property or attribute. You can specify a single type, a list of legal types separated by vertical bars, or if you are lazy, "any" or "mixed".
See also:
|
private |
/** * Reference to the internal JSONP * instance used to make the queries. * * @private * @property _jsonp */ |
Indicates a member that should not be used externally.
Although YUIDoc does not generate documentation for
See also:
|
protected |
/** * Removes the `container` from * the DOM and ... * * @method _destroyContainer * @protected */ |
Indicates a member that should not be modified by implementers unless they are creating a subclass. All methods and properties are assumed to be public unless marked as private or protected.
See also:
|
requires |
/** * @module event-simulate * @requires event */ |
[Uncommon] Identifies one or more dependencies in the module declaration. Can be a single module name or a comma-separated list.
See also:
|
default |
/** * @default false */ |
Specifies the default value of a property or attribute.
Should be paired with a
See also:
|
*uses |
/** * @class Panel * @constructor * @extends Widget * @uses WidgetAutohide * @uses WidgetButtons ... */ |
Specifies that the class has some other class's
properties, methods, and other members mixed into its prototype,
perhaps using Note that
See also:
|
*example |
/** * @example * model.set('foo', 'bar'); */ |
Indicates a block of example code
to be automatically parsed and displayed with
YUIDoc's Markdown and code highlighting parser.
Your code sample should be indented beneath the A block may include multiple |
chainable |
/** * Renders this view ... * * @method render * @chainable */ render: function () { return this; }, |
Indicates that a method returns
See also:
|
deprecated |
/** * @property locale * @type String * @deprecated Use `config.lang` * instead. */ |
Indicates that the module, class, or member is deprecated and will be removed in a future release. You can optionally supply a string message describing what to use instead. |
since |
/** * @since 3.4.0 */ |
Indicates that the module, class, or member was added to the source at the specified version.
See also:
|
async |
/** * @async */ |
[Uncommon] Indicates that the method is asynchronous and requires a callback. |
beta |
/** * @beta */ |
Indicates that the method, class, or member is in beta and might undergo backwards-incompatible changes in the near future.
See also:
|
bubbles |
/** * Handles the mouseup DOM event... * * @event drag:mouseup * @bubbles DDM */ |
Specifies the default target that a custom event bubbles to. This is a useful tag if your API has a "manager" class that is responsible for capturing a set of related custom events.
See also:
|
extension extensionfor extension_for |
/** * @class PjaxBase * @extensionfor Router */ |
Indicates that the class is an extension object designed to be optionally mixed into the specified class.
|
parents |
/** * @element x-foo * @parents <body> */ |
It's a secondary tag for the
See also:
|
contents |
/** * @element x-foo * @contents <x-bar> */ |
It's a secondary tag for the
See also:
|
interface |
/** * @element x-foo * @interface XFooElement */ |
It's a secondary tag for the
See also:
|
A * indicates that you can supply multiple tags of that type in the same block.
Parsed but not in the theme yet
The following tags are parsed by the DocParser
but are not in the default theme yet.
author |
Author information about this item | |
broadcast |
Event broadcasts to a large audience than scoped | |
*category |
Category to place this item into. |
Comment Styles
The comment blocks can start with any amount of whitespace, and optionally one or more asterisks. Valid examples include:
/** * Description * @method description */
/** * Description * @method description **/
/** Description @method description */
/** Description @method description **/
Extra formatting
YUIDoc supports 3 main forms of formatting your documentation. HTML, Markdown & Selleck.
HTML |
Doc comments may contain standard HTML markup and YUIDoc will display it as is. |
Markdown |
Full Markdown syntax is also supported. |
Selleck |
Selleck's additional parsing is also supported. |
Markdown and Code Highlighting
Inside any documentation block you may use Markdown or Selleck based markup. If you indent your code snippets, YUIDoc will automatically wrap them in a code block and syntax highlight them for you.
/** * This is the __module__ description for the `YUIDoc` module. * * var options = { * paths: [ './lib' ], * outdir: './out' * }; * * var Y = require('yuidoc'); * var json = (new Y.YUIDoc(options)).run(); * * @class YUIDoc * @main yuidoc */
This would render as:
This is the module description for the YUIDoc
module.
var options = { paths: [ './lib' ], outdir: './out' }; var Y = require('yuidoc'); var json = (new Y.YUIDoc(options)).run();
Cross-referencing Modules and Classes
YUIDoc also includes a Handlebars blockHelper
that enables you to
easily cross-reference classes and modules. It uses this pattern:
#crossLink "Class/item:type" #crossLink "Foo/bar:event" #crossLink "Foo/bar:attribute" #crossLink "Foo/bar:method" --default
So, for example, if you include:
/** * * This module also uses {{#crossLink "Foo"}}{{/crossLink}}, where Foo is a class name. * Also see {{#crossLink "myClass/Foo:method"}}{{/crossLink}}, where myClass is a class name and Foo is a method on that class. * * This module uses {{#crossLinkModule "widget"}}{{/crossLinkModule}}, where widget is a module name * * This module also uses {{#crossLink "Bar"}} an awesome class {{/crossLink}} named Bar. */
This automatically generates an internal link to Foo's API reference page:
<p> This module also uses <a href="../classes/Foo.html" class="crosslink">Foo</a>, where Foo is a class or module name. </p> <p> Also see <a href="../classes/myClass.html#method_Foo">Foo</a>, where myClass is a class name and Foo is a method on that class. </p> <p> This module uses <a href="../modules/widget.html">widget</a>, where widget is a module name </p> <p> This module also uses <a href="../classes/Bar.html" class="crosslink">an awesome class</a> named Bar. </p>
You can also call crossLinkRaw
to return only the HREF portion of the link, so you can link it
yourself.
Using custom Handlebars block helpers
You can tell YUIDoc
to include custom Y.Handlebars
helpers with the -H
or --helpers
command line arguments
(or helpers
Array in the yuidoc.json
file).
Here is an example helper.js
file:
module.exports = { davglass: function(item) { return "Dav Glass says: " + item } };
Now you can use the davglass
helper inside your own docs like this:
/** * This is also a test {{#davglass "Foo"}}{{/davglass}} */This will output this in your documentation:
<p> This is also a test Dav Glass says: Foo </p>