Browse Source

tools: allow multiple added: version entries

Allow multiple `added:` version entries, since semver-minors
can trickle down to previous major versions, and thus
features may have been added in multiple versions.

Also include `deprecated:` entries and apply the same logic
to them for consistency.

Stylize the added HTML as `Added in:` and `Deprecated since:`.

PR-URL: https://github.com/nodejs/node/pull/6495
Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
process-exit-stdio-flushing
Anna Henningsen 9 years ago
parent
commit
00ffa33564
No known key found for this signature in database GPG Key ID: D8B9F5AEAE84E4CF
  1. 9
      test/doctool/test-doctool-html.js
  2. 17
      test/doctool/test-doctool-json.js
  3. 9
      test/fixtures/doc_with_yaml.md
  4. 21
      tools/doc/common.js
  5. 13
      tools/doc/html.js

9
test/doctool/test-doctool-html.js

@ -34,12 +34,17 @@ const testData = [
' id="foo_sample_markdown_with_yaml_info">#</a></span></h1>' +
'<h2>Foobar<span><a class="mark" href="#foo_foobar" ' +
'id="foo_foobar">#</a></span></h2>' +
'<div class="api_metadata"><span>Added: v1.0.0</span></div> ' +
'<div class="api_metadata"><span>Added in: v1.0.0</span></div> ' +
'<p>Describe <code>Foobar</code> in more detail here.</p>' +
'<h2>Foobar II<span><a class="mark" href="#foo_foobar_ii" ' +
'id="foo_foobar_ii">#</a></span></h2>' +
'<div class="api_metadata"><span>Added in: v5.3.0, v4.2.0</span></div> ' +
'<p>Describe <code>Foobar II</code> in more detail here.</p>' +
'<h2>Deprecated thingy<span><a class="mark" ' +
'href="#foo_deprecated_thingy" id="foo_deprecated_thingy">#</a>' +
'</span></h2>' +
'<div class="api_metadata"><span>Added: v1.0.0</span></div><p>Describe ' +
'<div class="api_metadata"><span>Added in: v1.0.0</span>' +
'<span>Deprecated since: v2.0.0</span></div><p>Describe ' +
'<code>Deprecated thingy</code> in more detail here.</p>' +
'<h2>Something<span><a class="mark" href="#foo_something" ' +
'id="foo_something">#</a></span></h2> ' +

17
test/doctool/test-doctool-json.js

@ -78,19 +78,30 @@ var testData = [
'textRaw': 'Foobar',
'name': 'foobar',
'meta': {
'added': 'v1.0.0'
'added': ['v1.0.0']
},
'desc': '<p>Describe <code>Foobar</code> in more detail ' +
'here.\n\n</p>\n',
'type': 'module',
'displayName': 'Foobar'
},
{
'textRaw': 'Foobar II',
'name': 'foobar_ii',
'meta': {
'added': ['v5.3.0', 'v4.2.0']
},
'desc': '<p>Describe <code>Foobar II</code> in more detail ' +
'here.\n\n</p>\n',
'type': 'module',
'displayName': 'Foobar II'
},
{
'textRaw': 'Deprecated thingy',
'name': 'deprecated_thingy',
'meta': {
'added': 'v1.0.0',
'deprecated': 'v2.0.0'
'added': ['v1.0.0'],
'deprecated': ['v2.0.0']
},
'desc': '<p>Describe <code>Deprecated thingy</code> in more ' +
'detail here.\n\n</p>\n',

9
test/fixtures/doc_with_yaml.md

@ -7,6 +7,15 @@ added: v1.0.0
Describe `Foobar` in more detail here.
## Foobar II
<!-- YAML
added:
- v5.3.0
- v4.2.0
-->
Describe `Foobar II` in more detail here.
## Deprecated thingy
<!-- YAML
added: v1.0.0

21
tools/doc/common.js

@ -8,6 +8,10 @@ function isYAMLBlock(text) {
exports.isYAMLBlock = isYAMLBlock;
function arrify(value) {
return Array.isArray(value) ? value : [value];
}
function extractAndParseYAML(text) {
text = text.trim();
@ -15,7 +19,22 @@ function extractAndParseYAML(text) {
.replace(/-->$/, '');
// js-yaml.safeLoad() throws on error
return yaml.safeLoad(text);
const meta = yaml.safeLoad(text);
const added = meta.added || meta.Added;
if (added) {
// Since semver-minors can trickle down to previous major versions,
// features may have been added in multiple versions.
meta.added = arrify(added);
}
const deprecated = meta.deprecated || meta.Deprecated;
if (deprecated) {
// Treat deprecated like added for consistency.
meta.deprecated = arrify(deprecated);
}
return meta;
}
exports.extractAndParseYAML = extractAndParseYAML;

13
tools/doc/html.js

@ -180,15 +180,18 @@ function parseLists(input) {
function parseYAML(text) {
const meta = common.extractAndParseYAML(text);
let html = '<div class="api_metadata">';
const html = ['<div class="api_metadata">'];
if (meta.added || meta.Added) {
meta.added = meta.added || meta.Added;
if (meta.added) {
html.push(`<span>Added in: ${meta.added.join(', ')}</span>`);
}
html += '<span>Added: ' + meta.added + '</span>';
if (meta.deprecated) {
html.push(`<span>Deprecated since: ${meta.deprecated.join(', ')} </span>`);
}
return html + '</div>';
html.push('</div>');
return html.join('\n');
}
// Syscalls which appear in the docs, but which only exist in BSD / OSX

Loading…
Cancel
Save