Skip to content
Browse files

now able to set file_system for include tag through registers

  • Loading branch information...
1 parent 1fb94e7 commit e26c7868fb392c477b190b03d61ed941df69f357 @jamesmacaulay jamesmacaulay committed with tobi
Showing with 16 additions and 1 deletion.
  1. +2 −1 lib/liquid/tags/include.rb
  2. +14 −0 test/include_tag_test.rb
View
3 lib/liquid/tags/include.rb
@@ -24,7 +24,8 @@ def parse(tokens)
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]]
View
14 test/include_tag_test.rb
@@ -23,6 +23,9 @@ def read_template_file(template_path)
when "recursively_nested_template"
"-{% include 'recursively_nested_template' %}"
+
+ when "pick_a_source"
+ "from TestFileSystem"
else
template_path
@@ -30,6 +33,12 @@ def read_template_file(template_path)
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 @@ def setup
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 ",

0 comments on commit e26c786

Please sign in to comment.
Something went wrong with that request. Please try again.