Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc, tools: refactor html generation #6974

Closed
wants to merge 17 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
doc, tools: meet dependencies
  • Loading branch information
eljefedelrodeodeljefe committed May 25, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 0d9d4a659f830837f54c865fe4899cb0f8c62e19
2 changes: 1 addition & 1 deletion test/doctool/test-doctool-html.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');

const html = require('../../tools/doc/html.js');
const html = require('../../tools/doc/html.js').toHTML;

// Test data is a list of objects with two properties.
// The file property is the file path.
2 changes: 1 addition & 1 deletion tools/doc/generate.js
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ function next(er, input) {
break;

case 'html':
require('./html.js')(input, inputFile, template, nodeVersion,
require('./html.js').toHTML(input, inputFile, template, nodeVersion,
function(er, html) {
if (er) throw er;
console.log(html);
30 changes: 1 addition & 29 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
'use strict';

const common = require('./common.js');
const fs = require('fs');
const marked = require('marked');
const path = require('path');
const preprocess = require('./preprocess.js');
const typeParser = require('./type-parser.js');

const linkManPages = require('./lib/linkManPages')
const parseText = require('./lib/parseText')
const toHTML = require('./lib/toHTML')
const loadGtoc = require('./lib/loadGtoc')
const toID = require('./lib/toID')
const render = require('./lib/render')
const parseLists = require('./lib/parseLists')
const parseYAML = require('./lib/parseYAML')
const linkJsTypeDocs = require('./lib/linkJsTypeDocs')
const parseAPIHeader = require('./lib/parseAPIHeader')
const getSection = require('./lib/getSection')
const buildToc = require('./lib/buildToc')
const getId = require('./lib/getId')

module.exports = toHTML;

// customized heading without id attribute
var renderer = new marked.Renderer();
renderer.heading = function(text, level) {
return '<h' + level + '>' + text + '</h' + level + '>\n';
};
marked.setOptions({
renderer: renderer
});
module.exports.toHTML = toHTML;
3 changes: 3 additions & 0 deletions tools/doc/lib/buildToc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const marked = require('marked')
const toID = require('./toID.js');
const getId = require('./getId.js');

module.exports = function buildToc(lexed, filename, cb) {
var toc = [];
2 changes: 2 additions & 0 deletions tools/doc/lib/linkJsTypeDocs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const typeParser = require('../type-parser.js');

module.exports = function linkJsTypeDocs(text) {
var parts = text.split('`');
var i;
12 changes: 9 additions & 3 deletions tools/doc/lib/loadGtoc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
const path = require('path')
const fs = require('fs')
const marked = require('marked')
const preprocess = require('../preprocess.js');
const toID = require('./toID.js');
// TODO(chrisdickinson): never stop vomitting / fix this.
var gtocPath = path.resolve(path.join(
__dirname,
'..',
'..',
'..',
'doc',
'api',
'_toc.md'
));
var gtocLoading = null;
var gtocData = null;
global.global.gtocLoading = null;
global.gtocData = null;


module.epxorts = function loadGtoc(cb) {
exports.loadGtoc = (cb) => {
fs.readFile(gtocPath, 'utf8', function(err, data) {
if (err) return cb(err);

4 changes: 3 additions & 1 deletion tools/doc/lib/parseLists.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

const common = require('../common.js');
const parseAPIHeader = require('./parseAPIHeader.js');
const parseYAML = require('./parseYAML.js');
// just update the list item text in-place.
// lists that come right after a heading are what we're after.
module.exports = function parseLists(input) {
2 changes: 2 additions & 0 deletions tools/doc/lib/parseText.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const linkManPages = require('./linkManPages')
const linkJsTypeDocs = require('./linkJsTypeDocs')
// handle general body-text replacements
// for example, link man page references to the actual page
module.exports = function parseText(lexed) {
2 changes: 2 additions & 0 deletions tools/doc/lib/parseYAML.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const common = require('../common.js');

module.exports = function parseYAML(text) {
const meta = common.extractAndParseYAML(text);
const html = ['<div class="api_metadata">'];
10 changes: 9 additions & 1 deletion tools/doc/lib/render.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const path = require('path')
const marked = require('marked')
const getSection = require('./getSection')
const parseText = require('./parseText')
const parseLists = require('./parseLists')
const buildToc = require('./buildToc')
const toID = require('./toID.js');

module.exports = function render(lexed, filename, template, nodeVersion, cb) {
if (typeof nodeVersion === 'function') {
cb = nodeVersion;
@@ -28,7 +36,7 @@ module.exports = function render(lexed, filename, template, nodeVersion, cb) {
template = template.replace(/__TOC__/g, toc);
template = template.replace(
/__GTOC__/g,
gtocData.replace('class="nav-' + id, 'class="nav-' + id + ' active')
global.gtocData.replace('class="nav-' + id, 'class="nav-' + id + ' active')
);

// content has to be the last thing we do with
29 changes: 22 additions & 7 deletions tools/doc/lib/toHTML.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
const fs = require('fs')
const loadGtoc = require('./loadGtoc').loadGtoc
const render = require('./render')
const marked = require('marked')

// customized heading without id attribute
var renderer = new marked.Renderer();
renderer.heading = function(text, level) {
return '<h' + level + '>' + text + '</h' + level + '>\n';
};
marked.setOptions({
renderer: renderer
});


module.exports = function toHTML(input, filename, template, nodeVersion, cb) {
if (typeof nodeVersion === 'function') {
cb = nodeVersion;
nodeVersion = null;
}
nodeVersion = nodeVersion || process.version;

if (gtocData) {
if (global.gtocData) {
return onGtocLoaded();
}

if (gtocLoading === null) {
gtocLoading = [onGtocLoaded];
if (global.gtocLoading === null) {
global.gtocLoading = [onGtocLoaded];
return loadGtoc(function(err, data) {
if (err) throw err;
gtocData = data;
gtocLoading.forEach(function(xs) {
global.gtocData = data;
global.gtocLoading.forEach(function(xs) {
xs();
});
});
}

if (gtocLoading) {
return gtocLoading.push(onGtocLoaded);
if (global.gtocLoading) {
return global.gtocLoading.push(onGtocLoaded);
}

function onGtocLoaded() {