function generateHtml (docs, done) { var docsHtml = ''; var githubMark = octicons['mark-github'].toSVG({ 'width': 45 }); docs['$.utils'] = docsForUtils; var totalFiles = 3; // number of root-level files from below utils.each(docs, function (categoryDocs) { totalFiles += categoryDocs.length; }); var totalWrites = 0; function writeComplete (f) { totalWrites++; if (totalWrites >= totalFiles) { done(); } } utils.each(docs, function (categoryDocs, categoryName) { docsHtml += '<h2 class="module-name">' + categoryName + '</h2>'; docsHtml += '<div class="methods"><table>'; utils.each(categoryDocs, function (doc) { docsHtml += utils.template(utils.readFile('build/_docs_templates/_doc.html'), doc); if (doc.params.length) { doc.paramsTable = '<table>'; doc.params.forEach(function (param) { var paramTypes = []; param.types.forEach(function (type) { paramTypes.push('<a href="../../types/#' + type.toLowerCase() + '">' + type + '</a>'); }); doc.paramsTable += '<tr><td class="param-name">' + param.name + '</td><td class="param-types">{' + paramTypes.join('/') + '}' + (param.optional ? ' [optional]' : '') + '</td><td class="param-desc">' + param.desc + '</td></tr>'; }); doc.paramsTable += '</table>'; } else { doc.paramsTable = '<p>none</p>'; } utils.writeFile('docs/api/' + doc.name + '/index.html', utils.template(utils.readFile('build/_docs_templates/method.html'), doc), writeComplete); }); docsHtml += '</table></div>'; }); // root-level files utils.writeFile('docs/api/index.html', utils.template(utils.readFile('build/_docs_templates/index.html'), { docs: docsHtml, githubMark: githubMark }), writeComplete); utils.writeFile('docs/api/index.css', utils.readFile('build/_docs_templates/index.css'), writeComplete); utils.writeFile('docs/api/method.css', utils.readFile('build/_docs_templates/method.css'), writeComplete); }
utils.each(docs, function (categoryDocs, categoryName) { docsHtml += '<h2 class="module-name">' + categoryName + '</h2>'; docsHtml += '<div class="methods"><table>'; utils.each(categoryDocs, function (doc) { docsHtml += utils.template(utils.readFile('build/_docs_templates/_doc.html'), doc); if (doc.params.length) { doc.paramsTable = '<table>'; doc.params.forEach(function (param) { var paramTypes = []; param.types.forEach(function (type) { paramTypes.push('<a href="../../types/#' + type.toLowerCase() + '">' + type + '</a>'); }); doc.paramsTable += '<tr><td class="param-name">' + param.name + '</td><td class="param-types">{' + paramTypes.join('/') + '}' + (param.optional ? ' [optional]' : '') + '</td><td class="param-desc">' + param.desc + '</td></tr>'; }); doc.paramsTable += '</table>'; } else { doc.paramsTable = '<p>none</p>'; } utils.writeFile('docs/api/' + doc.name + '/index.html', utils.template(utils.readFile('build/_docs_templates/method.html'), doc), writeComplete); }); docsHtml += '</table></div>'; });
function buildNavHTML (data) { var html = '<ul>'; utils.each(data.dirs, function (dir, name) { html += '<li><div class="readmejs-nav-dir-name readmejs-nav-clickable">' + name + '</div><div class="readmejs-nav-dir-contents">' + buildNavHTML(dir) + '</li>'; }); data.files.forEach(function (file) { html += '<li><div class="readmejs-nav-file-name readmejs-nav-clickable" data-nav-id="' + file.path + '">' + file.filename + '</div></li>'; }); return html + '</ul>'; }
function buildModulesHTML (data, options, current) { current = current || { parent: 'app', id: '', class: '', tab: '', item: false }; var html = current.tab + '<div' + getId(data, options, current) + getClass(data, options, current) + '>'; if (typeof data === 'object') { if (current.id === 'params' && data.length) { html += '\n' + current.tab + indent + '<div class="readmejs-params-headers">\n' + current.tab + indent + indent + '<div class="readmejs-param-header-name">Name</div>\n' + current.tab + indent + indent + '<div class="readmejs-param-header-type">Type</div>\n' + current.tab + indent + indent + '<div class="readmejs-param-header-description">Description</div>\n' + current.tab + indent + '</div>'; } if (!Array.isArray(data) || data.length) { utils.each(data, function (v, k) { if (typeof k !== 'string' || k.indexOf('_') !== 0) { html += '\n' + buildModulesHTML(v, options, { parent: current.parent + dash(current.id), id: k, class: data._classname, tab: current.tab + indent, item: true }); } }); html += '\n' + current.tab; } } else if (typeof data !== 'undefined') { html += data; } return html + '</div>'; }