complete testing for website_generatorlib

master
Ken Barbour 2022-02-12 15:41:55 -05:00
parent da080a9465
commit c61affe5e7
3 changed files with 51 additions and 12 deletions

View File

@ -13,9 +13,15 @@
##
prog="$0"
me=${HELP:-`basename "$prog"`}
rootdir=$(dirname $(realpath $0))
rootdir=$(dirname $(realpath ${BASH_SOURCE[0]}))
source ${rootdir}/lib/utils.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() {
file=${1}
path=$(publish_audio ${file})
@ -33,6 +39,14 @@ function render_pass_image() {
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() {
#TODO: generate an actual thumbnail and move it to the web dir
# skip if file exists, unless forced

View File

@ -4,20 +4,19 @@ WXRX_WEB_DIR=${WXRX_WEB_DIR:=~/wxrx/web}
WXRX_WEB_TEMPLATES=${WXRX_WEB_TEMPLATES:="${WXRX_WEB_DIR}/templates"}
WXRX_WEB_PUBDIR=${WXRX_WEB_PUBDIR:="${WXRX_WEB_DIR}/public"}
function render_index_item() {
url=${1}
title=${2}
thumbnail=${3}
cat ${WXRX_WEB_TEMPLATES}/item.template |
url="${url}" title="${title}" thumbnail="${thumbnail}" envsubst
}
# Determine the path of a template
# @param name
# @output path to template
# @return non-zero if path does not exist
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
# @param VAR
# @param replacement

View File

@ -4,6 +4,32 @@ me=${HELP:-$(basename "$prog")}
rootdir=$(dirname $(dirname $(realpath ${BASH_SOURCE[0]})))
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() {
source ${unit}