Skip to content

Commit aaaee72

Browse files
committed
generate covers during build
1 parent 79aa797 commit aaaee72

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed

Diff for: js/print.js

-26
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ PDF.author = 'Ecma International';
2626
PDF.subject = shortname.innerHTML + ', ' + version.innerHTML;
2727

2828
Prince.registerPostLayoutFunc(() => {
29-
specContainer.parentNode.insertBefore(generateFrontCover(), specContainer);
30-
specContainer.parentNode.insertBefore(generateInsideCover(), specContainer);
31-
3229
/**
3330
* Specific modifications for Ecma standards that don't apply to other
3431
* usages of ecmarkup. In case idk a proposal has the need to publish a PDF.
@@ -64,29 +61,6 @@ function rearrangeTables() {
6461
});
6562
}
6663

67-
function generateFrontCover() {
68-
const frontCover = document.createElement('div');
69-
70-
frontCover.classList.add('full-page-svg');
71-
frontCover.setAttribute('id', 'front-cover');
72-
73-
frontCover.appendChild(shortname);
74-
frontCover.appendChild(version);
75-
frontCover.appendChild(title);
76-
77-
return frontCover;
78-
}
79-
80-
function generateInsideCover() {
81-
const insideCover = document.createElement('div');
82-
83-
insideCover.classList.add('full-page-svg');
84-
insideCover.setAttribute('id', 'inside-cover');
85-
insideCover.innerHTML =
86-
'<p>Ecma International<br />Rue du Rhone 114 CH-1204 Geneva<br/>Tel: +41 22 849 6000<br/>Fax: +41 22 849 6001<br/>Web: https://www.ecma-international.org<br/>Ecma is the registered trademark of Ecma International.</p>';
87-
88-
return insideCover;
89-
}
9064

9165
function generateEcmaCopyrightPage() {
9266
const copyrightNotice = document.createElement('div');

Diff for: src/Spec.ts

+40
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,15 @@ export default class Spec {
404404
throw new Error(`--assets=${this.opts.assets} cannot be used --assets-dir"`);
405405
}
406406

407+
if (this.opts.printable) {
408+
if (this.opts.title == null) {
409+
throw new Error(`--printable requires a title to be set in the metadata"`);
410+
}
411+
if (this.opts.shortname == null) {
412+
throw new Error(`--printable requires a shortname to be set in the metadata"`);
413+
}
414+
}
415+
407416
if (this.opts.multipage) {
408417
this.opts.outfile ??= '';
409418
const type = this.opts.assets ?? 'external';
@@ -582,6 +591,37 @@ export default class Spec {
582591
this.setCharset();
583592
const wrapper = this.buildSpecWrapper();
584593

594+
if (this.opts.printable) {
595+
this.log('Building covers...');
596+
597+
// front cover
598+
const frontCover = document.createElement('div');
599+
600+
frontCover.classList.add('full-page-svg');
601+
frontCover.setAttribute('id', 'front-cover');
602+
603+
const shortNameNode = this.doc.querySelector('h1.shortname');
604+
if (shortNameNode != null) {
605+
frontCover.appendChild(shortNameNode.cloneNode(true));
606+
}
607+
const versionNode = this.doc.querySelector('h1.version');
608+
if (versionNode != null) {
609+
frontCover.appendChild(versionNode.cloneNode(true));
610+
}
611+
// we know title exists because we enforce it in the constructor when using --printable
612+
frontCover.appendChild(this.doc.querySelector('title')!.cloneNode(true));
613+
wrapper.before(frontCover);
614+
615+
// inside cover
616+
const insideCover = document.createElement('div');
617+
618+
insideCover.classList.add('full-page-svg');
619+
insideCover.setAttribute('id', 'inside-cover');
620+
insideCover.innerHTML = '<p>Ecma International<br />Rue du Rhone 114 CH-1204 Geneva<br/>Tel: +41 22 849 6000<br/>Fax: +41 22 849 6001<br/>Web: https://www.ecma-international.org<br/>Ecma is the registered trademark of Ecma International.</p>';
621+
622+
frontCover.after(insideCover);
623+
}
624+
585625
let commonEles: HTMLElement[] = [];
586626
let tocJs = '';
587627
if (this.opts.toc) {

Diff for: test/baselines/generated-reference/clauses.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<head><meta charset="utf-8"></head><body class=" oldtoc"><div id="spec-container">
2+
<head><meta charset="utf-8"><title>Test Doc</title></head><body class=" oldtoc"><div class="full-page-svg" id="front-cover"><title>Test Doc</title></div><div class="full-page-svg" id="inside-cover"><p>Ecma International<br>Rue du Rhone 114 CH-1204 Geneva<br>Tel: +41 22 849 6000<br>Fax: +41 22 849 6001<br>Web: https://www.ecma-international.org<br>Ecma is the registered trademark of Ecma International.</p></div><div id="spec-container"><h1 class="title">Test Doc</h1>
33
<div id="toc"><h2>Contents</h2><ol class="toc"><li><a href="#sec-intro" title="Intro">Intro</a><ol class="toc"><li><a href="#sec-intro2" title="Sub Intro">Sub Intro</a></li></ol></li><li><a href="#sec-clause" title="Clause Foo(a, b)"><span class="secnum">1</span> Clause Foo(<var>a</var>, <var>b</var>)</a><ol class="toc"><li><a href="#Foo" title="Sub Clause"><span class="secnum">1.1</span> Sub Clause</a></li></ol></li><li><a href="#sec-number" title="Explicit number"><span class="secnum">7</span> Explicit number</a><ol class="toc"><li><a href="#sec-number1" title="Automatic number inside explicit number"><span class="secnum">7.1</span> Automatic number inside explicit number</a></li><li><a href="#sec-number2" title="Nested explicit number"><span class="secnum">7.4</span> Nested explicit number</a></li><li><a href="#sec-number3" title="Automatic number after explicit number"><span class="secnum">7.5</span> Automatic number after explicit number</a></li><li><a href="#sec-number-nested" title="Multi-step explicit numbers"><span class="secnum">7.6</span> Multi-step explicit numbers</a></li></ol></li><li><a href="#sec-annex" title="Annex"><span class="secnum">Annex A <span class="annex-kind">(informative)</span></span> Annex</a><ol class="toc"><li><a href="#sec-annex2" title="Sub-annex"><span class="secnum">A.1</span> Sub-annex</a></li></ol></li></ol></div><emu-intro id="sec-intro">
44
<h1>Intro</h1>
55
<emu-intro id="sec-intro2">

Diff for: test/baselines/generated-reference/shortname.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<li><span>Jump to search box</span><code>/</code></li>
88
<li><span>Toggle pinning of the current clause</span><code>p</code></li>
99
<li><span>Jump to <i>n</i>th pin</span><code>1-9</code></li>
10-
</ul></div><div id="spec-container"><h1 class="shortname">Draft ECMA-000</h1><h1 class="version">Draft 1 / September 26, 2015</h1><h1 class="title">test title!</h1>
10+
</ul></div><div id="spec-container"><h1 class="shortname"><span class="status">Draft</span> ECMA-000</h1><h1 class="version">Draft 1 / September 26, 2015</h1><h1 class="title">test title!</h1>
1111

1212
<p>Some body content</p>
1313
</div></body>

Diff for: test/baselines/sources/clauses.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<pre class=metadata>
22
printable: true
3+
title: Test Doc
4+
shortname: Test
35
copyright: false
46
assets: none
57
</pre>

0 commit comments

Comments
 (0)