mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
now able to set file_system for include tag through registers
This commit is contained in:
@@ -24,7 +24,8 @@ module Liquid
|
||||
end
|
||||
|
||||
def render(context)
|
||||
source = Liquid::Template.file_system.read_template_file(context[@template_name])
|
||||
file_system = context.registers[:file_system] || Liquid::Template.file_system
|
||||
source = file_system.read_template_file(context[@template_name])
|
||||
partial = Liquid::Template.parse(source)
|
||||
|
||||
variable = context[@variable_name || @template_name[1..-2]]
|
||||
|
||||
@@ -23,6 +23,9 @@ class TestFileSystem
|
||||
|
||||
when "recursively_nested_template"
|
||||
"-{% include 'recursively_nested_template' %}"
|
||||
|
||||
when "pick_a_source"
|
||||
"from TestFileSystem"
|
||||
|
||||
else
|
||||
template_path
|
||||
@@ -30,6 +33,12 @@ class TestFileSystem
|
||||
end
|
||||
end
|
||||
|
||||
class OtherFileSystem
|
||||
def read_template_file(template_path)
|
||||
'from OtherFileSystem'
|
||||
end
|
||||
end
|
||||
|
||||
class IncludeTagTest < Test::Unit::TestCase
|
||||
include Liquid
|
||||
|
||||
@@ -37,6 +46,11 @@ class IncludeTagTest < Test::Unit::TestCase
|
||||
Liquid::Template.file_system = TestFileSystem.new
|
||||
end
|
||||
|
||||
def test_include_tag_looks_for_file_system_in_registers_first
|
||||
assert_equal 'from OtherFileSystem',
|
||||
Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => OtherFileSystem.new})
|
||||
end
|
||||
|
||||
|
||||
def test_include_tag_with
|
||||
assert_equal "Product: Draft 151cm ",
|
||||
|
||||
Reference in New Issue
Block a user