Skip to content

Commit

Permalink
docs(template): Fix newline option description (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
RiskoZoSlovenska authored Feb 15, 2024
1 parent 636e66b commit 675a0c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lua/pl/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/test-template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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")
Expand Down

0 comments on commit 675a0c2

Please sign in to comment.