diff --git a/pkgs/output-template/output-template.fnl b/pkgs/output-template/output-template.fnl index 4d26fe6..186c8ae 100644 --- a/pkgs/output-template/output-template.fnl +++ b/pkgs/output-template/output-template.fnl @@ -35,8 +35,11 @@ }] (string.gsub text delim (fn [x] - (assert ((load (.. "return " x) x :t myenv)) - (string.format "missing value for %q" x)))))) + (let [chunk (if (= (x:sub 1 1) ";") + (x:sub 2) + (.. "return " x))] + (assert ((load chunk x :t myenv)) + (string.format "missing value for %q" x))))))) (fn run [] (let [[opening closing] arg @@ -49,6 +52,11 @@ (expect= (pick-values 1 (substitute "{{ json_quote(\"o'reilly\") }}" "{{" "}}")) "\"o'reilly\"") + (expect= (pick-values 1 (substitute "{{; local a=9; return a }}" "{{" "}}")) "9") + + ;; "globals" set in one interpolation are available in subsequent ones + (expect= (pick-values 1 (substitute "{{; a=42; return a }} {{ a and 999 or 0 }}" "{{" "}}")) "42 999") + (fn slurp [name] (with-open [f (assert (io.open name))] (f:read "*a"))) (expect=