~sircmpwn/wersh

29f36aa5fba3179f9b901a1b32f7ba6093965a52 — Drew DeVault 3 years ago 856b503
Make wersh more POSIXly correct, use *.w
8 files changed, 20 insertions(+), 30 deletions(-)

M README
M example/_config.sh
R example/_templates/{layout.html.sh => layout.html.w}
R example/css/{main.css.sh => main.css.w}
R example/{index.html.sh => index.html.w}
R example/{page-one.html.sh => page-one.html.w}
R example/{page-two.html.sh => page-two.html.w}
M wersh
M README => README +4 -4
@@ 6,10 6,10 @@ USAGE

wersh [-w] [input] [output]

wersh takes files from input/**.sh, converts them into scripts with wersh.awk,
then sources these scripts to produce output files as output/**. Files that
don't match *.sh are copied directly to the output. Any files or directories
that begin with _ are ignored.
wersh takes files from input/**.w, converts them into shell scripts with
wersh.awk, then sources these scripts to produce output files as output/**.
Files that don't match *.w are copied directly to the output. Any files or
directories that begin with _ are ignored.

Files parsed with wersh.awk produce scripts. Any line prefixed with % will be
added to the script, and any line without will be automatically output by the

M example/_config.sh => example/_config.sh +5 -5
@@ 1,22 1,22 @@
pages="page-one.html.sh page-two.html.sh"
pages="page-one.html.w page-two.html.w"

function page_title() {
    case $1 in
        page-one.html.sh)
        page-one.html.w)
            echo "Page one"
            ;;
        page-two.html.sh)
        page-two.html.w)
            echo "Page two"
            ;;
    esac
}

case $input in
    *.html.sh)
    *.html.w)
        preprocessor="hoedown --tables --fenced-code"
        wsource _templates/layout.html.sh
        ;;
    *.scss.sh)
    *.scss.w)
        preprocessor="sassc -s -t compressed"
        ;;
esac

R example/_templates/layout.html.sh => example/_templates/layout.html.w +0 -0

R example/css/main.css.sh => example/css/main.css.w +0 -0

R example/index.html.sh => example/index.html.w +0 -0

R example/page-one.html.sh => example/page-one.html.w +0 -0

R example/page-two.html.sh => example/page-two.html.w +0 -0

M wersh => wersh +11 -21
@@ 6,9 6,13 @@ function usage() {
    exit 1
}

_bin=$(readlink -f $0)
if [ -f ./wersh.awk ]
then
    _wershawk=./wersh.awk
else
    _wershawk=wersh.awk
fi
_single=
_watch=
_n=0
for arg in "$@"
do


@@ 17,10 21,6 @@ do
            _single=t
            _n=$(($_n + 1))
            ;;
        -w)
            _watch=t
            _n=$(($_n + 1))
            ;;
        -*)
            usage
            ;;


@@ 48,7 48,7 @@ function escape() {

function wsource() {
    local _file=$(mktemp)
    $(dirname $_bin)/wersh.awk < "$1" > "$_file"
    ${wershawk} < "$1" > "$_file"
    source "$_file"
    rm "$_file"
}


@@ 58,8 58,8 @@ preprocessor="cat"
if [ -n "$_single" ]
then
    [ $# -ne 4 ] && usage
    root=$(readlink -f $1)
    outputdir=$(readlink -f $2)
    root=$1
    outputdir=$2
    output=$3
    input=$4
    cd $root


@@ 67,16 67,6 @@ then
    wsource $input
    _rendering=t
    printf "%s" "$content" | $preprocessor | render
elif [ -n "$_watch" ]
then
    [ $# -gt 2 ] && usage
    root=${1:-.}
    $0 "$@"
    while inotifywait -qqre close_write "$root"
    do
        sleep 1
        $0 "$@"
    done
else
    [ $# -gt 2 ] && usage
    root=${1:-.}


@@ 86,7 76,7 @@ else
        echo "$_outputdir exists and is not a directory"
        exit 1
    fi
    find "$root" -type f -name "*.sh" -not -path "*/_*/*" -not -name "_*" | \
    find "$root" -type f -name "*.w" -not -path "*/_*/*" -not -name "_*" | \
    while IFS= read -r _input
    do
        _output=$_outputdir${_input#$root}


@@ 95,7 85,7 @@ else
        mkdir -p $(dirname "$_output")
        $0 -s "$root" "$_outputdir" "$_output" "${_input#$root/}" > "$_output"
    done
    find "$root" -type f -not -name "*.sh" -not -path "*/_*/*" -not -name "_*" | \
    find "$root" -type f -not -name "*.w" -not -path "*/_*/*" -not -name "_*" | \
    while IFS= read -r _input
    do
        _output=$_outputdir${_input#$root}