Skip to content

Commit

Permalink
Merge pull request #6 from 3scale/partial-filesystem
Browse files Browse the repository at this point in the history
fix passing filesystem when rendering partials
  • Loading branch information
mikz authored Oct 8, 2018
2 parents 8783931 + eee3a67 commit ce79ebf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/liquid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2407,7 +2407,7 @@ function Interpreter:visit_Partial( node )
end
end
local interpreter = Interpreter:new(parser)
local result = interpreter:interpret(context, self.filterset, self.resourcelimit)
local result = interpreter:interpret(context, self.filterset, self.resourcelimit, self.filesystem)
context:destroyframe()
self.resourcelimit:check_length(#result)
return result
Expand Down
29 changes: 21 additions & 8 deletions t/interpreter.t
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,36 @@ GET /t
local Interpreter = Liquid.Interpreter
local FileSystem = Liquid.FileSystem
local InterpreterContext = Liquid.InterpreterContext
local var = {["aa"] = "-----", ["bb"] = { ["cc"] = "======" } }
local document = "{% if true %} abc{{ aa }}defg {% endif %} {% include 'foo' for bb %} {% include 'foo' %} "
local function mock_template()
return [[{% if true %} 12345{{ cc }}6789 {% endif %}]]
local var = {
["aa"] = "-----",
["bb"] = { ["cc"] = "======" },
}
local document = [[
{%- if true -%}
abc{{ aa }}defg
{%- endif %}
{%- include 'foo' for bb -%}
{%- include 'foo' -%}
{%- include 'bar' -%}
]]
local filesystem = {
foo = [[{% if true %} 12345{{ cc }}6789 {% endif %}]],
bar = [[{% include 'recursive' %}]],
recursive = [[bar]],
}
local function mock_template(name)
return filesystem[name]
end
FileSystem.get = mock_template
local lexer = Lexer:new(document)
local parser = Parser:new(lexer)
local interpreter = Interpreter:new(parser)
ngx.say( interpreter:interpret( InterpreterContext:new(var) ) )
ngx.say( interpreter:interpret( InterpreterContext:new(var), nil, nil, FileSystem:new(mock_template) ) )
}
}
--- request
GET /t
--- response_body
abc-----defg 12345======6789 123456789
abc-----defg 12345======6789 123456789 bar
--- no_error_log
[error]
Expand Down

0 comments on commit ce79ebf

Please sign in to comment.