diff --git a/scripts/make-images.sh b/scripts/make-images.sh index 2bf6e61..adfbb76 100644 --- a/scripts/make-images.sh +++ b/scripts/make-images.sh @@ -229,7 +229,7 @@ templateVars(){ # cache the vars... if [ ${TEMPLATE_INDEX[$1]+_} ] ; then TEMPLATE_INDEX[$1]=$(cat "$1" \ - | grep -o '\${[A-Z0-9]\+}' \ + | grep -o '\${[A-Z0-9_]\+}' \ | sed 's/\${\(.*\)}/\1/g' \ | sort) fi @@ -242,6 +242,30 @@ indexTemplates(){ templateVars "${tpl}" > /dev/null done } +# this depends on $img and $txt arrays being defined... +populateTemplate(){ + local tpl="$1" + local slots=( $(templateSlots "${tpl}") ) + local text=$(cat "${tpl}") + + local var + local i=0 + local t=0 + # XXX can we do this in a single pass??? + for var in ${slots[@]} ; do + local name=${var//[0-9]/} + if [ ${name} = "IMAGE" ] ; then + local val=${img[$i]} + i=$(( n + 1 )) + else + local val=${txt[$t]} + t=$(( n + 1 )) + fi + text=$(echo -e "${text}" | \ + sed "s/\${${var}}/${val}/g") + done + echo -e "${text}" +} getTemplate(){ local SPREAD=$1