fakestache-ssg

[Archived] A static site generator in Bash 4.
Log | Files | Refs | Submodules | README

commit 1a8a963550567a06a757e89ef9f879ead0fb5e11
parent 699373d2d1e2419b21cbedeaf49399f624ee5049
Author: Hugo Soucy <hugo.soucy@savoirfairelinux.com>
Date:   Fri, 10 Mar 2017 20:07:24 -0500

Enhance the parse_yaml function.

Diffstat:
Mfunctions/parse_yaml | 15++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/functions/parse_yaml b/functions/parse_yaml @@ -4,16 +4,21 @@ parse_yaml() { local prefix=$2 - local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') + local s + local w + local fs + s='[[:space:]]*' + w='[a-zA-Z0-9_]*' + fs="$(echo @|tr @ '\034')" sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \ - -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | - awk -F$fs '{ + -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" | + awk -F"$fs" '{ indent = length($1)/2; vname[indent] = $2; for (i in vname) {if (i > indent) {delete vname[i]}} if (length($3) > 0) { vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")} - printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3); + printf("%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, $3); } - }' + }' | sed 's/_=/+=/g' }