From 90896bcfeb4e55c78d9a15700a6a4580f0df6365 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 5 Aug 2021 20:44:25 +0200 Subject: enable modularization of html files --- build.sh | 41 +++++++---------------------------------- copyright | 2 +- process_html_file.sh | 33 +++++++++++++++++++++++++++++++++ shell_utils.sh | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 35 deletions(-) create mode 100755 process_html_file.sh create mode 100644 shell_utils.sh diff --git a/build.sh b/build.sh index 60c1863..d940176 100755 --- a/build.sh +++ b/build.sh @@ -3,36 +3,7 @@ # Copyright (C) 2021 Wojtek Kosior # Redistribution terms are gathered in the `copyright' file. -ENDL=" -" - -errcho() { - echo "$@" >&2 -} - -map_set_instr() { - echo "$1__$2='$3'" -} - -map_set() { - eval "$(map_set_instr "$@")" -} - -map_get() { - eval "echo \"\$$1__$2\"" -} - -map_del_instr() { - echo "unset $1__$2" -} - -map_del() { - eval "$(map_del_instr "$@")" -} - -sanitize() { - echo "$1" | tr /.- _ -} +. ./shell_utils.sh handle_export_line() { if [ "x$1" = "xEXPORTS_START" ]; then @@ -259,11 +230,13 @@ s^_BGSCRIPTS_^$BGSCRIPTS^ s^_CONTENTSCRIPTS_^$CONTENTSCRIPTS^" \ < manifest.json > $BUILDDIR/manifest.json - sed "s^_POPUPSCRIPTS_^$POPUPSCRIPTS^" \ - < html/display-panel.html > $BUILDDIR/html/display-panel.html + ./process_html_file.sh html/display-panel.html | + sed "s^_POPUPSCRIPTS_^$POPUPSCRIPTS^" \ + > $BUILDDIR/html/display-panel.html - sed "s^_OPTIONSSCRIPTS_^$OPTIONSSCRIPTS^" \ - < html/options.html > $BUILDDIR/html/options.html + ./process_html_file.sh html/options.html | + sed "s^_OPTIONSSCRIPTS_^$OPTIONSSCRIPTS^" \ + > $BUILDDIR/html/options.html for FILE in $SCRIPTS; do FILEKEY=$(sanitize "$FILE") diff --git a/copyright b/copyright index 36340e4..96de092 100644 --- a/copyright +++ b/copyright @@ -6,7 +6,7 @@ Files: * Copyright: 2021 Wojtek Kosior License: GPL-3+-javascript or Alicense-1.0 -Files: re-generate_icons.sh build.sh +Files: *.sh Copyright: 2021 Wojtek Kosior 2021 jahoti License: CC0 diff --git a/process_html_file.sh b/process_html_file.sh new file mode 100755 index 0000000..1ed0295 --- /dev/null +++ b/process_html_file.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# Copyright (C) 2021 Wojtek Kosior +# Redistribution terms are gathered in the `copyright' file. + +# Call like: +# ./process_html_file.sh html/options.html + +. ./shell_utils.sh + +FILE="$1" +FILEKEY=$(sanitize "$FILE") + +if [ "x$(map_get HTML_FILENAMES $FILEKEY)" = "xyes" ]; then + errcho "import loop on $FILE" + exit 1 +fi + +map_set_export HTML_FILENAMES $FILEKEY yes + +awk '\ +!/^[\t\r ]*[\t\r ]*$/{ + print $0; +} +/^[\t\r ]*[\t\r ]*$/{ + indent = substr($0, 1, index($0, "<") - 1); + command = "./process_html_file.sh " $2; + while (command | getline) { + print indent $0; + } + if (close(command) != 0) + exit 1; +}' < "$FILE" diff --git a/shell_utils.sh b/shell_utils.sh new file mode 100644 index 0000000..95e0d4e --- /dev/null +++ b/shell_utils.sh @@ -0,0 +1,39 @@ +# Copyright (C) 2021 Wojtek Kosior +# Redistribution terms are gathered in the `copyright' file. + +# This file is meant to be sourced in sh. + +ENDL=" +" + +errcho() { + echo "$@" >&2 +} + +map_set_instr() { + echo "$1__$2='$3'" +} + +map_set() { + eval "$(map_set_instr "$@")" +} + +map_set_export() { + eval "export $(map_set_instr "$@")" +} + +map_get() { + eval "echo \"\$$1__$2\"" +} + +map_del_instr() { + echo "unset $1__$2" +} + +map_del() { + eval "$(map_del_instr "$@")" +} + +sanitize() { + echo "$1" | tr /.- _ +} -- cgit v1.2.3