Skip to content

Commit

Permalink
Add scripts for generating specification PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
sake92 committed Feb 6, 2019
1 parent 596c123 commit 7cc6915
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 21 deletions.
26 changes: 26 additions & 0 deletions scripts/generate-spec-pdf.bat
@@ -0,0 +1,26 @@
@ECHO OFF
SETLOCAL EnableDelayedExpansion

REM NOTES:
REM "toc" -> treated just like another page, its location can be changed
REM "--window-status loaded" -> when window.status is set to "loaded", wkhtmltopdf knows js is loaded

SET THIS_SCRIPT_DIR=%~dp0
SET ROOT_DIR=%THIS_SCRIPT_DIR%..
SET SPEC_SRC_DIR=%ROOT_DIR%\spec
SET SPEC_BUILD_DIR=%ROOT_DIR%\build\spec

SET WKHTML_OPTS=--print-media-type --window-status loaded --footer-center [page] --javascript-delay 1000
SET WKHTML_TOC=toc --xsl-style-sheet %SPEC_SRC_DIR%\spec-toc.xslt

SET HTML_FILES=
FOR /F "tokens=*" %%a IN ('dir %SPEC_BUILD_DIR%\*.html /B /O:N ^| findstr /v /i "index.*"') DO (
SET HTML_FILES=!HTML_FILES! %SPEC_BUILD_DIR%\%%a
)
ECHO Making Spec.pdf with HTML files:
ECHO %SPEC_BUILD_DIR%\index.html %HTML_FILES%

echo wkhtmltopdf %WKHTML_OPTS% %SPEC_BUILD_DIR%\index.html %WKHTML_TOC% %HTML_FILES% %SPEC_BUILD_DIR%\Spec.pdf

REM first goes index.html, then TOC, then rest
wkhtmltopdf %WKHTML_OPTS% %SPEC_BUILD_DIR%\index.html %WKHTML_TOC% %HTML_FILES% %SPEC_BUILD_DIR%\Spec.pdf
21 changes: 21 additions & 0 deletions scripts/generate-spec-pdf.sh
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# NOTES:
# "toc" -> treated just like another page, its location can be changed
# "--window-status loaded" -> when window.status is set to "loaded", wkhtmltopdf knows js is loaded

ROOT_DIR=..
SPEC_SRC_DIR=$ROOT_DIR/spec
SPEC_BUILD_DIR=$ROOT_DIR/build/spec

WKHTML_OPTS="--print-media-type --window-status loaded --footer-center [page]"
WKHTML_TOC="toc --xsl-style-sheet $SPEC_SRC_DIR/spec-toc.xslt"

# exclude index.html, prepend SPEC_BUILD_DIR path
HTML_FILES=$(ls $SPEC_BUILD_DIR -I 'index.html' | grep '\.html$' | while read line; do echo "$SPEC_BUILD_DIR/$line"; done)
echo "Making Spec.pdf with HTML files: "
echo $SPEC_BUILD_DIR/index.html $HTML_FILES
# first goes index.html, then TOC, then rest
wkhtmltopdf $WKHTML_OPTS $SPEC_BUILD_DIR/index.html $WKHTML_TOC $HTML_FILES $SPEC_BUILD_DIR/Spec.pdf
19 changes: 19 additions & 0 deletions spec/_includes/table-of-contents.yml
@@ -0,0 +1,19 @@

<div class="hidden-print">

<h1>Table of Contents</h1>

<ol>
{% assign sorted_pages = site.pages | sort:"name" %}
{% for post in sorted_pages %}
<!-- exclude this page from the toc, not sure how to check
whether there is no chapter variable in the page -->
{% if post.chapter >= 0 %}
<li>
<a href="{{site.baseurl}}{{ post.url }}"> {{ post.title }}</a>
</li>
{% endif %}
{% endfor %}
</ol>

</div>
8 changes: 4 additions & 4 deletions spec/_layouts/default.yml
Expand Up @@ -16,8 +16,8 @@
});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/styles/default.min.css">
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/styles/default.min.css">
<!-- need to use include to see value of page.chapter variable -->
<style type="text/css">
{% include numbering.css %}
Expand All @@ -30,7 +30,7 @@
</head>

<body>
<header>
<header class="hidden-print">
<nav id="chapters">
<a href="{{site.baseurl}}/" title="Table of Contents">Scala {{ site.thisScalaVersion }}</a>
<a id="github" href="https://github.com/scala/scala/tree/2.12.x/spec"><img src="public/images/github-logo@2x.png" alt="Edit at GitHub"></a>
Expand All @@ -42,7 +42,7 @@
{% endfor %}
</nav>
</header>
<aside class="left"><nav id="toc"></nav></aside>
<aside class="left hidden-print"><nav id="toc"></nav></aside>

<main id="content">
{% include version-notice.yml %}
Expand Down
5 changes: 4 additions & 1 deletion spec/_layouts/toc.yml
Expand Up @@ -6,11 +6,12 @@
<link rel="icon" type="image/png" href="public/favicon.ico">
<link rel="shortcut icon" type="image/png" href="public/favicon.ico">

<script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<title>{{ page.title }} | Scala {{ site.thisScalaVersion }}</title>

<link rel="stylesheet" type="text/css" href="public/stylesheets/screen.css">
<link rel="stylesheet" type="text/css" href="public/stylesheets/screen-toc.css">
<link rel="stylesheet" type="text/css" media="print" href="public/stylesheets/print.css">
<link rel="stylesheet" type="text/css" href="public/stylesheets/fonts.css">
</head>

Expand All @@ -27,5 +28,7 @@
{% include version-notice.yml %}
{{ content }}
</main>

<script>window.status = "loaded";</script>
</body>
</html>
15 changes: 1 addition & 14 deletions spec/index.md
Expand Up @@ -3,20 +3,7 @@ title: Scala Language Specification
layout: toc
---

# Table of Contents

<ol>
{% assign sorted_pages = site.pages | sort:"name" %}
{% for post in sorted_pages %}
<!-- exclude this page from the toc, not sure how to check
whether there is no chapter variable in the page -->
{% if post.chapter >= 0 %}
<li>
<a href="{{site.baseurl}}{{ post.url }}"> {{ post.title }}</a>
</li>
{% endif %}
{% endfor %}
</ol>
{% include table-of-contents.yml %}

#### Authors and Contributors

Expand Down
2 changes: 2 additions & 0 deletions spec/public/scripts/main.js
Expand Up @@ -47,6 +47,8 @@ hljs.configure({
MathJax.Hub.Queue(function () {
hljs.initHighlighting();
$("pre nobr").addClass("fixws");
// point when all necessary js is done, so PDF to be rendered
window.status = "loaded";
})

$("#chapters a").each(function (index) {
Expand Down
21 changes: 19 additions & 2 deletions spec/public/stylesheets/print.css
Expand Up @@ -5,11 +5,28 @@ body {
margin: 0.5em;
}

.anchor, #navigation, .to_top {
display: none;
.anchor, #navigation, .to_top, .version-notice, .hidden-print {
display: none !important;
}

#content-container {
width: 100%;
float: none;
}

/* no scrollbars, jump to next row.. */
/*.highlight pre code {
overflow: hidden;
white-space: pre-wrap;
}*/

main {
position: relative;
top: 32px;
margin: 0 0 0 0;
padding: 0px 32px;
max-width: none;
min-width: none;
min-height: none;
background-color: #FFF;
}
64 changes: 64 additions & 0 deletions spec/spec-toc.xslt
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:outline="http://wkhtmltopdf.org/outline"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
indent="yes" />
<xsl:template match="outline:outline">
<html>
<head>
<title>Table of Contents</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css">
<xsl:attribute name="href">./public/stylesheets/fonts.css</xsl:attribute>
</link>
<style>
h1 {
text-align: center;
font-size: 20px;
font-family: Heuristica,Georgia,serif;
}
div {border-bottom: 1px dashed rgb(200,200,200);}
span {float: right;}
li {list-style: none;}
ul {
font-size: 20px;
font-family: Heuristica,Georgia,serif;
}
ul ul {font-size: 80%; }
ul {padding-left: 0em;}
ul ul {padding-left: 1em;}
a {text-decoration:none; color: black;}
</style>
</head>
<body>
<h1>Table of Contents</h1>
<ul><xsl:apply-templates select="outline:item/outline:item"/></ul>
</body>
</html>
</xsl:template>
<xsl:template match="outline:item">
<li>
<xsl:if test="@title!=''">
<div>
<a>
<xsl:if test="@link">
<xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute>
</xsl:if>
<xsl:if test="@backLink">
<xsl:attribute name="name"><xsl:value-of select="@backLink"/></xsl:attribute>
</xsl:if>
<xsl:value-of select="@title" />
</a>
<span> <xsl:value-of select="@page" /> </span>
</div>
</xsl:if>
<ul>
<xsl:comment>added to prevent self-closing tags in QtXmlPatterns</xsl:comment>
<xsl:apply-templates select="outline:item"/>
</ul>
</li>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 7cc6915

Please sign in to comment.