Fix some JSDoc issues

Also makes a few minor changes to the template, so it can be used until
we have a new doc generation process. JSDoc output is written to
build/apidoc.
This commit is contained in:
ahocevar
2018-05-10 17:14:17 +02:00
parent 1e0086460b
commit e810387956
17 changed files with 66 additions and 61 deletions

View File

@@ -1,6 +1,7 @@
{ {
"opts": { "opts": {
"recurse": true "recurse": true,
"template": "config/jsdoc/api/template"
}, },
"tags": { "tags": {
"allowUnknownTags": true "allowUnknownTags": true

View File

@@ -1,43 +1,43 @@
<table><tr> <table><tr>
<th width="33.3%">Map</th><th width="33.3%">View</th><th width="33.3%">Layers</th> <th width="33.3%">Map</th><th width="33.3%">View</th><th width="33.3%">Layers</th>
</tr><tr> </tr><tr>
<td><p>A [map](ol.Map.html) is made of [layers](ol.layer.html), a [view](ol.View.html) to visualize them, [interactions](ol.interaction.html) to modify map content and [controls](ol.control.html) with UI components.</p> <td><p>A [map](module-ol_Map-Map.html) is made of [layers](module-ol_layer_Base-BaseLayer.html), a [view](module-ol_View-View.html) to visualize them, [interactions](module-ol_interaction_Interaction-Interaction.html) to modify map content and [controls](module-ol_control_Control-Control.html) with UI components.</p>
[Overview](ol.Map.html)<br> [Overview](module-ol_Map-Map.html)<br>
[Creation](ol.Map.html#Map)<br> [Creation](module-ol_Map-Map.html#Map)<br>
[Events](ol.MapBrowserEvent.html)</td> [Events](module-ol_MapBrowserEvent-MapBrowserEvent.html)</td>
<td><p>The view manages the visual parameters of the map view, like resolution or rotation.</p> <td><p>The view manages the visual parameters of the map view, like resolution or rotation.</p>
[ol.View](ol.View.html) with center, projection, resolution and rotation</td> [View](module-ol_View-View.html) with center, projection, resolution and rotation</td>
<td><p>Layers are lightweight containers that get their data from [sources](ol.source.html).</p> <td><p>Layers are lightweight containers that get their data from [sources](module-ol_source_Source-Source.html).</p>
[ol.layer.Tile](ol.layer.Tile.html)<br> [layer/Tile](module-ol_layer_Tile-TileLayer.html)<br>
[ol.layer.Image](ol.layer.Image.html)<br> [layer/Image](module-ol_layer_Image-ImageLayer.html)<br>
[ol.layer.Vector](ol.layer.Vector.html)<br> [layer/Vector](module-ol_layer_Vector-VectorLayer.html)<br>
[ol.layer.VectorTile](ol.layer.VectorTile.html)</td> [layer/VectorTile](module-ol_layer_VectorTile-VectorTileLayer.html)</td>
</tr><tr> </tr><tr>
<th>Controls</th><th>Interactions</th><th>Sources and formats</th> <th>Controls</th><th>Interactions</th><th>Sources and formats</th>
</tr><tr> </tr><tr>
<td>[Map default controls](ol.control.html#.defaults)<br> <td>[Map default controls](module-ol_control_util.html#.defaults)<br>
[All controls](ol.control.html) [All controls](module-ol_control_Control-Control.html)
</td> </td>
<td> <td>
[Map default interactions](ol.interaction.html#.defaults)<br> [Map default interactions](module-ol_interaction.html#~defaults)<br>
Interactions for [vector features](ol.Feature.html) Interactions for [vector features](module-ol_Feature-Feature.html)
<ul><li>[ol.interaction.Select](ol.interaction.Select.html)</li> <ul><li>[interaction/Select](module-ol_interaction_Select-Select.html)</li>
<li>[ol.interaction.Draw](ol.interaction.Draw.html)</li> <li>[interaction/Draw](module-ol_interaction_Draw-Draw.html)</li>
<li>[ol.interaction.Modify](ol.interaction.Modify.html)</li></ul> <li>[interaction/Modify](module-ol_interaction_Modify-Modify.html)</li></ul>
[All interactions](ol.interaction.html)</td> [All interactions](module-ol_interaction_Interaction-Interaction.html)</td>
<td>[Tile sources](ol.source.Tile.html) for [ol.layer.Tile](ol.layer.Tile.html) <td>[Tile sources](module-ol_source_Tile-TileSource.html) for [layer/Tile](module-ol_layer_Tile-TileLayer.html)
<br>[Image sources](ol.source.Image.html) for [ol.layer.Image](ol.layer.Image.html) <br>[Image sources](module-ol_source_Image-ImageSource.html) for [layer/Image](module-ol_layer_Image-ImageLayer.html)
<br>[Vector sources](ol.source.Vector.html) for [ol.layer.Vector](ol.layer.Vector.html) <br>[Vector sources](module-ol_source_Vector-VectorSource.html) for [layer/Vector](module-ol_layer_Vector-VectorLayer.html)
<br>[Vector tile sources](ol.source.VectorTile.html) for [ol.layer.VectorTile](ol.layer.VectorTile.html) <br>[Vector tile sources](module-ol_source_VectorTile-VectorTile.html) for [layer/VectorTile](module-ol_layer_VectorTile-VectorTileLayer.html)
<br>[Formats](ol.format.Feature.html) for reading/writing vector data <br>[Formats](module-ol_format_Feature-FeatureFormat.html) for reading/writing vector data
<br>[ol.format.WMSCapabilities](ol.format.WMSCapabilities.html)</td></tr> <br>[format/WMSCapabilities](module-ol_format_WMSCapabilities-WMSCapabilities.html)</td></tr>
<tr><th>Projections</th><th>Observable objects</th><th>Other components</th></tr> <tr><th>Projections</th><th>Observable objects</th><th>Other components</th></tr>
<tr><td><p>All coordinates and extents need to be provided in view projection (default: EPSG:3857). To transform, use [ol.proj.transform()](ol.proj.html#.transform) and [ol.proj.transformExtent()](ol.proj.html#.transformExtent).</p> <tr><td><p>All coordinates and extents need to be provided in view projection (default: EPSG:3857). To transform, use [proj.transform()](module-ol_proj.html#.transform) and [proj.transformExtent()](module-ol_proj.html#.transformExtent).</p>
[ol.proj](ol.proj.html)</td> [ol/proj](module-ol_proj.html)</td>
<td><p>Changes to all [ol.Objects](ol.Object.html) can be observed by calling the [object.on('propertychange')](ol.Object.html#on) method. Listeners receive an [ol.Object.Event](ol.Object.Event.html) with information on the changed property and old value.</p> <td><p>Changes to all [ol/Object](module-ol_Object-BaseObject.html)s can be observed by calling the [object.on('propertychange')](module-ol_Object-BaseObject.html#on) method. Listeners receive an [ol/Object~ObjectEvent](module-ol_Object-ObjectEvent.html) with information on the changed property and old value.</p>
<td> <td>
[ol.Geolocation](ol.Geolocation.html)<br> [ol/Geolocation](module-ol_Geolocation.html)<br>
[ol.Overlay](ol.Overlay.html)<br></td> [ol/Overlay](module-ol_Overlay-Overlay.html)<br></td>
</tr></table> </tr></table>
&nbsp; &nbsp;
@@ -52,11 +52,4 @@ The OpenLayers API consists of
Within a major release series, the API will not be changed. Any changes to the API will be accompanied by a new major release. Within a major release series, the API will not be changed. Any changes to the API will be accompanied by a new major release.
*Note*: The API change policy does not cover CSS class names that are used to style the *Note*: The API change policy does not cover CSS class names that are used to style the OpenLayers UI. It also does not cover any typedefs and enums.
OpenLayers UI.
*Note for Closure Compiler users compiling their application code together with OpenLayers*:
The names of types other than those in the list above (e.g. `ol.Coordinate`) are subject to change. It
is therefore recommended to either use the resolved type as listed in the API docs (e.g.
`Array.<number>` instead of `ol.Coordinate`), or pay attention to the upgrade notes, which will list
the changes for those types.

View File

@@ -76,15 +76,12 @@ function extractTypes(item) {
} }
function includeTypes(doclet) { function includeTypes(doclet) {
if (doclet.params && doclet.kind != 'class') { if (doclet.params) {
doclet.params.forEach(extractTypes); doclet.params.forEach(extractTypes);
} }
if (doclet.returns) { if (doclet.returns) {
doclet.returns.forEach(extractTypes); doclet.returns.forEach(extractTypes);
} }
if (doclet.isEnum) {
types[doclet.meta.code.name] = true;
}
if (doclet.type && doclet.meta.code.type == 'MemberExpression') { if (doclet.type && doclet.meta.code.type == 'MemberExpression') {
extractTypes(doclet); extractTypes(doclet);
} }
@@ -131,6 +128,10 @@ exports.handlers = {
continue; continue;
} }
if (doclet.kind == 'module' && doclet.longname in modules) { if (doclet.kind == 'module' && doclet.longname in modules) {
// Document all modules that are referenced by the API
continue;
}
if (doclet.isEnum) {
continue; continue;
} }
if (doclet.kind == 'class' && api.some(hasApiMembers, doclet)) { if (doclet.kind == 'class' && api.some(hasApiMembers, doclet)) {

View File

@@ -22,7 +22,7 @@ function addDefaultExportPath(obj) {
const lines = file.split('\n'); const lines = file.split('\n');
let hasDefaultExport = false; let hasDefaultExport = false;
for (let i = 0, ii = lines.length; i < ii; ++i) { for (let i = 0, ii = lines.length; i < ii; ++i) {
hasDefaultExport = hasDefaultExport || lines[i].indexOf('export default ') == 0; hasDefaultExport = hasDefaultExport || /^export default [^\{]/.test(lines[i]);
const match = lines[i].match(/^export default ([A-Za-z_$][A-Za-z0-9_$]+);$/); const match = lines[i].match(/^export default ([A-Za-z_$][A-Za-z0-9_$]+);$/);
if (match) { if (match) {
// Use variable name if default export is assigned to a variable. // Use variable name if default export is assigned to a variable.

View File

@@ -47,7 +47,7 @@ exports.handlers = {
if (!cls.fires) { if (!cls.fires) {
cls.fires = []; cls.fires = [];
} }
event = 'ol.Object.Event#event:change:' + name; event = 'module:ol/Object~ObjectEvent#event:change:' + name;
if (cls.fires.indexOf(event) == -1) { if (cls.fires.indexOf(event) == -1) {
cls.fires.push(event); cls.fires.push(event);
} }

View File

@@ -1,4 +1,13 @@
/*global env: true */ /*global env: true */
const hasOwnProp = Object.prototype.hasOwnProperty;
// Work around an issue with hasOwnProperty in JSDoc's templateHelper.js.
//TODO Fix in JSDoc.
Object.prototype.hasOwnProperty = function(property) {
return property in this;
};
const template = require('jsdoc/lib/jsdoc/template'); const template = require('jsdoc/lib/jsdoc/template');
const fs = require('jsdoc/lib/jsdoc/fs'); const fs = require('jsdoc/lib/jsdoc/fs');
const path = require('jsdoc/lib/jsdoc/path'); const path = require('jsdoc/lib/jsdoc/path');
@@ -9,9 +18,12 @@ const _ = require('underscore');
const htmlsafe = helper.htmlsafe; const htmlsafe = helper.htmlsafe;
const linkto = helper.linkto; const linkto = helper.linkto;
const resolveAuthorLinks = helper.resolveAuthorLinks; const resolveAuthorLinks = helper.resolveAuthorLinks;
const hasOwnProp = Object.prototype.hasOwnProperty;
const outdir = env.opts.destination; const outdir = env.opts.destination;
// Work around an issue with hasOwnProperty in JSDoc's templateHelper.js.
//TODO Fix in JSDoc.
Object.prototype.hasOwnProperty = hasOwnProp;
let view; let view;
let data; let data;
@@ -192,7 +204,7 @@ function attachModuleSymbols(doclets, modules) {
function buildNav(members) { function buildNav(members) {
const nav = []; const nav = [];
// merge namespaces and classes, then sort // merge namespaces and classes, then sort
const merged = members.namespaces.concat(members.classes); const merged = members.modules.concat(members.classes);
merged.sort(function(a, b) { merged.sort(function(a, b) {
if (a.longname > b.longname) { if (a.longname > b.longname) {
return 1; return 1;
@@ -205,9 +217,9 @@ function buildNav(members) {
_.each(merged, function(v) { _.each(merged, function(v) {
// exclude interfaces from sidebar // exclude interfaces from sidebar
if (v.interface !== true) { if (v.interface !== true) {
if (v.kind == 'namespace') { if (v.kind == 'module') {
nav.push({ nav.push({
type: 'namespace', type: 'module',
longname: v.longname, longname: v.longname,
name: v.name, name: v.name,
members: find({ members: find({

View File

@@ -20,12 +20,10 @@
<br> <br>
<?js if (doc.stability || doc.kind == 'namespace') { <?js if (doc.stability || doc.kind == 'namespace') {
var ancestors = doc.ancestors.map(a => a.replace(/>\./g, '>').replace(/\.</g, '<')).join('/'); var ancestors = doc.ancestors.map(a => a.replace(/>\./g, '>').replace(/\.</g, '<')).join('/');
var name = doc.name.toLowerCase();
var parts = []; var parts = [];
if (ancestors) { if (ancestors) {
parts.push(ancestors); parts.push(ancestors.split('~').shift());
} }
parts.push(name);
var importPath = parts.join('/'); var importPath = parts.join('/');
?> ?>
<pre class="prettyprint source"><code>import <?js= doc.name ?> from '<?js= importPath ?>';</code></pre> <pre class="prettyprint source"><code>import <?js= doc.name ?> from '<?js= importPath ?>';</code></pre>

View File

@@ -11,7 +11,7 @@ var self = this;
?> ?>
<li class="item" data-name="<?js= item.longname ?>"> <li class="item" data-name="<?js= item.longname ?>">
<span class="title"> <span class="title">
<?js= self.linkto(item.longname, item.longname) ?> <?js= self.linkto(item.longname, item.longname.replace('module:', '')) ?>
<?js if (item.type === 'namespace' && <?js if (item.type === 'namespace' &&
(item.members.length + item.typedefs.length + item.methods.length + (item.members.length + item.typedefs.length + item.methods.length +
item.events.length > 0)) { ?> item.events.length > 0)) { ?>

View File

@@ -8,7 +8,7 @@
<th>Name</th> <th>Name</th>
<th>Type</th> <th>Type</th>
<th>Settable</th> <th>Settable</th>
<th><a href="ol.Object.Event.html">ol.Object.Event</a> type</th> <th><a href="module-ol_Object-ObjectEvent.html">ol/Object~ObjectEvent</a> type</th>
<th class="last">Description</th> <th class="last">Description</th>
</tr> </tr>
</thead> </thead>

View File

@@ -23,7 +23,7 @@
"src-closure": "babel -q --out-dir build/src-closure src/", "src-closure": "babel -q --out-dir build/src-closure src/",
"pretypecheck": "npm run src-closure", "pretypecheck": "npm run src-closure",
"typecheck": "node tasks/typecheck", "typecheck": "node tasks/typecheck",
"apidoc": "jsdoc -c config/jsdoc/api/conf.json -d build/apidoc" "apidoc": "jsdoc config/jsdoc/api/index.md -c config/jsdoc/api/conf.json -d build/apidoc"
}, },
"main": "src/ol/index.js", "main": "src/ol/index.js",
"repository": { "repository": {

View File

@@ -8,7 +8,7 @@
export default { export default {
/** /**
* Triggered when a property is changed. * Triggered when a property is changed.
* @event module:ol/Object~Event#propertychange * @event module:ol/Object~ObjectEvent#propertychange
* @api * @api
*/ */
PROPERTYCHANGE: 'propertychange' PROPERTYCHANGE: 'propertychange'

View File

@@ -28,7 +28,7 @@ import {assign} from '../obj.js';
* Abstract base class; normally only used for creating subclasses and not * Abstract base class; normally only used for creating subclasses and not
* instantiated in apps. * instantiated in apps.
* Note that with {@link module:ol/layer/Base} and all its subclasses, any property set in * Note that with {@link module:ol/layer/Base} and all its subclasses, any property set in
* the options is set as a {@link module:ol/Object property on the layer object, so * the options is set as a {@link module:ol/Object} property on the layer object, so
* is observable, and has get/set accessors. * is observable, and has get/set accessors.
* *
* @constructor * @constructor

View File

@@ -58,7 +58,7 @@ const DEFAULT_GRADIENT = ['#00f', '#0ff', '#0f0', '#ff0', '#f00'];
/** /**
* @classdesc * @classdesc
* Layer for rendering vector data as a heatmap. * Layer for rendering vector data as a heatmap.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject * Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the * property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors. * options means that `title` is observable, and has get/set accessors.
* *

View File

@@ -30,7 +30,7 @@ import Layer from '../layer/Layer.js';
* @classdesc * @classdesc
* Server-rendered images that are available for arbitrary extents and * Server-rendered images that are available for arbitrary extents and
* resolutions. * resolutions.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject * Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the * property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors. * options means that `title` is observable, and has get/set accessors.
* *

View File

@@ -35,7 +35,7 @@ import {assign} from '../obj.js';
* @classdesc * @classdesc
* For layer sources that provide pre-rendered, tiled images in grids that are * For layer sources that provide pre-rendered, tiled images in grids that are
* organized by zoom levels for specific resolutions. * organized by zoom levels for specific resolutions.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject * Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the * property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors. * options means that `title` is observable, and has get/set accessors.
* *

View File

@@ -80,7 +80,7 @@ const Property = {
/** /**
* @classdesc * @classdesc
* Vector data that is rendered client-side. * Vector data that is rendered client-side.
* Note that any property set in the options is set as a {@link } * Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the * property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors. * options means that `title` is observable, and has get/set accessors.
* *

View File

@@ -91,7 +91,7 @@ export const RenderType = {
/** /**
* @classdesc * @classdesc
* Layer for vector tile data that is rendered client-side. * Layer for vector tile data that is rendered client-side.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject * Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the * property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors. * options means that `title` is observable, and has get/set accessors.
* *