diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-05 16:10:26 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-05 16:10:26 +0300 |
| commit | 0351784f043be5adc549d246758f1369248d56c3 (patch) | |
| tree | 03be9181ada396ef9b2a6c2f4995da4b8f26180e | |
| parent | 1136d9e696b726eb8a2a84a9ef0860b87c9e742e (diff) | |
Decompose template rendering orchestration
| -rwxr-xr-x | bin/photoalbum | 42 | ||||
| -rwxr-xr-x | src/photoalbum.sh | 42 |
2 files changed, 56 insertions, 28 deletions
diff --git a/bin/photoalbum b/bin/photoalbum index 2aa28ac..fd3160d 100755 --- a/bin/photoalbum +++ b/bin/photoalbum @@ -609,9 +609,23 @@ prepare_template_render_vars() { fi } -template() { +validate_template_render_request() { + local -r template_name="$1"; shift + local -r context_name="$1"; shift + local -r template_path="$TEMPLATE_DIR/$template_name.tmpl" + + if [ ! -r "$template_path" ]; then + config_error "template file $template_path must be readable" + return 1 + fi + + validate_template_context "$template_name" "$context_name" +} + +render_template() { local -r template_name="$1"; shift local -r html="$1"; shift + local -r context_name="$1"; shift local -r template_path="$TEMPLATE_DIR/$template_name.tmpl" local dist_html local render_animation_class_html @@ -644,28 +658,28 @@ template() { local render_title_html local render_view_next_html local render_view_prev_html - # shellcheck disable=SC2034 - local -A render_context=() - - parse_template_context "$template_name" render_context "$@" - - if [ ! -r "$template_path" ]; then - config_error "template file $template_path must be readable" - return 1 - fi - validate_template_context "$template_name" render_context - - render_html_dir=$(template_context_value render_context html_dir) + render_html_dir=$(template_context_value "$context_name" html_dir) dist_html="$DIST_DIR/$render_html_dir" log_info "Generating $(_display_path "$dist_html")/$html" mkdir -p "$dist_html" - prepare_template_render_vars render_context + prepare_template_render_vars "$context_name" source_template_file "$template_path" "$dist_html/$html" } +template() { + local -r template_name="$1"; shift + local -r html="$1"; shift + # shellcheck disable=SC2034 + local -A render_context=() + + parse_template_context "$template_name" render_context "$@" + validate_template_render_request "$template_name" render_context + render_template "$template_name" "$html" render_context +} + cleanphotos() { local basename local photo diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 2d23b5b..26befbe 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -609,9 +609,23 @@ prepare_template_render_vars() { fi } -template() { +validate_template_render_request() { + local -r template_name="$1"; shift + local -r context_name="$1"; shift + local -r template_path="$TEMPLATE_DIR/$template_name.tmpl" + + if [ ! -r "$template_path" ]; then + config_error "template file $template_path must be readable" + return 1 + fi + + validate_template_context "$template_name" "$context_name" +} + +render_template() { local -r template_name="$1"; shift local -r html="$1"; shift + local -r context_name="$1"; shift local -r template_path="$TEMPLATE_DIR/$template_name.tmpl" local dist_html local render_animation_class_html @@ -644,28 +658,28 @@ template() { local render_title_html local render_view_next_html local render_view_prev_html - # shellcheck disable=SC2034 - local -A render_context=() - - parse_template_context "$template_name" render_context "$@" - - if [ ! -r "$template_path" ]; then - config_error "template file $template_path must be readable" - return 1 - fi - validate_template_context "$template_name" render_context - - render_html_dir=$(template_context_value render_context html_dir) + render_html_dir=$(template_context_value "$context_name" html_dir) dist_html="$DIST_DIR/$render_html_dir" log_info "Generating $(_display_path "$dist_html")/$html" mkdir -p "$dist_html" - prepare_template_render_vars render_context + prepare_template_render_vars "$context_name" source_template_file "$template_path" "$dist_html/$html" } +template() { + local -r template_name="$1"; shift + local -r html="$1"; shift + # shellcheck disable=SC2034 + local -A render_context=() + + parse_template_context "$template_name" render_context "$@" + validate_template_render_request "$template_name" render_context + render_template "$template_name" "$html" render_context +} + cleanphotos() { local basename local photo |
