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

tools: parse documentation metadata #3867

Closed
wants to merge 1 commit into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions doc/api_assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ code a:hover {
background-color: #0084B6;
}

.api_metadata {
font-size: .75em;
margin-bottom: 1em;
}

.api_metadata span {
margin-right: 1em;
}

.api_metadata span:last-child {
margin-right: 0px;
}

ul.plain {
list-style: none;
}
Expand Down
27 changes: 27 additions & 0 deletions tools/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ Each type of heading has a description block.


## module
<!-- YAML
added: v0.10.0
-->

Stability: 3 - Stable

description and examples.

### module.property
<!-- YAML
added: v0.10.0
-->

* Type

description of the property.

### module.someFunction(x, y, [z=100])
<!-- YAML
added: v0.10.0
-->

* `x` {String} the description of the string
* `y` {Boolean} Should I stay or should I go?
Expand All @@ -26,17 +35,26 @@ Each type of heading has a description block.
A description of the function.

### Event: 'blerg'
<!-- YAML
added: v0.10.0
-->

* Argument: SomeClass object.

Modules don't usually raise events on themselves. `cluster` is the
only exception.

## Class: SomeClass
<!-- YAML
added: v0.10.0
-->

description of the class.

### Class Method: SomeClass.classMethod(anArg)
<!-- YAML
added: v0.10.0
-->

* `anArg` {Object} Just an argument
* `field` {String} anArg can have this field.
Expand All @@ -46,16 +64,25 @@ Each type of heading has a description block.
Description of the method for humans.

### someClass.nextSibling()
<!-- YAML
added: v0.10.0
-->

* Return: {SomeClass object | null} The next someClass in line.

### someClass.someProperty
<!-- YAML
added: v0.10.0
-->

* String

The indication of what someProperty is.

### Event: 'grelb'
<!-- YAML
added: v0.10.0
-->

* `isBlerg` {Boolean}

Expand Down
21 changes: 21 additions & 0 deletions tools/doc/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const yaml = require('js-yaml');

function isYAMLBlock(text) {
return !!text.match(/^<!-- YAML/);
}

exports.isYAMLBlock = isYAMLBlock;

function extractAndParseYAML(text) {
text = text.trim();

text = text.replace(/^<!-- YAML/, '')
.replace(/-->$/, '');

// js-yaml.safeLoad() throws on error
return yaml.safeLoad(text);
}

exports.extractAndParseYAML = extractAndParseYAML;
16 changes: 8 additions & 8 deletions tools/doc/generate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var processIncludes = require('./preprocess.js');
var marked = require('marked');
var fs = require('fs');
var path = require('path');
'use strict';

const processIncludes = require('./preprocess.js');
const fs = require('fs');

// parse the args.
// Don't use nopt or whatever for this. It's simple enough.

var args = process.argv.slice(2);
var format = 'json';
var template = null;
var inputFile = null;
const args = process.argv.slice(2);
let format = 'json';
let template = null;
let inputFile = null;

args.forEach(function (arg) {
if (!arg.match(/^\-\-/)) {
Expand Down
31 changes: 24 additions & 7 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
var fs = require('fs');
var marked = require('marked');
var path = require('path');
var preprocess = require('./preprocess.js');
'use strict';

const common = require('./common.js');
const fs = require('fs');
const marked = require('marked');
const path = require('path');
const 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'));
const gtocPath = path.resolve(path.join(__dirname, '..', '..', 'doc', 'api', '_toc.markdown'));
var gtocLoading = null;
var gtocData = null;

Expand Down Expand Up @@ -85,7 +88,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);
let content = marked.parser(lexed);
template = template.replace(/__CONTENT__/g, content);

cb(null, template);
Expand Down Expand Up @@ -123,6 +126,9 @@ function parseLists(input) {
output.push(tok);
return;
}
if (tok.type === 'html' && common.isYAMLBlock(tok.text)) {
tok.text = parseYAML(tok.text);
}
state = null;
output.push(tok);
return;
Expand Down Expand Up @@ -152,6 +158,18 @@ function parseLists(input) {
return output;
}

function parseYAML(text) {
const meta = common.extractAndParseYAML(text);
let html = '<div class="api_metadata">';

if(meta.added || meta.Added){
meta.added = meta.added || meta.Added;

html += '<span>Added: ' + meta.added + '</span>';
}

return html + '</div>';
}

function parseListItem(text) {
var parts = text.split('`');
Expand Down Expand Up @@ -219,4 +237,3 @@ function getId(text) {
}
return text;
}

10 changes: 9 additions & 1 deletion tools/doc/json.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict';

module.exports = doJSON;

// Take the lexed input, and return a JSON-encoded object
// A module looks like this: https://gist.github.com/1777387

var marked = require('marked');
const common = require('./common.js');
const marked = require('marked');

function doJSON(input, filename, cb) {
var root = {source: filename};
Expand Down Expand Up @@ -89,6 +92,8 @@ function doJSON(input, filename, cb) {
current.list = current.list || [];
current.list.push(tok);
current.list.level = 1;
} else if ( type === 'html' ) {
current.meta = parseYAML(tok.text);
} else {
current.desc = current.desc || [];
if (!Array.isArray(current.desc)) {
Expand Down Expand Up @@ -265,6 +270,9 @@ function processList(section) {
delete section.list;
}

function parseYAML(text) {
return common.extractAndParseYAML(text);
}

// textRaw = "someobject.someMethod(a[, b=100][, c])"
function parseSignature(text, sig) {
Expand Down
15 changes: 15 additions & 0 deletions tools/doc/node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tools/doc/node_modules/.bin/esparse.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tools/doc/node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tools/doc/node_modules/.bin/esvalidate.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tools/doc/node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tools/doc/node_modules/.bin/js-yaml.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading