Skip to content

Commit 9db33ae

Browse files
committed
Add many document options.
1 parent be601a4 commit 9db33ae

12 files changed

+156
-10
lines changed

css/elements.css

+14
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ emu-gprose {
206206
font-family: Helvetica, Arial, sans-serif;
207207
}
208208

209+
h1.shortname {
210+
color: #f60;
211+
font-size: 1.5em;
212+
margin: 0;
213+
}
214+
h1.version {
215+
color: #f60;
216+
font-size: 1.5em;
217+
margin: 0;
218+
}
219+
h1.title {
220+
margin-top: 0;
221+
color: #f60;
222+
}
209223
h1, h2, h3, h4, h5, h6 {
210224
position: relative;
211225
}

lib/Spec.js

+73-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const clauseTextNodesUnder = utils.textNodesUnder(NO_CLAUSE_AUTOLINK);
2727
const NO_ALG_AUTOLINK = ['PRE', 'CODE', 'EMU-XREF'];
2828
const algTextNodesUnder = utils.textNodesUnder(NO_ALG_AUTOLINK);
2929

30+
const DRAFT_DATE_FORMAT = { year: 'numeric', month: 'long', day: 'numeric' };
31+
const STANDARD_DATE_FORMAT = { year: 'numeric', month: 'long' };
32+
3033
module.exports = class Spec {
3134
constructor (rootPath, fetch, doc, opts) {
3235
opts = opts || {};
@@ -110,6 +113,7 @@ module.exports = class Spec {
110113

111114
build() {
112115
let p = this.buildAll('emu-import', Import)
116+
.then(this.buildBoilerplate.bind(this))
113117
.then(this.loadES6Biblio.bind(this))
114118
.then(this.loadBiblios.bind(this))
115119
.then(this.buildAll.bind(this, 'emu-clause, emu-intro, emu-annex', Clause))
@@ -196,7 +200,7 @@ module.exports = class Spec {
196200

197201
exportBiblio() {
198202
if (!this.opts.location) {
199-
utils.logWarning('no spec location specified. Biblio not generated. Try --location or setting the location in the document\'s metadata block.');
203+
utils.logWarning('No spec location specified. Biblio not generated. Try --location or setting the location in the document\'s metadata block.');
200204
return {};
201205
}
202206

@@ -224,6 +228,60 @@ module.exports = class Spec {
224228
}
225229
}
226230

231+
buildBoilerplate() {
232+
const status = this.opts.status || 'proposal';
233+
const version = this.opts.version;
234+
const title = this.opts.title;
235+
const shortname = this.opts.shortname;
236+
const stage = this.opts.stage === undefined ? null : String(this.opts.stage);
237+
238+
// no title boilerplate generated if title not specified
239+
if (!title) return;
240+
241+
// title
242+
if (title && !this._updateBySelector('title', title)) {
243+
const titleElem = this.doc.createElement('title');
244+
titleElem.innerHTML = title;
245+
this.doc.head.appendChild(titleElem);
246+
247+
const h1 = this.doc.createElement('h1');
248+
h1.setAttribute('class', 'title');
249+
h1.innerHTML = title;
250+
this.doc.body.insertBefore(h1, this.doc.body.firstChild);
251+
}
252+
253+
// version string, ala 6th Edition July 2016 or Draft 10 / September 26, 2015
254+
let versionText = '';
255+
if (version) {
256+
versionText += version + ' / ';
257+
} else if (status === 'proposal' && stage) {
258+
versionText += 'Stage ' + stage + ' Draft / ';
259+
}
260+
261+
const defaultDateFormat = status === 'standard' ? STANDARD_DATE_FORMAT : DRAFT_DATE_FORMAT;
262+
const date = this.opts.date || new Intl.DateTimeFormat('en-US', defaultDateFormat).format(new Date());
263+
versionText += date;
264+
265+
if (!this._updateBySelector('h1.version', versionText)) {
266+
const h1 = this.doc.createElement('h1');
267+
h1.setAttribute('class', 'version');
268+
h1.innerHTML = versionText;
269+
this.doc.body.insertBefore(h1, this.doc.body.firstChild);
270+
}
271+
272+
// shortname and status, ala 'Draft ECMA-262
273+
if (shortname) {
274+
const shortnameText = status.charAt(0).toUpperCase() + status.slice(1) + ' ' + shortname;
275+
276+
if (!this._updateBySelector('h1.shortname', shortnameText)) {
277+
const h1 = this.doc.createElement('h1');
278+
h1.setAttribute('class', 'shortname');
279+
h1.innerHTML = shortnameText;
280+
this.doc.body.insertBefore(h1, this.doc.body.firstChild);
281+
}
282+
}
283+
}
284+
227285
autolink() {
228286
this._log('Autolinking terms and abstract ops...');
229287
const termlinkmap = {};
@@ -294,6 +352,20 @@ module.exports = class Spec {
294352
if (!this.opts.verbose) return;
295353
utils.logVerbose(str);
296354
}
355+
356+
_updateBySelector(selector, contents) {
357+
const elem = this.doc.querySelector(selector);
358+
if (elem && elem.textContent.trim().length > 0) {
359+
return true;
360+
}
361+
362+
if (elem) {
363+
elem.innerHTML = contents;
364+
return true;
365+
}
366+
367+
return false;
368+
}
297369
};
298370

299371

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ecmarkup",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.",
55
"main": "lib/ecmarkup.js",
66
"scripts": {

spec/index.html

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<link rel="stylesheet" href="elements.css">
66
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/solarized_light.min.css">
77
<pre class=metadata>
8-
title: Ecmarkup Documentation
98
repository: https://github.com/bterlson/ecmarkup
109
</pre>
1110
<emu-biblio href="./biblio.json"></emu-biblio>
@@ -37,16 +36,28 @@ <h1>Getting Started</h1>
3736

3837
<emu-clause id="useful-options">
3938
<h1>Useful Options</h1>
40-
<p>These options can be passed in via the command line or specified in the front-matter of your document.</p>
41-
<emu-table>
42-
<emu-caption>Listing of available options</emu-caption>
39+
<p>Build options and document options can be passed in via the command line or specified in the front-matter of your document.</p>
40+
<emu-table id="build-options">
41+
<emu-caption>Build options</emu-caption>
4342
<table>
4443
<tr><th>Option</th><th>Description</th></tr>
4544
<tr><td>watch</td><td>Rebuild when files change</td></tr>
4645
<tr><td>verbose</td><td>Print verbose logging info</td></tr>
4746
<tr><td>biblio</td><td>Emit a biblio file to the specified location</td></tr>
4847
<tr><td>css</td><td>Emit the Ecmarkup CSS file to the specified location</td></tr>
4948
<tr><td>js</td><td>Emit the Ecmarkup JS file to the specified location</td></tr>
49+
</table>
50+
</emu-table>
51+
52+
<emu-table id="document-options">
53+
<emu-caption>Document options</emu-caption>
54+
<table>
55+
<tr><th>Option</th><th>Description</th></tr>
56+
<tr><td>title</td><td>Title of specification, for example `ECMAScript 2016` or `Async Functions`.</td></tr>
57+
<tr><td>status</td><td>Status of specification. Can be `proposal`, `draft`, or `standard`. Default is `proposal`.</td></tr>
58+
<tr><td>stage</td><td>Stage of proposal. Must be a number if provided, but is optional. Sets `version` to `Stage N Draft`, but can be overridden.</td></tr>
59+
<tr><td>version</td><td>Version of specification, for example `6<sup>th</sup> Edition` or `Draft 1`. Optional.</td></tr>
60+
<tr><td>shortname</td><td>Shortname of specification, for example `ECMA-262` or `ECMA-402`.</td></tr>
5061
<tr><td>location</td><td>Href of this specification. Use in conjunction with the biblio file to enable external specs to reference this one.</td></tr>
5162
<tr><td>toc</td><td>Emit table of contents. Boolean, default true.</td></tr>
5263
<tr><td>old-toc</td><td>Emit the old style of table of contents. Boolean, default false.</td></tr>
@@ -119,7 +130,7 @@ <h1>Editorial Conventions</h1>
119130
<h1>Metadata</h1>
120131
<p>There are a number of settings that allow customizations or enable generation of boilerplate. Metadata can be included in the document and passed on the command line, for example `--no-toc --title "Document 1"`. Metadata given on the command line takes precedence.</p>
121132
<p>To add metadata to your document, use yaml syntax inside a `&lt;pre class=metadata>` element somewhere in the root of your document.</p>
122-
<p>All of the command line options can be provided in the metadata block. See the table above for a list (or consult `--help`).</p>
133+
<p>All of the command line options can be provided in the metadata block. See <emu-xref href="#build-options"></emu-xref> and <emu-xref href="#document-options"></emu-xref> for a list (or consult `--help`).</p>
123134
<h2>Example document with metadata</h2>
124135
<pre><code class="language-html">
125136
&lt;pre class=metadata>

test/date.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<pre class=metadata>
2+
title: test title!
3+
date: July, 2014
4+
toc: false
5+
</pre>
6+
7+
<p>Some body content</p>
8+

test/date.html.baseline

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!doctype html>
2+
<head><title>test title!</title><meta charset="utf-8"></head><body><h1 class="version">July, 2014</h1><h1 class="title">test title!</h1>
3+
4+
<p>Some body content</p>
5+
6+
</body>

test/shortname.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<pre class=metadata>
2+
title: test title!
3+
shortname: ECMA-000
4+
status: draft
5+
version: Draft 1
6+
toc: false
7+
</pre>
8+
9+
<p>Some body content</p>

test/shortname.html.baseline

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!doctype html>
2+
<head><title>test title!</title><meta charset="utf-8"></head><body><h1 class="shortname">Draft ECMA-000</h1><h1 class="version">Draft 1 / September 26, 2015</h1><h1 class="title">test title!</h1>
3+
4+
<p>Some body content</p>
5+
</body>

test/test.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<!doctype html>
22
<meta charset="utf-8">
3-
<link rel="stylesheet" href="https://bterlson.github.com/ecmarkup/elements.css">
3+
<link rel="stylesheet" href="./ecmarkup.css">
4+
<script src="ecmarkup.js"></script>
5+
<pre class="metadata">
6+
title: Ecmarkup Test Document
7+
status: draft
8+
version: Draft 1
9+
</pre>
410
<emu-intro>
511
<h1>Intro</h1>
612
<emu-intro>

test/test.html.baseline

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<!doctype html>
22
<head><meta charset="utf-8">
3-
<link rel="stylesheet" href="https://bterlson.github.com/ecmarkup/elements.css">
4-
</head><body><div id="menu-toggle">☰</div><div id="menu"><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">◢</span><a href="#" title="Intro"><span class="secnum"></span> Intro</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#" title="Sub Intro"><span class="secnum"></span> Sub Intro</a></li></ol></li><li><span class="item-toggle">◢</span><a href="#" title="Clause Foo(_a_, _b_)"><span class="secnum">1</span> Clause Foo(<var>a</var>, <var>b</var>)</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#Foo" title="Sub Clause"><span class="secnum">1.1</span> Sub Clause</a></li><li><span class="item-toggle-none"></span><a href="#Bar" title="Sub Clause"><span class="secnum">1.2</span> Sub Clause</a></li><li><span class="item-toggle">◢</span><a href="#Baz" title="Header"><span class="secnum">1.3</span> Header</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#import3" title="Import 3"><span class="secnum">1.3.1</span> Import 3</a></li></ol></li></ol></li><li><span class="item-toggle-none"></span><a href="#" title="Annex"><span class="secnum">A</span> Annex</a></li></ol></div></div><emu-intro>
3+
<link rel="stylesheet" href="./ecmarkup.css">
4+
<script src="ecmarkup.js"></script>
5+
<title>Ecmarkup Test Document</title></head><body><div id="menu-toggle">☰</div><div id="menu"><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">◢</span><a href="#" title="Intro"><span class="secnum"></span> Intro</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#" title="Sub Intro"><span class="secnum"></span> Sub Intro</a></li></ol></li><li><span class="item-toggle">◢</span><a href="#" title="Clause Foo(_a_, _b_)"><span class="secnum">1</span> Clause Foo(<var>a</var>, <var>b</var>)</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#Foo" title="Sub Clause"><span class="secnum">1.1</span> Sub Clause</a></li><li><span class="item-toggle-none"></span><a href="#Bar" title="Sub Clause"><span class="secnum">1.2</span> Sub Clause</a></li><li><span class="item-toggle">◢</span><a href="#Baz" title="Header"><span class="secnum">1.3</span> Header</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#import3" title="Import 3"><span class="secnum">1.3.1</span> Import 3</a></li></ol></li></ol></li><li><span class="item-toggle-none"></span><a href="#" title="Annex"><span class="secnum">A</span> Annex</a></li></ol></div></div><h1 class="version">Draft 1 / September 26, 2015</h1><h1 class="title">Ecmarkup Test Document</h1>
6+
<emu-intro>
57
<h1><span class="secnum"></span>Intro<span class="utils"><span class="anchor"><a href="#">#</a></span></span></h1>
68
<emu-intro>
79
<h1><span class="secnum"></span>Sub Intro<span class="utils"><span class="anchor"><a href="#">#</a></span></span></h1>

test/title.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<pre class=metadata>
2+
title: test title!
3+
status: draft
4+
version: Draft 1
5+
toc: false
6+
</pre>
7+
8+
<p>Some body content</p>

test/title.html.baseline

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!doctype html>
2+
<head><title>test title!</title><meta charset="utf-8"></head><body><h1 class="version">Draft 1 / September 26, 2015</h1><h1 class="title">test title!</h1>
3+
4+
<p>Some body content</p>
5+
</body>

0 commit comments

Comments
 (0)