mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -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
|
end
|
||||||
|
|
||||||
def render(context)
|
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)
|
partial = Liquid::Template.parse(source)
|
||||||
|
|
||||||
variable = context[@variable_name || @template_name[1..-2]]
|
variable = context[@variable_name || @template_name[1..-2]]
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ class TestFileSystem
|
|||||||
|
|
||||||
when "recursively_nested_template"
|
when "recursively_nested_template"
|
||||||
"-{% include 'recursively_nested_template' %}"
|
"-{% include 'recursively_nested_template' %}"
|
||||||
|
|
||||||
|
when "pick_a_source"
|
||||||
|
"from TestFileSystem"
|
||||||
|
|
||||||
else
|
else
|
||||||
template_path
|
template_path
|
||||||
@@ -30,6 +33,12 @@ class TestFileSystem
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class OtherFileSystem
|
||||||
|
def read_template_file(template_path)
|
||||||
|
'from OtherFileSystem'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class IncludeTagTest < Test::Unit::TestCase
|
class IncludeTagTest < Test::Unit::TestCase
|
||||||
include Liquid
|
include Liquid
|
||||||
|
|
||||||
@@ -37,6 +46,11 @@ class IncludeTagTest < Test::Unit::TestCase
|
|||||||
Liquid::Template.file_system = TestFileSystem.new
|
Liquid::Template.file_system = TestFileSystem.new
|
||||||
end
|
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
|
def test_include_tag_with
|
||||||
assert_equal "Product: Draft 151cm ",
|
assert_equal "Product: Draft 151cm ",
|
||||||
|
|||||||
Reference in New Issue
Block a user