diff --git a/lua/pl/template.lua b/lua/pl/template.lua index 3bc7ee6f..bb99a5ce 100644 --- a/lua/pl/template.lua +++ b/lua/pl/template.lua @@ -115,7 +115,7 @@ function template.substitute(str,env) escape = rawget(env,"_escape"), inline_escape = rawget(env,"_inline_escape"), inline_brackets = rawget(env,"_brackets"), - newline = nil, + newline = false, debug = rawget(env,"_debug") }) if not t then return t, err end @@ -159,7 +159,7 @@ end -- * `escape`: character marking Lua lines, default is '#' -- * `inline_escape`: character marking inline Lua expression, default is '$'. -- * `inline_brackets`: bracket pair that wraps inline Lua expressions, default is '()'. --- * `newline`: string to replace newline characters, default is `nil` (not replacing newlines). +-- * `newline`: if truthy, newlines will be stripped from text in the template. Default is `false`. -- * `debug`: if truthy, the generated source code will be retained within the compiled template object, default is `nil`. -- -- @string str the template string diff --git a/tests/test-template.lua b/tests/test-template.lua index eb3470b7..a879da7c 100644 --- a/tests/test-template.lua +++ b/tests/test-template.lua @@ -184,7 +184,7 @@ local my_env = { ipairs = ipairs, T = {'one','two','three'} } -local t, err = template.compile(tmpl, { debug = true, newline = "" }) +local t, err = template.compile(tmpl, { debug = true, newline = true }) local res, err, code = t:render(my_env) --print(res, err, code) asserteq(res, [[some list: ONE,TWO,THREE]]) @@ -197,7 +197,7 @@ local tmpl = [[ header: $("hello" * 10) ]] -local t, err = template.compile(tmpl, { debug = true, newline = "" }) +local t, err = template.compile(tmpl, { debug = true, newline = true }) local res, err, code = t:render() --print(res, err, code) assert(res == nil, "expected nil here because of the runtime error") @@ -213,7 +213,7 @@ local tmpl = [[ header: $(myParam) ]] -local t, err = template.compile(tmpl, { debug = true, newline = "" }) +local t, err = template.compile(tmpl, { debug = true, newline = true }) local myParam = {} local res, err, code = t:render( {myParam = myParam } ) -- insert a table --print(res, err, code) @@ -232,7 +232,7 @@ local my_env = { ipairs = ipairs, T = {'one','two','three'} } -local t, err, code = template.compile(tmpl, { debug = true, newline = "" }) +local t, err, code = template.compile(tmpl, { debug = true, newline = true }) --print(t, err, code) assert(t==nil, "expected t to be nil here because of the syntax error") asserteq(type(err), "string")