Moved template functions/procedures into their own file
In particular, this makes resume-default available to raw (-i) modetpl
parent
80b466694b
commit
f776c8f918
|
@ -0,0 +1,51 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Common template vars and functions/procedures
|
||||
#
|
||||
# Copyright (C) 2012 Mike Gerwitz
|
||||
#
|
||||
# This file is part of repo2html.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# #
|
||||
|
||||
# default template path (the former is exported so that templates themselves may
|
||||
# make use of default templates)
|
||||
declare -xr path_default_tpl=./tpl
|
||||
declare -xr path_tpl="${1:-$path_default_tpl}"
|
||||
|
||||
resolv-template()
|
||||
{
|
||||
name="$1"
|
||||
[ -x "$path_tpl/$name" ] \
|
||||
&& echo "$path_tpl/$name" \
|
||||
|| echo "$path_default_tpl/$name"
|
||||
}
|
||||
apply-template()
|
||||
{
|
||||
$( resolv-template "$1" )
|
||||
}
|
||||
exec-template()
|
||||
{
|
||||
exec $( resolv-template "$1" )
|
||||
}
|
||||
|
||||
# allows custom templates to invoke the default template (say, to set/override
|
||||
# options)
|
||||
resume-default()
|
||||
{
|
||||
exec "$path_default_tpl/$1"
|
||||
}
|
||||
|
||||
export -f resolv-template apply-template exec-template resume-default
|
31
processor
31
processor
|
@ -26,33 +26,7 @@ declare -xr path_out="${2?Missing output path}"
|
|||
# provide default message formatter if necessary
|
||||
msgfmt="${msgfmt:-./msgfmt}"
|
||||
|
||||
# default template path (the former is exported so that templates themselves may
|
||||
# make use of default templates)
|
||||
declare -xr path_default_tpl=./tpl
|
||||
declare -xr path_tpl="${path_tpl:-$path_default_tpl}"
|
||||
|
||||
resolv-template()
|
||||
{
|
||||
name="$1"
|
||||
[ -x "$path_tpl/$name" ] \
|
||||
&& echo "$path_tpl/$name" \
|
||||
|| echo "$path_default_tpl/$name"
|
||||
}
|
||||
apply-template()
|
||||
{
|
||||
$( resolv-template "$1" )
|
||||
}
|
||||
exec-template()
|
||||
{
|
||||
exec $( resolv-template "$1" )
|
||||
}
|
||||
|
||||
# allows custom templates to invoke the default template (say, to set/override
|
||||
# options)
|
||||
resume-default()
|
||||
{
|
||||
exec "$path_default_tpl/$1"
|
||||
}
|
||||
source include/tpl "$path_tpl"
|
||||
|
||||
|
||||
# generates output filename
|
||||
|
@ -146,6 +120,5 @@ do-index()
|
|||
}
|
||||
|
||||
# let the template finish
|
||||
export -f do-index resolv-template apply-template exec-template resume-default \
|
||||
outfgen
|
||||
export -f do-index outfgen
|
||||
exec-template index
|
||||
|
|
|
@ -67,8 +67,7 @@ cwarn()
|
|||
|
||||
# these configuration opts must be read first since they will be used to load
|
||||
# configuration options that must be overridden by future command-line options
|
||||
path_tpl_default=./tpl
|
||||
path_tpl=$path_tpl_default
|
||||
path_tpl=
|
||||
while true; do
|
||||
getopts :T: opt
|
||||
[ -z "$OPTARG" ] && break
|
||||
|
@ -80,6 +79,8 @@ while true; do
|
|||
done
|
||||
OPTIND=0
|
||||
|
||||
source include/tpl "$path_tpl"
|
||||
|
||||
# if a custom template path was given, attempt to load the configuration
|
||||
cfgpath="$path_tpl/.config"
|
||||
[ -n "$path_tpl" -a -e "$cfgpath" ] && {
|
||||
|
|
Loading…
Reference in New Issue