From 9db33ae48daa49df2a6dc36a46599d345f72a53a Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Sat, 26 Sep 2015 16:34:21 -0700 Subject: [PATCH] Add many document options. --- css/elements.css | 14 +++++++ lib/Spec.js | 74 +++++++++++++++++++++++++++++++++++- package.json | 2 +- spec/index.html | 21 +++++++--- test/date.html | 8 ++++ test/date.html.baseline | 6 +++ test/shortname.html | 9 +++++ test/shortname.html.baseline | 5 +++ test/test.html | 8 +++- test/test.html.baseline | 6 ++- test/title.html | 8 ++++ test/title.html.baseline | 5 +++ 12 files changed, 156 insertions(+), 10 deletions(-) create mode 100644 test/date.html create mode 100644 test/date.html.baseline create mode 100644 test/shortname.html create mode 100644 test/shortname.html.baseline create mode 100644 test/title.html create mode 100644 test/title.html.baseline diff --git a/css/elements.css b/css/elements.css index 26a7b841..cc7989ec 100644 --- a/css/elements.css +++ b/css/elements.css @@ -206,6 +206,20 @@ emu-gprose { font-family: Helvetica, Arial, sans-serif; } +h1.shortname { + color: #f60; + font-size: 1.5em; + margin: 0; +} +h1.version { + color: #f60; + font-size: 1.5em; + margin: 0; +} +h1.title { + margin-top: 0; + color: #f60; +} h1, h2, h3, h4, h5, h6 { position: relative; } diff --git a/lib/Spec.js b/lib/Spec.js index bdf24204..d449d929 100644 --- a/lib/Spec.js +++ b/lib/Spec.js @@ -27,6 +27,9 @@ const clauseTextNodesUnder = utils.textNodesUnder(NO_CLAUSE_AUTOLINK); const NO_ALG_AUTOLINK = ['PRE', 'CODE', 'EMU-XREF']; const algTextNodesUnder = utils.textNodesUnder(NO_ALG_AUTOLINK); +const DRAFT_DATE_FORMAT = { year: 'numeric', month: 'long', day: 'numeric' }; +const STANDARD_DATE_FORMAT = { year: 'numeric', month: 'long' }; + module.exports = class Spec { constructor (rootPath, fetch, doc, opts) { opts = opts || {}; @@ -110,6 +113,7 @@ module.exports = class Spec { build() { let p = this.buildAll('emu-import', Import) + .then(this.buildBoilerplate.bind(this)) .then(this.loadES6Biblio.bind(this)) .then(this.loadBiblios.bind(this)) .then(this.buildAll.bind(this, 'emu-clause, emu-intro, emu-annex', Clause)) @@ -196,7 +200,7 @@ module.exports = class Spec { exportBiblio() { if (!this.opts.location) { - utils.logWarning('no spec location specified. Biblio not generated. Try --location or setting the location in the document\'s metadata block.'); + utils.logWarning('No spec location specified. Biblio not generated. Try --location or setting the location in the document\'s metadata block.'); return {}; } @@ -224,6 +228,60 @@ module.exports = class Spec { } } + buildBoilerplate() { + const status = this.opts.status || 'proposal'; + const version = this.opts.version; + const title = this.opts.title; + const shortname = this.opts.shortname; + const stage = this.opts.stage === undefined ? null : String(this.opts.stage); + + // no title boilerplate generated if title not specified + if (!title) return; + + // title + if (title && !this._updateBySelector('title', title)) { + const titleElem = this.doc.createElement('title'); + titleElem.innerHTML = title; + this.doc.head.appendChild(titleElem); + + const h1 = this.doc.createElement('h1'); + h1.setAttribute('class', 'title'); + h1.innerHTML = title; + this.doc.body.insertBefore(h1, this.doc.body.firstChild); + } + + // version string, ala 6th Edition July 2016 or Draft 10 / September 26, 2015 + let versionText = ''; + if (version) { + versionText += version + ' / '; + } else if (status === 'proposal' && stage) { + versionText += 'Stage ' + stage + ' Draft / '; + } + + const defaultDateFormat = status === 'standard' ? STANDARD_DATE_FORMAT : DRAFT_DATE_FORMAT; + const date = this.opts.date || new Intl.DateTimeFormat('en-US', defaultDateFormat).format(new Date()); + versionText += date; + + if (!this._updateBySelector('h1.version', versionText)) { + const h1 = this.doc.createElement('h1'); + h1.setAttribute('class', 'version'); + h1.innerHTML = versionText; + this.doc.body.insertBefore(h1, this.doc.body.firstChild); + } + + // shortname and status, ala 'Draft ECMA-262 + if (shortname) { + const shortnameText = status.charAt(0).toUpperCase() + status.slice(1) + ' ' + shortname; + + if (!this._updateBySelector('h1.shortname', shortnameText)) { + const h1 = this.doc.createElement('h1'); + h1.setAttribute('class', 'shortname'); + h1.innerHTML = shortnameText; + this.doc.body.insertBefore(h1, this.doc.body.firstChild); + } + } + } + autolink() { this._log('Autolinking terms and abstract ops...'); const termlinkmap = {}; @@ -294,6 +352,20 @@ module.exports = class Spec { if (!this.opts.verbose) return; utils.logVerbose(str); } + + _updateBySelector(selector, contents) { + const elem = this.doc.querySelector(selector); + if (elem && elem.textContent.trim().length > 0) { + return true; + } + + if (elem) { + elem.innerHTML = contents; + return true; + } + + return false; + } }; diff --git a/package.json b/package.json index 7b4cd92e..58ab6162 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ecmarkup", - "version": "2.2.0", + "version": "2.3.0", "description": "Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.", "main": "lib/ecmarkup.js", "scripts": { diff --git a/spec/index.html b/spec/index.html index d6dd8801..ffc473d2 100644 --- a/spec/index.html +++ b/spec/index.html @@ -5,7 +5,6 @@
-title: Ecmarkup Documentation
 repository: https://github.com/bterlson/ecmarkup
 
@@ -37,9 +36,9 @@

Getting Started

Useful Options

-

These options can be passed in via the command line or specified in the front-matter of your document.

- - Listing of available options +

Build options and document options can be passed in via the command line or specified in the front-matter of your document.

+ + Build options @@ -47,6 +46,18 @@

Useful Options

+
OptionDescription
watchRebuild when files change
biblioEmit a biblio file to the specified location
cssEmit the Ecmarkup CSS file to the specified location
jsEmit the Ecmarkup JS file to the specified location
+
+ + + Document options + + + + + + + @@ -119,7 +130,7 @@

Editorial Conventions

Metadata

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.

To add metadata to your document, use yaml syntax inside a `<pre class=metadata>` element somewhere in the root of your document.

-

All of the command line options can be provided in the metadata block. See the table above for a list (or consult `--help`).

+

All of the command line options can be provided in the metadata block. See and for a list (or consult `--help`).

Example document with metadata


 <pre class=metadata>
diff --git a/test/date.html b/test/date.html
new file mode 100644
index 00000000..b6e703b2
--- /dev/null
+++ b/test/date.html
@@ -0,0 +1,8 @@
+
+
+

Some body content

+ diff --git a/test/date.html.baseline b/test/date.html.baseline new file mode 100644 index 00000000..5df44dc6 --- /dev/null +++ b/test/date.html.baseline @@ -0,0 +1,6 @@ + +test title!

July, 2014

test title!

+ +

Some body content

+ + \ No newline at end of file diff --git a/test/shortname.html b/test/shortname.html new file mode 100644 index 00000000..660c0e7c --- /dev/null +++ b/test/shortname.html @@ -0,0 +1,9 @@ + + +

Some body content

diff --git a/test/shortname.html.baseline b/test/shortname.html.baseline new file mode 100644 index 00000000..e5da0019 --- /dev/null +++ b/test/shortname.html.baseline @@ -0,0 +1,5 @@ + +test title!

Draft ECMA-000

Draft 1 / September 26, 2015

test title!

+ +

Some body content

+ \ No newline at end of file diff --git a/test/test.html b/test/test.html index 5f3dab7d..81649cd0 100644 --- a/test/test.html +++ b/test/test.html @@ -1,6 +1,12 @@ - + + +

Intro

diff --git a/test/test.html.baseline b/test/test.html.baseline index ff9f908a..19f31a85 100644 --- a/test/test.html.baseline +++ b/test/test.html.baseline @@ -1,7 +1,9 @@ - - + + +Ecmarkup Test Document

Draft 1 / September 26, 2015

Ecmarkup Test Document

+

Intro#

Sub Intro#

diff --git a/test/title.html b/test/title.html new file mode 100644 index 00000000..c242774d --- /dev/null +++ b/test/title.html @@ -0,0 +1,8 @@ + + +

Some body content

diff --git a/test/title.html.baseline b/test/title.html.baseline new file mode 100644 index 00000000..de6e262b --- /dev/null +++ b/test/title.html.baseline @@ -0,0 +1,5 @@ + +test title!

Draft 1 / September 26, 2015

test title!

+ +

Some body content

+ \ No newline at end of file
OptionDescription
titleTitle of specification, for example `ECMAScript 2016` or `Async Functions`.
statusStatus of specification. Can be `proposal`, `draft`, or `standard`. Default is `proposal`.
stageStage of proposal. Must be a number if provided, but is optional. Sets `version` to `Stage N Draft`, but can be overridden.
versionVersion of specification, for example `6th Edition` or `Draft 1`. Optional.
shortnameShortname of specification, for example `ECMA-262` or `ECMA-402`.
locationHref of this specification. Use in conjunction with the biblio file to enable external specs to reference this one.
tocEmit table of contents. Boolean, default true.
old-tocEmit the old style of table of contents. Boolean, default false.