+ basic template engine
parent
bb8805d786
commit
c53cb884ef
2
http.sh
2
http.sh
|
@ -32,7 +32,7 @@ if [[ $error == true ]]; then
|
|||
fi
|
||||
|
||||
if [[ $1 == "init" ]]; then # will get replaced with proper parameter parsing in 1.0
|
||||
mkdir -p "${cfg[namespace]}/${cfg[root]}" "${cfg[namespace]}/workers/example" "${cfg[namespace]}/views"
|
||||
mkdir -p "${cfg[namespace]}/${cfg[root]}" "${cfg[namespace]}/workers/example" "${cfg[namespace]}/views" "${cfg[namespace]}/templates"
|
||||
touch "${cfg[namespace]}/config.sh" "${cfg[namespace]}/workers/example/control"
|
||||
cat <<LauraIsCute > "${cfg[namespace]}/config.sh"
|
||||
## app config
|
||||
|
|
|
@ -39,6 +39,5 @@ function post_dump() {
|
|||
|
||||
# html_encode(string)
|
||||
function html_encode() {
|
||||
#echo -n "$1" | xxd -ps | sed -E 's/.{2}/\&#x&;/g'
|
||||
echo -n "$1" | sed 's/</\</g;s/>/\>/g;s/%/\%/g;s/\//\//g;s/\\/\\/g;s/'"'"'/\'/g;s/"/\"/g;s/`/\`/g;s/?/\?/g'
|
||||
sed 's/</\</g;s/>/\>/g;s/%/\%/g;s/\//\//g;s/\\/\\/g;s/'"'"'/\'/g;s/"/\"/g;s/`/\`/g;s/?/\?/g' <<< "$1"
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ source src/misc.sh
|
|||
source src/account.sh
|
||||
source src/mail.sh
|
||||
source src/route.sh
|
||||
source src/template.sh
|
||||
[[ -f "${cfg[namespace]}/config.sh" ]] && source "${cfg[namespace]}/config.sh"
|
||||
|
||||
declare -A r # current request / response
|
||||
|
@ -17,7 +18,7 @@ declare -A params # parsed router data
|
|||
r[status]=210 # Mommy always said that I was special
|
||||
post_length=0
|
||||
|
||||
while read param; do
|
||||
while read -r param; do
|
||||
param_l="${param,,}" # lowercase
|
||||
name=''
|
||||
value=''
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
# template.sh - basic templating engine
|
||||
|
||||
# render(array, template_file)
|
||||
function render() {
|
||||
local template="$(cat "$2")"
|
||||
local -n ref=$1
|
||||
for key in ${!ref[@]}; do
|
||||
local value="$(html_encode "${ref[$key]}" | sed -E 's/\&/<2F>UwU<77>/g')"
|
||||
template="$(sed -E 's/\{\{\.'"$key"'\}\}/'"$value"'/g' <<< "$template")"
|
||||
done
|
||||
|
||||
sed -E 's/<2F>UwU<77>/\&/g' <<< "$template"
|
||||
}
|
Loading…
Reference in New Issue