Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(template): Fix newline option description #467

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading