refactor variable replacements into own function
This commit is contained in:
parent
93c88daf78
commit
f39ea95089
22
mige.sh
22
mige.sh
@ -32,6 +32,18 @@ read_options() {
|
||||
done
|
||||
}
|
||||
|
||||
replace_variables() {
|
||||
while read -r variable; do
|
||||
if [[ $variable =~ $REGEX_VARIABLE ]]; then
|
||||
local variable_name=${BASH_REMATCH[1]}
|
||||
local variable_value=${BASH_REMATCH[2]}
|
||||
sed -i "s/\$$variable_name/$variable_value/g;/$variable/d" $1
|
||||
else
|
||||
echo -e "\e[38;5;208mWarning: could not match '$variable' as a variable assignment.\e[0m"
|
||||
fi
|
||||
done < <(grep -P $REGEX_VARIABLE $1)
|
||||
}
|
||||
|
||||
replace_embeds () {
|
||||
while read match; do
|
||||
IFS=$SEPARATOR_EMBED read -ra parts <<< "$match"
|
||||
@ -58,16 +70,8 @@ process_file () {
|
||||
mkdir -p $( dirname "$1" | sed "s/$sourcediresc\/$DIR_CONTENT/$sourcediresc\/$DIR_DIST/" )
|
||||
local file_output=$( echo "$1" | sed "s/$sourcediresc\/$DIR_CONTENT/$sourcediresc\/$DIR_DIST/" )
|
||||
cat "$SOURCEDIR/$TEMPLATE_HEADER" "$1" "$SOURCEDIR/$TEMPLATE_FOOTER" > $file_output
|
||||
while read -r variable; do
|
||||
if [[ $variable =~ $REGEX_VARIABLE ]]; then
|
||||
local variable_name=${BASH_REMATCH[1]}
|
||||
local variable_value=${BASH_REMATCH[2]}
|
||||
sed -i "s/\$$variable_name/$variable_value/g;/$variable/d" $file_output
|
||||
else
|
||||
echo -e "\e[38;5;208mWarning: could not match '$variable' as a variable assignment.\e[0m"
|
||||
fi
|
||||
done < <(grep -P $REGEX_VARIABLE $file_output)
|
||||
|
||||
replace_variables $file_output
|
||||
replace_embeds $file_output
|
||||
|
||||
timep=$((($(date +%s%N) - $timep)/1000000))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user