mostly done with new dynamic teplate generation...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-03-06 02:08:47 +03:00
parent c21fb0bbf8
commit f5c1c8c968

View File

@ -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