Skip to content
This repository was archived by the owner on Mar 25, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/.bin/lab
node_modules/lab/
5 changes: 4 additions & 1 deletion generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var args = process.argv.slice(2);
var format = 'json';
var template = null;
var inputFile = null;
var gtocPath = null;

args.forEach(function (arg) {
if (!arg.match(/^\-\-/)) {
Expand All @@ -40,6 +41,8 @@ args.forEach(function (arg) {
format = arg.replace(/^\-\-format=/, '');
} else if (arg.match(/^\-\-template=/)) {
template = arg.replace(/^\-\-template=/, '');
} else if (arg.match(/^\-\-gtoc=/)) {
gtocPath = arg.replace(/^\-\-gtoc=/, '');
}
})

Expand Down Expand Up @@ -70,7 +73,7 @@ function next(er, input) {
break;

case 'html':
require('./html.js')(input, inputFile, template, function(er, html) {
require('./html.js')(input, inputFile, template, gtocPath, function(er, html) {
if (er) throw er;
console.log(html);
});
Expand Down
10 changes: 4 additions & 6 deletions html.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ var preprocess = require('./preprocess.js');

module.exports = toHTML;

// TODO(chrisdickinson): never stop vomitting / fix this.
var gtocPath = path.resolve(path.join(__dirname, '..', '..', 'doc', 'api', '_toc.markdown'));
var gtocLoading = null;
var gtocData = null;

function toHTML(input, filename, template, cb) {
function toHTML(input, filename, template, gtocPath, cb) {
if (gtocData) {
return onGtocLoaded();
}

if (gtocLoading === null) {
gtocLoading = [onGtocLoaded];
return loadGtoc(function(err, data) {
return loadGtoc(gtocPath, function(err, data) {
if (err) throw err;
gtocData = data;
gtocLoading.forEach(function(xs) {
Expand All @@ -60,7 +58,7 @@ function toHTML(input, filename, template, cb) {
}
}

function loadGtoc(cb) {
function loadGtoc(gtocPath, cb) {
fs.readFile(gtocPath, 'utf8', function(err, data) {
if (err) return cb(err);

Expand Down Expand Up @@ -106,7 +104,7 @@ function render(lexed, filename, template, cb) {

// content has to be the last thing we do with
// the lexed tokens, because it's destructive.
content = marked.parser(lexed);
var content = marked.parser(lexed);
template = template.replace(/__CONTENT__/g, content);

cb(null, template);
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
"engines": {
"node": ">=0.6.10"
},
"scripts": {
"test": "lab -v"
},
"dependencies": {
"marked": "~0.1.9"
},
"devDependencies": {},
"devDependencies": {
"lab": "~5.2.1"
},
"optionalDependencies": {},
"bin": "./generate.js"
}
45 changes: 45 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var Lab = require('lab');
var lab = exports.lab = Lab.script();
var assert = require('assert');

var spawn = require('child_process').spawn;

lab.experiment('doc generation', function() {
lab.test('it renders html from *.markdown files', function(done) {
var files = [__dirname + '/fixtures/markdown/index.markdown'];

generate('html', files, function (err, buf) {
assert.ok(/<h2>hello from index.markdown/.test(buf.toString()));
done();
});
});

lab.test('it processes includes from *.markdown files', function(done) {
var files = [__dirname + '/fixtures/markdown/index.markdown'];

generate('html', files, function (err, buf) {
assert.ok(/<h2>Hello from include with markdown-fileending!/.test(buf.toString()));
done();
});
});
});


function generate(format, files, cb) {
var buffer = '',
child;

child = spawn(__dirname + '/../generate.js', [
'--format=' + format,
'--gtoc=' + __dirname + '/fixtures/markdown/_toc.markdown',
'--template=' + __dirname + '/fixtures/template.html'
].concat(files));

child.stdout.on('data', function(chunk) {
buffer += chunk;
});

child.on('close', function () {
cb(null, buffer);
});
}
1 change: 1 addition & 0 deletions test/fixtures/markdown/include-fixture.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Hello from include with markdown-fileending!
5 changes: 5 additions & 0 deletions test/fixtures/markdown/index.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Api Docs

## hello from index.markdown

@include include-fixture
78 changes: 78 additions & 0 deletions test/fixtures/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>__SECTION__ Node.js __VERSION__ Manual &amp; Documentation</title>
<link rel="stylesheet" href="assets/style.css">
<link rel="stylesheet" href="assets/sh.css">
<link rel="canonical" href="http://nodejs.org/api/__FILENAME__.html">
</head>
<body class="alt apidoc" id="api-section-__FILENAME__">
<div id="intro" class="interior">
<a href="/" title="Go back to the home page">
<img id="logo" src="http://nodejs.org/images/logo-light.png" alt="node.js">
</a>
</div>
<div id="content" class="clearfix">
<div id="column2" class="interior">
<ul>
<li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li>
<li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li>
<li><a href="/logos/" class="logos">Resources</a></li>
<li><a href="http://jobs.nodejs.org/" class="jobs">Jobs</a></li>
</ul>
<p class="twitter"><a href="http://twitter.com/nodejs">@nodejs</a></p>
</div>

<div id="column1" class="interior">
<header>
<h1>Node.js __VERSION__ Manual &amp; Documentation</h1>
<div id="gtoc">
<p>
<a href="index.html" name="toc">Index</a> |
<a href="all.html">View on single page</a> |
<a href="__FILENAME__.json">View as JSON</a>
</p>
</div>
<hr>
</header>

<div id="toc">
<h2>Table of Contents</h2>
__TOC__
</div>

<div id="apicontent">
__CONTENT__
</div>
</div>
</div>
<div id="footer">
<a href="http://joyent.com" class="joyent-logo">Joyent</a>
<ul class="clearfix">
<li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li>
<li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li>
<li><a href="/logos/">Resources</a></li>
<li><a href="http://jobs.nodejs.org/">Jobs</a></li>
<li><a href="http://twitter.com/nodejs" class="twitter">@nodejs</a></li>
</ul>

<p class="copyright">Copyright 2015 <a href="http://joyent.com/">Joyent, Inc</a>, Node.js is a <a href="/images/trademark-policy.pdf">trademark</a> of Joyent, Inc. <a href="https://raw.github.com/joyent/node/__VERSION__/LICENSE">View license</a>.</p>
</div>

<script src="../sh_main.js"></script>
<script src="../sh_javascript.min.js"></script>
<script>highlight(undefined, undefined, 'pre');</script>
<script src="/tracking.js"></script>
</body>
</html>