Skip to content

Commit ce79ebf

Browse files
authored
Merge pull request #6 from 3scale/partial-filesystem
fix passing filesystem when rendering partials
2 parents 8783931 + eee3a67 commit ce79ebf

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

lib/liquid.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2407,7 +2407,7 @@ function Interpreter:visit_Partial( node )
24072407
end
24082408
end
24092409
local interpreter = Interpreter:new(parser)
2410-
local result = interpreter:interpret(context, self.filterset, self.resourcelimit)
2410+
local result = interpreter:interpret(context, self.filterset, self.resourcelimit, self.filesystem)
24112411
context:destroyframe()
24122412
self.resourcelimit:check_length(#result)
24132413
return result

t/interpreter.t

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,23 +341,36 @@ GET /t
341341
local Interpreter = Liquid.Interpreter
342342
local FileSystem = Liquid.FileSystem
343343
local InterpreterContext = Liquid.InterpreterContext
344-
local var = {["aa"] = "-----", ["bb"] = { ["cc"] = "======" } }
345-
local document = "{% if true %} abc{{ aa }}defg {% endif %} {% include 'foo' for bb %} {% include 'foo' %} "
346-
local function mock_template()
347-
return [[{% if true %} 12345{{ cc }}6789 {% endif %}]]
344+
local var = {
345+
["aa"] = "-----",
346+
["bb"] = { ["cc"] = "======" },
347+
}
348+
local document = [[
349+
{%- if true -%}
350+
abc{{ aa }}defg
351+
{%- endif %}
352+
{%- include 'foo' for bb -%}
353+
{%- include 'foo' -%}
354+
{%- include 'bar' -%}
355+
]]
356+
local filesystem = {
357+
foo = [[{% if true %} 12345{{ cc }}6789 {% endif %}]],
358+
bar = [[{% include 'recursive' %}]],
359+
recursive = [[bar]],
360+
}
361+
local function mock_template(name)
362+
return filesystem[name]
348363
end
349-
FileSystem.get = mock_template
350364
local lexer = Lexer:new(document)
351365
local parser = Parser:new(lexer)
352366
local interpreter = Interpreter:new(parser)
353-
ngx.say( interpreter:interpret( InterpreterContext:new(var) ) )
367+
ngx.say( interpreter:interpret( InterpreterContext:new(var), nil, nil, FileSystem:new(mock_template) ) )
354368
}
355369
}
356370
--- request
357371
GET /t
358372
--- response_body
359-
abc-----defg 12345======6789 123456789
360-
373+
abc-----defg 12345======6789 123456789 bar
361374
--- no_error_log
362375
[error]
363376

0 commit comments

Comments
 (0)