From a4d7c80ce098e255593e5baec186671f9a9d2517 Mon Sep 17 00:00:00 2001 From: James MacAulay Date: Thu, 6 Aug 2009 18:24:27 -0400 Subject: [PATCH] now able to set file_system for include tag through registers --- lib/liquid/tags/include.rb | 3 ++- test/include_tag_test.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/liquid/tags/include.rb b/lib/liquid/tags/include.rb index 2f9439fa..3c74d72a 100644 --- a/lib/liquid/tags/include.rb +++ b/lib/liquid/tags/include.rb @@ -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]] diff --git a/test/include_tag_test.rb b/test/include_tag_test.rb index 06f3b305..f78b5788 100644 --- a/test/include_tag_test.rb +++ b/test/include_tag_test.rb @@ -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 ",