This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_standalone.sh
executable file
·74 lines (65 loc) · 2.39 KB
/
create_standalone.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
##
# Generate a standalone version of the flaskfiller web application. A
# standalone version does not need the internet to run, all assets are URL
# encoded embedded in the generated HTML file.
#
# Usage:
#
# ./create_standalone.sh [non-standalone file or language code]
#
# If optional argument "non-standalone file or language code" is "nl", the
# Dutch version of the standalone flaskfiller web application is generated.
# If it is "en" the English version is generated. Any other value is treated
# as a file name of a non-standalone version of flaskfiller to be converted
# to a standalone version. This allows you to create custom flaskfiller
# applications and convert them to a standalone version.
#
# If no argument is supplied, the English "flaskfiller.html" file is used as
# a template.
#
# Examples:
#
# To generate the full FlaskFiller application in Dutch:
#
# ./create_standalone.sh nl
#
# To generate a standalone version of a custom FlaskFiller application named
# "graph_only.html":
#
# ./create_standalone.sh graph_only.html
#
# Dependencies:
#
# pandoc [http://pandoc.org/] is used to generated the standalone version
# with all the URL encoded assets embedded in it. See pandoc's website on
# how to install and use pandoc.
##
TEMPLATE=${1:-flaskfiller.html}
# Two default templates are defined
if [[ "$TEMPLATE" == "nl" ]]; then
TEMPLATE="flessenvuller.html"
else
if [[ "$TEMPLATE" == "en" ]]; then
TEMPLATE="flaskfiller.html"
fi
fi
OUT_FILE="standalone_$TEMPLATE"
# Because pandoc converts all assets to 64 bit encoded text, the source code
# of flaskfiller becomes unreadable. To prevent this from happening—it is free
# software after all—, the template is copied, the inclusion of flaskfiller.js
# is replaced by a recognizable string (READABLE_SOURCE_CODE), and after
# running pandoc, that string is replaced by the contents of flaskfiller.js.
# This makes flaskfiller's code readable in the standalone version as well!
READABLE_TEMPLATE="READABLE_$TEMPLATE"
sed -e 's|<script src="flaskfiller.js" charset="utf-8"></script>|<script>\nREADABLE_SOURCE_CODE\n</script>|' $TEMPLATE > $READABLE_TEMPLATE
echo "" | pandoc \
--from markdown \
--to html \
--template $READABLE_TEMPLATE \
--standalone \
--self-contained \
-o $OUT_FILE
rm $READABLE_TEMPLATE
sed -e '/READABLE_SOURCE_CODE/ {' -e 'r flaskfiller.js' -e 'd' -e '}' -i $OUT_FILE