Skip to content

Commit

Permalink
Add copyright boilerplate generation for proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
bterlson committed Sep 28, 2015
1 parent cba78a9 commit 818e2c9
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 27 deletions.
1 change: 1 addition & 0 deletions boilerplate/proposal-copyright.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>© !YEAR! !CONTRIBUTORS!</p>
52 changes: 39 additions & 13 deletions lib/Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ module.exports = class Spec {
if (!this.opts.date) {
this.opts.date = new Date();
}

if (this.opts.stage) {
this.opts.stage = String(this.opts.stage);
} else if (this.opts.status === 'proposal') {
this.opts.stage = '0';
} else {
this.opts.stage = null;
}
}

buildAll(selector, Builder, opts) {
Expand Down Expand Up @@ -246,11 +254,16 @@ module.exports = class Spec {
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);
const stage = this.opts.stage;

if (this.opts.copyright && (status === 'draft' || status === 'standard')) {
this.buildCopyrightBoilerplate();
if (this.opts.copyright) {
if (status !== 'draft' && status !== 'standard' && !this.opts.contributors) {
utils.logWarning('Contributors not specified, skipping copyright boilerplate. Specify contributors in your frontmatter metadata.');
} else {
this.buildCopyrightBoilerplate();
}
}

// no title boilerplate generated if title not specified
if (!title) return;

Expand Down Expand Up @@ -305,16 +318,34 @@ module.exports = class Spec {
copyright = fs.readFileSync('boilerplate/draft-copyright.html', 'utf8');
} else if (this.opts.status === 'standard') {
copyright = fs.readFileSync('boilerplate/standard-copyright.html', 'utf8');
} else {
copyright = fs.readFileSync('boilerplate/proposal-copyright.html', 'utf8');
}

copyright = copyright.replace(/!YEAR!/g, this.opts.date.getFullYear());

if (this.opts.contributors) {
copyright = copyright.replace(/!CONTRIBUTORS!/g, this.opts.contributors);
}

const softwareLicense = fs.readFileSync('boilerplate/software-license.html', 'utf8');

let lastAnnex = this.doc.querySelector('body > emu-annex:last-child');
let lastClause = this.doc.querySelector('body > emu-clause:last-child');
const last = lastAnnex || lastClause;
let copyrightClause = this.doc.querySelector('.copyright-and-software-license');
if (!copyrightClause) {
let lastAnnex = this.doc.querySelector('body > emu-annex:last-child');
let lastClause = this.doc.querySelector('body > emu-clause:last-child');
const last = lastAnnex || lastClause;

copyrightClause = this.doc.createElement('emu-annex');
copyrightClause.setAttribute('id', 'sec-copyright-and-software-license');

if (last) {
last.parentNode.insertBefore(copyrightClause, last.previousSibling);
} else {
this.doc.body.appendChild(copyrightClause);
}
}

const copyrightClause = this.doc.createElement('emu-annex');
copyrightClause.setAttribute('id', 'sec-copyright-and-software-license');
copyrightClause.innerHTML = `
<h1>Copyright &amp; Software License</h1>
<h2>Copyright Notice</h2>
Expand All @@ -323,11 +354,6 @@ module.exports = class Spec {
${softwareLicense}
`;

if (last) {
last.parentNode.insertBefore(copyrightClause, last.previousSibling);
} else {
this.doc.body.appendChild(copyrightClause);
}
}

autolink() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ecmarkup",
"version": "2.3.0",
"version": "2.4.0",
"description": "Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.",
"main": "lib/ecmarkup.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ <h1>Useful Options</h1>
<tr><td>shortname</td><td>Shortname of specification, for example `ECMA-262` or `ECMA-402`.</td></tr>
<tr><td>location</td><td>URL of this specification. Use in conjunction with the biblio file to enable external specs to reference this one.</td></tr>
<tr><td>copyright</td><td>Emit copyright and software license information. Boolean, default true.</td></tr>
<tr><td>contributors</td><td>Contributors to this specification, ie. those who own the copyright. If your proposal includes text from any Ecma specification, you should include "Ecma International" in this list.</td></tr>
<tr><td>toc</td><td>Emit table of contents. Boolean, default true.</td></tr>
<tr><td>old-toc</td><td>Emit the old style of table of contents. Boolean, default false.</td></tr>
</table>
Expand Down
5 changes: 4 additions & 1 deletion test/algorithms.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
<emu-biblio href="./algorithmsBiblio.json"></emu-biblio>
<emu-alg>
1. Can call abstract operations in this spec: Internal();
Expand Down
2 changes: 1 addition & 1 deletion test/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Promise = require('bluebird');

const build = require('../lib/ecmarkup').build;

const doc = '<!doctype html><pre class=metadata>toc: false</pre><emu-clause><h1>hi</h1></emu-clause>';
const doc = '<!doctype html><pre class=metadata>toc: false\ncopyright: false</pre><emu-clause><h1>hi</h1></emu-clause>';
const out = '<!doctype html>\n<head><meta charset="utf-8"></head><body><emu-clause><h1><span class="secnum">1</span>hi<span class="utils"><span class="anchor"><a href="#">#</a></span></span></h1></emu-clause></body>';
function fetch(file) {
if (file.match(/\.json$/)) {
Expand Down
5 changes: 4 additions & 1 deletion test/charset-absent.html
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
5 changes: 4 additions & 1 deletion test/charset-present.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<meta charset="ascii">
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>

5 changes: 4 additions & 1 deletion test/clauses.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<pre class=metadata>oldToc: true</pre>
<pre class=metadata>
oldToc: true
copyright: false
</pre>
<emu-intro>
<h1>Intro</h1>
<emu-intro>
Expand Down
5 changes: 4 additions & 1 deletion test/dfn.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
<emu-intro id="sec-intro">
<h1>Intro</h1>
<p>Forward references to dfn work.</p>
Expand Down
5 changes: 4 additions & 1 deletion test/eqn.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<link rel=stylesheet href="./css/elements.css">
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
<emu-clause id="sec-example">
<h1>Header</h1>
<p>Can refer to eqns inside paragraph text via autolinking: DateValue.</p>
Expand Down
5 changes: 4 additions & 1 deletion test/escaping.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
<emu-clause id="blah">
<h1>blah</h1>
<p>U+200C (ZERO WIDTH NON-JOINER) is abbreviated "&lt;ZWNJ&gt;"</p>
Expand Down
5 changes: 4 additions & 1 deletion test/example.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
<p>Examples outside of clauses aren't processed specially.</p>
<emu-example>
This is an example.
Expand Down
5 changes: 4 additions & 1 deletion test/figure.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
<link rel="stylesheet" href="css/elements.css">
<emu-figure id="figure-1">
this is a figure!
Expand Down
5 changes: 4 additions & 1 deletion test/imports.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
<emu-import href="imports/import1.html"></emu-import>
<emu-import href="imports/import2.html"></emu-import>

Expand Down
5 changes: 4 additions & 1 deletion test/notes.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
<emu-note>This is a note. Since it is outside a clause it is unstyled.</emu-note>

<emu-clause id="sec-this">
Expand Down
7 changes: 7 additions & 0 deletions test/proposal-copyright.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<pre class=metadata>
title: test title!
toc: false
date: 2014-09-26
contributors: Brian Terlson, Ecma International
</pre>

22 changes: 22 additions & 0 deletions test/proposal-copyright.html.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<head><title>test title!</title><meta charset="utf-8"></head><body><h1 class="version">Stage 0 Draft / September 26, 2014</h1><h1 class="title">test title!</h1>

<emu-annex id="sec-copyright-and-software-license">
<h1><span class="secnum">A</span>Copyright &amp; Software License<span class="utils"><span class="anchor"><a href="#sec-copyright-and-software-license">#</a></span></span></h1>
<h2>Copyright Notice</h2>
<p>© 2014 Brian Terlson, Ecma International</p>

<h2>Software License</h2>
<p>All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT http://www.ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.</p>

<p>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</p>

<ol>
<li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>
<li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.</li>
<li>Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.</li>
</ol>

<p>THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>

</emu-annex></body>
5 changes: 4 additions & 1 deletion test/xref.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<pre class=metadata>toc: false</pre>
<pre class=metadata>
toc: false
copyright: false
</pre>
<emu-biblio href="./xrefTestBiblio.json"></emu-biblio>
<emu-clause id="sec-clause-id">
<h1>Clause Title</h1>
Expand Down

0 comments on commit 818e2c9

Please sign in to comment.