Skip to content

Commit

Permalink
PDF spec generation script fixups, & add to Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue committed Mar 6, 2019
1 parent 8a4ecf6 commit 95f764e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -53,9 +53,11 @@ jobs:
- ruby -v
- bundler --version
- bundle install
- sudo apt-get install wkhtmltopdf
script:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then (cd admin && ./init.sh); fi'
- bundle exec jekyll build -s spec/ -d build/spec
- ./scripts/generate-spec-pdf.sh
after_success:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then ./scripts/travis-publish-spec.sh; fi'

Expand Down
23 changes: 19 additions & 4 deletions scripts/generate-spec-pdf.sh 100644 → 100755
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

set -e
set -v

# 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
Expand All @@ -8,15 +11,27 @@ THIS_SCRIPT_DIR=$(dirname $0)
ROOT_DIR=$THIS_SCRIPT_DIR/..
SPEC_SRC_DIR=$ROOT_DIR/spec
SPEC_BUILD_DIR=$ROOT_DIR/build/spec
PDF=$SPEC_BUILD_DIR/spec.pdf

mkdir -p $SPEC_BUILD_DIR

WKHTML_OPTS='--print-media-type --window-status loaded --footer-center [page] --javascript-delay 1000 --footer-font-name "Luxi Sans"'
WKHTML_OPTS='--print-media-type --window-status loaded --footer-center [page] --javascript-delay 1000 --footer-font-name "Luxi Sans" --load-error-handling ignore'
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)
HTML_FILES=$(ls $SPEC_BUILD_DIR | grep -vx 'index.html' | grep '\.html$' | while read line; do echo "$SPEC_BUILD_DIR/$line"; done)
echo "Making Spec.pdf with HTML files: "
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
rm -f $PDF
wkhtmltopdf $WKHTML_OPTS $SPEC_BUILD_DIR/index.html $WKHTML_TOC $HTML_FILES $PDF || true
# the '|| true' thing is because we get:
# Error: Failed to load http:/, with network status code 3 and http status code 0 - Host not found
# Warning: Failed loading page http: (ignored)
# as long we have `--load-error-handling ignore` we still get a PDF, but we also get a nonzero exit code
# fail if we didn't get a PDF file out
if [ ! -f $PDF ] ; then exit 1 ; fi

0 comments on commit 95f764e

Please sign in to comment.