output-template: allow splicing statements instead of expression
if the text inside the delimiters begins with ; (a semicolon) then the rest of it is expected to be one or more Lua statements. It needs to say `return "foo"` to interpolate anything, as there is no implicit return of the value of the last statement
This commit is contained in:
parent
2c7a16d792
commit
8c39b47cae
@ -35,8 +35,11 @@
|
|||||||
}]
|
}]
|
||||||
(string.gsub text delim
|
(string.gsub text delim
|
||||||
(fn [x]
|
(fn [x]
|
||||||
(assert ((load (.. "return " x) x :t myenv))
|
(let [chunk (if (= (x:sub 1 1) ";")
|
||||||
(string.format "missing value for %q" x))))))
|
(x:sub 2)
|
||||||
|
(.. "return " x))]
|
||||||
|
(assert ((load chunk x :t myenv))
|
||||||
|
(string.format "missing value for %q" x)))))))
|
||||||
|
|
||||||
(fn run []
|
(fn run []
|
||||||
(let [[opening closing] arg
|
(let [[opening closing] arg
|
||||||
@ -49,6 +52,11 @@
|
|||||||
(expect= (pick-values 1 (substitute "{{ json_quote(\"o'reilly\") }}" "{{" "}}"))
|
(expect= (pick-values 1 (substitute "{{ json_quote(\"o'reilly\") }}" "{{" "}}"))
|
||||||
"\"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]
|
(fn slurp [name]
|
||||||
(with-open [f (assert (io.open name))] (f:read "*a")))
|
(with-open [f (assert (io.open name))] (f:read "*a")))
|
||||||
(expect=
|
(expect=
|
||||||
|
Loading…
Reference in New Issue
Block a user