-
Notifications
You must be signed in to change notification settings - Fork 2
/
render.sh
executable file
·184 lines (169 loc) · 4.16 KB
/
render.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
# defaults
inside=true
insize=0.25
outside=true
outsize=2.25
border=\'\'
tinting=both
altdef=tx1
altalpha=15
bold=true
output=echo
tx2=
# usage
usage() {
echo ""
echo "Usage: $0 <ooxml-template>"
echo ""
echo "Options:"
echo " -h, --help show help"
echo " -l, --light-mode disable bold for 1st/last/total rows and cols (default is enabled)"
echo " -i, --inbdr-size inside borders size (in points, default is ${insize})"
echo " --no-inbdr disable inside borders styles (default is enabled)"
echo " -o, --outbdr-size outside borders size (in points, default is ${outsize})"
echo " --no-outbdr disable outside borders styles (default is enabled)"
echo " -b, --bdr-color border color (default is current rendering color, has to be tx1/dk1/...)"
echo " -t, --tinting alternate row tinting with current color: only/both/off (default is ${tinting})"
echo " -a, --alt-alpha alternate row tinting colors transparency percentage (default is ${altalpha}%, 0 to disable banding)"
echo " -c, --alt-color alternate row tinting color for tx1 rows (default is ${altdef})"
echo " -2, --tx2 enable tx2 based style rendering (default is off)"
echo " -x, --output output mode. possible values are"
echo " * echo (default)"
echo " * copy for clipboard"
echo " * filename of PPTX file to update in-place (make a backup first!)"
echo ""
echo "Example:"
echo " $0 --output=presentation.pptx -a 20 -l template.xml"
exit 2
}
# check args
needs_arg() {
if [ -z "$OPTARG" ]; then
echo ""
echo "Argument missing for --$o option";
echo "Use --$o=... syntax";
exit 2;
fi
}
# parse arguments
while getopts "hlb:i:jo:pa:c:t:2x:-:" o; do
if [ "$o" = "-" ]; then # long option: reformulate OPT and OPTARG
o="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#$o}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "${o}" in
h | help)
usage
;;
l | light-mode)
bold=false
;;
b | bdr-color)
needs_arg
border=${OPTARG}
;;
i | inbdr-size)
needs_arg
insize=${OPTARG}
;;
no-inbdr)
inside=false
;;
o | outbdr-size)
needs_arg
outsize=${OPTARG}
;;
no-outbdr)
outside=false
;;
a | alt-alpha)
needs_arg
altalpha=${OPTARG}
;;
c | alt-color)
needs_arg
altdef=${OPTARG}
;;
t | tinting)
needs_arg
tinting=${OPTARG}
;;
2 | tx2)
tx2=tx2
;;
x | output)
needs_arg
output=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
# parameters
template=$1
if [ -z "${template}" ]; then
usage
fi
# check
if [ "${output}" != "echo" ] && [ "${output}" != "copy" ]; then
if [ ! -f "${output}" ]; then
echo "File ${output} does not exist!"
exit 1
fi
fi
# data source
ds=$(mktemp)
: > ${ds}
echo "bold: ${bold}" >> ${ds}
echo "borderColor: ${border}" >> ${ds}
# inner
echo "innerBorder:" >> ${ds}
echo " enable: ${inside}" >> ${ds}
echo " size: ${insize}" >> ${ds}
echo "outerBorder:" >> ${ds}
echo " enable: ${outside}" >> ${ds}
echo " size: ${outsize}" >> ${ds}
# alternate will force tinting
if [ "$altalpha" == "0" ]; then
tinting=off
fi
# tinting
echo "tinting: ${tinting}" >> ${ds}
# color names
names=$(echo "tx1 ${tx2} accent1 accent2 accent3 accent4 accent5 accent6" | sed 's/ / /g')
# colors
echo "colors: ${names}" >> ${ds}
echo "names: ${names}" >> ${ds}
echo "altDefault: ${altdef}" >> ${ds}
echo "altAlpha: ${altalpha}" >> ${ds}
# do it
#cat ${ds}
xml=$(gomplate -d data=file://${ds}?type=application/yaml -f ${template} | sed '/^[[:space:]]*$/d')
rm ${ds}
# check clipboard
if [ "${output}" == "copy" ]; then
if ! hash pbcopy 2>/dev/null; then
output=echo
fi
fi
# output
if [ "${output}" == "echo" ]; then
echo "${xml}"
elif [ "${output}" == "copy" ]; then
echo "${xml}" | pbcopy
echo "Content copied to clipboard!"
else
tmp=$(mktemp -d)
output=$(realpath "${output}")
unzip -q -d ${tmp} "${output}"
echo "${xml}" > ${tmp}/ppt/tableStyles.xml
cd ${tmp}
zip -q -f -r "${output}" *
cd - > /dev/null
rm -rf ${tmp}
echo "Done!"
fi