diff --git a/support/jsdoc/theme/publish.js b/support/jsdoc/theme/publish.js index 016e53ea7..080e68d2c 100644 --- a/support/jsdoc/theme/publish.js +++ b/support/jsdoc/theme/publish.js @@ -1,25 +1,25 @@ /*global env: true */ 'use strict'; -var doop = require('jsdoc/util/doop'); -var fs = require('jsdoc/fs'); // jsdoc/fs offer non-standard functions (mkPath) -var fsExtra = require('fs-extra'); -var helper = require('jsdoc/util/templateHelper'); -var logger = require('jsdoc/util/logger'); -var path = require('jsdoc/path'); -var taffy = require('taffydb').taffy; -var template = require('jsdoc/template'); -var util = require('util'); - -var htmlsafe = helper.htmlsafe; -var linkto = helper.linkto; -var resolveAuthorLinks = helper.resolveAuthorLinks; -var hasOwnProp = Object.prototype.hasOwnProperty; - -var data; -var view; - -var outdir = path.normalize(env.opts.destination); +const doop = require('jsdoc/util/doop'); +const fs = require('jsdoc/fs'); // jsdoc/fs offer non-standard functions (mkPath) +const fsExtra = require('fs-extra'); +const helper = require('jsdoc/util/templateHelper'); +const logger = require('jsdoc/util/logger'); +const path = require('jsdoc/path'); +const taffy = require('taffydb').taffy; +const template = require('jsdoc/template'); +const util = require('util'); + +const htmlsafe = helper.htmlsafe; +const linkto = helper.linkto; +const resolveAuthorLinks = helper.resolveAuthorLinks; +const hasOwnProp = Object.prototype.hasOwnProperty; + +let data; +let view; + +let outdir = path.normalize(env.opts.destination); function find(spec) { return helper.find(data, spec); @@ -36,14 +36,14 @@ function getAncestorLinks(doclet) { function hashToLink(doclet, hash) { if ( !/^(#.+)/.test(hash) ) { return hash; } - var url = helper.createLink(doclet); + let url = helper.createLink(doclet); url = url.replace(/(#.+|$)/, hash); return '' + hash + ''; } function needsSignature(doclet) { - var needsSig = false; + let needsSig = false; // function and class definitions always get a signature if (doclet.kind === 'function' || doclet.kind === 'class') { @@ -52,7 +52,7 @@ function needsSignature(doclet) { // typedefs that contain functions get a signature, too else if (doclet.kind === 'typedef' && doclet.type && doclet.type.names && doclet.type.names.length) { - for (var i = 0, l = doclet.type.names.length; i < l; i++) { + for (let i = 0, l = doclet.type.names.length; i < l; i++) { if (doclet.type.names[i].toLowerCase() === 'function') { needsSig = true; break; @@ -64,7 +64,7 @@ function needsSignature(doclet) { } function getSignatureAttributes(item) { - var attributes = []; + const attributes = []; if (item.optional) { attributes.push('opt'); @@ -81,8 +81,8 @@ function getSignatureAttributes(item) { } function updateItemName(item) { - var attributes = getSignatureAttributes(item); - var itemName = item.name || ''; + const attributes = getSignatureAttributes(item); + let itemName = item.name || ''; if (item.variable) { itemName = '…' + itemName; @@ -97,16 +97,16 @@ function updateItemName(item) { } function addParamAttributes(params) { - return params.filter(function(param) { + return params.filter(param => { return param.name && param.name.indexOf('.') === -1; }).map(updateItemName); } function buildItemTypeStrings(item) { - var types = []; + const types = []; if (item && item.type && item.type.names) { - item.type.names.forEach(function(name) { + item.type.names.forEach(name => { types.push( linkto(name, htmlsafe(name)) ); }); } @@ -115,7 +115,7 @@ function buildItemTypeStrings(item) { } function buildAttribsString(attribs) { - var attribsString = ''; + let attribsString = ''; if (attribs && attribs.length) { attribsString = htmlsafe( util.format('(%s) ', attribs.join(', ')) ); @@ -125,9 +125,9 @@ function buildAttribsString(attribs) { } function addNonParamAttributes(items) { - var types = []; + let types = []; - items.forEach(function(item) { + items.forEach(item => { types = types.concat( buildItemTypeStrings(item) ); }); @@ -135,22 +135,22 @@ function addNonParamAttributes(items) { } function addSignatureParams(f) { - var params = f.params ? addParamAttributes(f.params) : []; + const params = f.params ? addParamAttributes(f.params) : []; f.signature = util.format( '%s(%s)', (f.signature || ''), params.join(', ') ); } function addSignatureReturns(f) { - var attribs = []; - var attribsString = ''; - var returnTypes = []; - var returnTypesString = ''; + const attribs = []; + let attribsString = ''; + let returnTypes = []; + let returnTypesString = ''; // jam all the return-type attributes into an array. this could create odd results (for example, // if there are both nullable and non-nullable return types), but let's assume that most people // who use multiple @return tags aren't using Closure Compiler type annotations, and vice-versa. if (f.returns) { - f.returns.forEach(function(item) { - helper.getAttribs(item).forEach(function(attrib) { + f.returns.forEach(item => { + helper.getAttribs(item).forEach(attrib => { if (attribs.indexOf(attrib) === -1) { attribs.push(attrib); } @@ -172,21 +172,21 @@ function addSignatureReturns(f) { } function addSignatureTypes(f) { - var types = f.type ? buildItemTypeStrings(f) : []; + const types = f.type ? buildItemTypeStrings(f) : []; f.signature = (f.signature || '') + '' + (types.length ? ' :' + types.join('|') : '') + ''; } function addAttribs(f) { - var attribs = helper.getAttribs(f); - var attribsString = buildAttribsString(attribs); + const attribs = helper.getAttribs(f); + const attribsString = buildAttribsString(attribs); f.attribs = util.format('%s', attribsString); } function shortenPaths(files, commonPrefix) { - Object.keys(files).forEach(function(file) { + Object.keys(files).forEach(file => { files[file].shortened = files[file].resolved.replace(commonPrefix, '') // always use forward slashes .replace(/\\/g, '/'); @@ -208,14 +208,14 @@ function getPathFromDoclet(doclet) { function generate(type, title, docs, filename, resolveLinks) { resolveLinks = resolveLinks === false ? false : true; - var docData = { + const docData = { type: type, title: title, docs: docs }; - var outpath = path.join(outdir, filename), - html = view.render('container.tmpl', docData); + const outpath = path.join(outdir, filename); + let html = view.render('container.tmpl', docData); if (resolveLinks) { html = helper.resolveLinks(html); // turn {@link foo} into foo @@ -226,11 +226,11 @@ function generate(type, title, docs, filename, resolveLinks) { function generateSourceFiles(sourceFiles, encoding) { encoding = encoding || 'utf8'; - var sourceFilenames = []; - Object.keys(sourceFiles).forEach(function(file) { - var source; + const sourceFilenames = []; + Object.keys(sourceFiles).forEach(file => { + let source; // links are keyed to the shortened path in each doclet's `meta.shortpath` property - var sourceOutfile = helper.getUniqueFilename(sourceFiles[file].shortened); + const sourceOutfile = helper.getUniqueFilename(sourceFiles[file].shortened); sourceFilenames.push(sourceOutfile); helper.registerLink(sourceFiles[file].shortened, sourceOutfile); @@ -260,23 +260,23 @@ function generateSourceFiles(sourceFiles, encoding) { * @param {Array.} modules - The array of module doclets to search. */ function attachModuleSymbols(doclets, modules) { - var symbols = {}; + const symbols = {}; // build a lookup table - doclets.forEach(function(symbol) { + doclets.forEach(symbol => { symbols[symbol.longname] = symbols[symbol.longname] || []; symbols[symbol.longname].push(symbol); }); - return modules.map(function(module) { + return modules.map(module => { if (symbols[module.longname]) { module.modules = symbols[module.longname] // Only show symbols that have a description. Make an exception for classes, because // we want to show the constructor-signature heading no matter what. - .filter(function(symbol) { + .filter(symbol => { return symbol.description || symbol.kind === 'class'; }) - .map(function(symbol) { + .map(symbol => { symbol = doop(symbol); if (symbol.kind === 'class' || symbol.kind === 'function') { @@ -290,14 +290,14 @@ function attachModuleSymbols(doclets, modules) { } function buildMemberNav(items, itemHeading, itemsSeen, linktoFn) { - var nav = ''; + let nav = ''; if (items && items.length) { - var itemsNav = ''; + let itemsNav = ''; - items.forEach(function(item) { - var methods = find({kind:'function', memberof: item.longname}); - var members = find({kind:'member', memberof: item.longname}); + items.forEach(item => { + const methods = find({kind:'function', memberof: item.longname}); + const members = find({kind:'member', memberof: item.longname}); if ( !hasOwnProp.call(item, 'longname') ) { itemsNav += '
  • ' + linktoFn('', item.name); @@ -307,7 +307,7 @@ function buildMemberNav(items, itemHeading, itemsSeen, linktoFn) { if (methods.length) { itemsNav += "