mirror of
https://github.com/TangentFoxy/etlua.git
synced 2025-07-28 02:52:17 +00:00
allow renderer to be provided
This commit is contained in:
11
etlua.lua
11
etlua.lua
@@ -316,15 +316,18 @@ do
|
|||||||
setfenv(fn, combined_env)
|
setfenv(fn, combined_env)
|
||||||
return fn(buffer, #buffer, tostring, concat, html_escape)
|
return fn(buffer, #buffer, tostring, concat, html_escape)
|
||||||
end,
|
end,
|
||||||
compile_to_lua = function(self, str)
|
compile_to_lua = function(self, str, ...)
|
||||||
local success, err = self:parse(str)
|
local success, err = self:parse(str)
|
||||||
if not (success) then
|
if not (success) then
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
return self:chunks_to_lua()
|
return self:chunks_to_lua(...)
|
||||||
end,
|
end,
|
||||||
chunks_to_lua = function(self)
|
chunks_to_lua = function(self, renderer_cls)
|
||||||
local r = Renderer()
|
if renderer_cls == nil then
|
||||||
|
renderer_cls = Renderer
|
||||||
|
end
|
||||||
|
local r = renderer_cls()
|
||||||
r:header()
|
r:header()
|
||||||
local _list_0 = self.chunks
|
local _list_0 = self.chunks
|
||||||
for _index_0 = 1, #_list_0 do
|
for _index_0 = 1, #_list_0 do
|
||||||
|
@@ -69,7 +69,6 @@ class Renderer
|
|||||||
@push "_b[_b_i] = ", ...
|
@push "_b[_b_i] = ", ...
|
||||||
@push "\n" if ...
|
@push "\n" if ...
|
||||||
|
|
||||||
|
|
||||||
class Parser
|
class Parser
|
||||||
open_tag: "<%"
|
open_tag: "<%"
|
||||||
close_tag: "%>"
|
close_tag: "%>"
|
||||||
@@ -230,14 +229,14 @@ class Parser
|
|||||||
setfenv fn, combined_env
|
setfenv fn, combined_env
|
||||||
fn buffer, #buffer, tostring, concat, html_escape
|
fn buffer, #buffer, tostring, concat, html_escape
|
||||||
|
|
||||||
compile_to_lua: (str) =>
|
compile_to_lua: (str, ...) =>
|
||||||
success, err = @parse str
|
success, err = @parse str
|
||||||
return nil, err unless success
|
return nil, err unless success
|
||||||
@chunks_to_lua!
|
@chunks_to_lua ...
|
||||||
|
|
||||||
-- generates the code of the template
|
-- generates the code of the template
|
||||||
chunks_to_lua: =>
|
chunks_to_lua: (renderer_cls=Renderer) =>
|
||||||
r = Renderer!
|
r = renderer_cls!
|
||||||
r\header!
|
r\header!
|
||||||
|
|
||||||
for chunk in *@chunks
|
for chunk in *@chunks
|
||||||
|
Reference in New Issue
Block a user