complete testing for website_generatorlib
parent
da080a9465
commit
c61affe5e7
|
@ -13,9 +13,15 @@
|
||||||
##
|
##
|
||||||
prog="$0"
|
prog="$0"
|
||||||
me=${HELP:-`basename "$prog"`}
|
me=${HELP:-`basename "$prog"`}
|
||||||
rootdir=$(dirname $(realpath $0))
|
rootdir=$(dirname $(realpath ${BASH_SOURCE[0]}))
|
||||||
source ${rootdir}/lib/utils.sh
|
source ${rootdir}/lib/utils.sh
|
||||||
source ${rootdir}/lib/website_generatorlib.sh
|
source ${rootdir}/lib/website_generatorlib.sh
|
||||||
|
|
||||||
|
# Renders the markup for a pass audio file
|
||||||
|
# Requires a file in $WXRX_WEB_DIR/templates/pass_audio.template
|
||||||
|
# @param file path to render
|
||||||
|
# @output markup to stdout
|
||||||
|
# @side-effect produces an audio file in public webroot
|
||||||
function render_pass_audio() {
|
function render_pass_audio() {
|
||||||
file=${1}
|
file=${1}
|
||||||
path=$(publish_audio ${file})
|
path=$(publish_audio ${file})
|
||||||
|
@ -33,6 +39,14 @@ function render_pass_image() {
|
||||||
template_subst CAPTION "${caption}"
|
template_subst CAPTION "${caption}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function render_index_item() {
|
||||||
|
url=${1}
|
||||||
|
title=${2}
|
||||||
|
thumbnail=${3}
|
||||||
|
cat ${WXRX_WEB_TEMPLATES}/item.template |
|
||||||
|
url="${url}" title="${title}" thumbnail="${thumbnail}" envsubst
|
||||||
|
}
|
||||||
|
|
||||||
function generate_manifest_thumbnail() {
|
function generate_manifest_thumbnail() {
|
||||||
#TODO: generate an actual thumbnail and move it to the web dir
|
#TODO: generate an actual thumbnail and move it to the web dir
|
||||||
# skip if file exists, unless forced
|
# skip if file exists, unless forced
|
||||||
|
|
|
@ -4,20 +4,19 @@ WXRX_WEB_DIR=${WXRX_WEB_DIR:=~/wxrx/web}
|
||||||
WXRX_WEB_TEMPLATES=${WXRX_WEB_TEMPLATES:="${WXRX_WEB_DIR}/templates"}
|
WXRX_WEB_TEMPLATES=${WXRX_WEB_TEMPLATES:="${WXRX_WEB_DIR}/templates"}
|
||||||
WXRX_WEB_PUBDIR=${WXRX_WEB_PUBDIR:="${WXRX_WEB_DIR}/public"}
|
WXRX_WEB_PUBDIR=${WXRX_WEB_PUBDIR:="${WXRX_WEB_DIR}/public"}
|
||||||
|
|
||||||
|
# Determine the path of a template
|
||||||
function render_index_item() {
|
# @param name
|
||||||
url=${1}
|
# @output path to template
|
||||||
title=${2}
|
# @return non-zero if path does not exist
|
||||||
thumbnail=${3}
|
|
||||||
cat ${WXRX_WEB_TEMPLATES}/item.template |
|
|
||||||
url="${url}" title="${title}" thumbnail="${thumbnail}" envsubst
|
|
||||||
}
|
|
||||||
|
|
||||||
function template_path() {
|
function template_path() {
|
||||||
echo ${WXRX_WEB_TEMPLATES}/${1}.template
|
file=${WXRX_WEB_TEMPLATES}/${1}.template
|
||||||
|
if [ -f "$file" ]; then
|
||||||
|
echo $file
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
|
||||||
# Replaces every "{{$1}}" in stdin with $2
|
# Replaces every "{{$1}}" in stdin with $2
|
||||||
# @param VAR
|
# @param VAR
|
||||||
# @param replacement
|
# @param replacement
|
||||||
|
|
|
@ -4,6 +4,32 @@ me=${HELP:-$(basename "$prog")}
|
||||||
rootdir=$(dirname $(dirname $(realpath ${BASH_SOURCE[0]})))
|
rootdir=$(dirname $(dirname $(realpath ${BASH_SOURCE[0]})))
|
||||||
unit=${rootdir}/lib/website_generatorlib.sh
|
unit=${rootdir}/lib/website_generatorlib.sh
|
||||||
|
|
||||||
|
test_source_unit() {
|
||||||
|
WXRX_WEB_DIR=${SHUNIT_TMPDIR}/test-source
|
||||||
|
WXRX_WEB_TEMPLATES=${SHUNIT_TMPDIR}/test-source/foo
|
||||||
|
WXRX_WEB_PUBDIR=${SHUNIT_TMPDIR}/test-source/bar
|
||||||
|
source ${unit}
|
||||||
|
|
||||||
|
assertEquals "${SHUNIT_TMPDIR}/test-source" "${WXRX_WEB_DIR}"
|
||||||
|
assertEquals "${SHUNIT_TMPDIR}/test-source/foo" "${WXRX_WEB_TEMPLATES}"
|
||||||
|
assertEquals "${SHUNIT_TMPDIR}/test-source/bar" "${WXRX_WEB_PUBDIR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_template_path() {
|
||||||
|
WXRX_WEB_TEMPLATES=${SHUNIT_TMPDIR}/template_path
|
||||||
|
mkdir -p ${WXRX_WEB_TEMPLATES}
|
||||||
|
source ${unit}
|
||||||
|
|
||||||
|
touch ${WXRX_WEB_TEMPLATES}/foo.template
|
||||||
|
|
||||||
|
assertEquals "${WXRX_WEB_TEMPLATES}/foo.template" "$(template_path foo)"
|
||||||
|
|
||||||
|
template_path 'bar'
|
||||||
|
retval=$?
|
||||||
|
assertFalse "missing templates should have non-zero exit status" "$retval"
|
||||||
|
assertEquals "" "$(template_path bar)"
|
||||||
|
}
|
||||||
|
|
||||||
test_template_subst() {
|
test_template_subst() {
|
||||||
source ${unit}
|
source ${unit}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue