~cadence/bliz

0bfdc82121851af1bb63e3fa16d4182a66cb39a0 — Cadence Ember 11 months ago bad4215
Allow showing source and true multiline eval
2 files changed, 24 insertions(+), 7 deletions(-)

M src/cgi.fish
M src/process-bliz.fish
M src/cgi.fish => src/cgi.fish +10 -3
@@ 32,6 32,13 @@ end

server_echo "Incoming request for: $req_path"

# check for file source mode
set source_mode false
if string match -q -r -- '.*\?source=1$' $req_path
    set req_path (string match -r -- '^[^?]+' $req_path)
    set source_mode true
end

# revise path to be relative to root
set file_path (echo "$serve_root$req_path")
server_echo "Rewrite to: $file_path"


@@ 91,13 98,13 @@ end

# route request to file
if test -f "$file_path"
    if string match -q -- '*.bliz' $file_path
    if not $source_mode; and string match -q -- '*.bliz' $file_path
        # process bliz script
        fish src/process-bliz.fish $file_path
        fish src/process-bliz.fish $file_path $req_path
        exit
    end
    set -l mime
    if string match -q -- '*.gmi' $file_path
    if string match -q -r -- '^.*\.(gmi)$' $file_path
        set mime text/gemini
    else
        set mime (file -i $file_path)

M src/process-bliz.fish => src/process-bliz.fish +14 -4
@@ 1,6 1,7 @@
#!/usr/bin/env fish

set blizfile $argv[1]
set req_path $argv[2]

source src/config.fish
source src/includes.fish


@@ 11,12 12,21 @@ test -f $blizfile; or exit

set input_mode text # or, script
set input_mode_meta
set script_lines

while read line
    # switch input mode
    if string match -q -- '%%%*' $line
        set input_mode (test $input_mode = text; and echo script; or echo text)
        set input_mode_meta (string sub -s 4 -- $line)
        if test $input_mode = text
            # switch to script buffer mode
            set input_mode script
            set script_lines
            set input_mode_meta (string sub -s 4 -- $line)
        else
            # eval script, then switch to text mode
            eval $script_lines\n
            set input_mode text
        end
        continue
    end
    if test $input_mode = text


@@ 49,7 59,7 @@ while read line
            echo $line
        end
    else
        # process script line
        eval $line
        # buffer script line
        set -a script_lines $line
    end
end < $blizfile