Created
March 22, 2018 13:40
-
-
Save jdvivar/b82654bc1ce4945233cdb16a7e11af14 to your computer and use it in GitHub Desktop.
Script to compile Sagepay XML/XSLT2 into HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Sagepay templates script file | |
# Function to show help with the use of this script | |
help() | |
{ | |
echo "compile Compiles XML/XSLT to HTML" | |
echo "bundle Create bundle to send to Sagepay" | |
echo "help Show this help" | |
echo "" | |
} | |
# Check wether saxon is available in the system | |
check_saxon() | |
{ | |
saxon -? &>/dev/null | |
if [ $? -ne 0 ] | |
then | |
echo "Please install saxon first. Try:" | |
echo "brew install saxon" | |
echo "More info on http://www.saxonica.com/documentation/index.html" | |
exit | |
fi | |
} | |
clean() | |
{ | |
echo "Cleaning up ..." | |
rm -rf ./HTML | |
rm sagepay_bundle.tar.gz | |
} | |
# Files lists, they should be matching | |
xml_list=( | |
'authorisation' | |
'card_authentication' | |
'card_details' | |
'error' | |
) | |
xslt_list=( | |
'authorisation_low' | |
'card_authentication_low' | |
'card_details_low' | |
'error' | |
) | |
# Compile files into html | |
compile() | |
{ | |
n=0 | |
while [ "${xslt_list[n]}" != "" ] | |
do | |
echo "Compiling ${xml_list[n]} ..." | |
saxon -s:XML/${xml_list[n]}.xml -xsl:XSLT/${xslt_list[n]}.xslt -o:HTML/${xml_list[n]}.html | |
n=$[n + 1] | |
done | |
} | |
# Bundle files into a compressed tar | |
bundle() | |
{ | |
echo "Bundling ..." | |
tar czf sagepay_bundle.tar.gz images XSLT | |
if [ $? -eq 0 ] | |
then | |
echo "Done. Look for sagepay_bundle.tar.gz" | |
fi | |
} | |
# Create boilerplate page with all iframes | |
boilerplate() | |
{ | |
echo "Creating boilerplate ..." | |
php boilerplate.php > HTML/index.html | |
open HTML/index.html | |
} | |
# If no arguments are given | |
if [ $# -eq 0 ] | |
then | |
echo "You didn't supply any commands. Use as follows:" | |
help | |
exit | |
fi | |
# Case statement for argument 1, other arguments are ignored | |
case $1 in | |
"compile" ) check_saxon | |
clean | |
compile | |
boilerplate | |
exit | |
;; | |
"bundle" ) clean | |
bundle | |
exit | |
;; | |
"help" ) help | |
exit | |
;; | |
* ) echo "You didn't supply a valid command. Use as follows:" | |
help | |
exit | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment