From a5285d3d093fd991bd33df41a548e6fb908feb71 Mon Sep 17 00:00:00 2001 From: Ishibashi Hideto Date: Tue, 10 Sep 2013 22:58:56 +0900 Subject: [PATCH] =?UTF-8?q?test=20for=20the=20Jekyll's=20issue:=20[Liquid?= =?UTF-8?q?=20doesn't=20render=20my=20partial=20=C2=B7=20Issue=20#1519=20?= =?UTF-8?q?=C2=B7=20mojombo/jekyll](https://github.com/mojombo/jekyll/issu?= =?UTF-8?q?es/1519)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/liquid/tags/include_tag_test.rb | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/liquid/tags/include_tag_test.rb b/test/liquid/tags/include_tag_test.rb index 8bdb19c..56cbc34 100644 --- a/test/liquid/tags/include_tag_test.rb +++ b/test/liquid/tags/include_tag_test.rb @@ -163,4 +163,53 @@ class IncludeTagTest < Test::Unit::TestCase Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system}) assert_equal 2, file_system.count end + + def test_include_tag_within_if_statement + assert_equal "foo_if_true", + Template.parse("{% if true %}{% include 'foo_if_true' %}{% endif %}").render + end + + def test_custom_include_tag + original_tag = Liquid::Template.tags['include'] + Liquid::Template.tags['include'] = CustomInclude + begin + assert_equal "custom_foo", + Template.parse("{% include 'custom_foo' %}").render + ensure + Liquid::Template.tags['include'] = original_tag + end + end + + def test_custom_include_tag_within_if_statement + original_tag = Liquid::Template.tags['include'] + Liquid::Template.tags['include'] = CustomInclude + begin + assert_equal "custom_foo_if_true", + Template.parse("{% if true %}{% include 'custom_foo_if_true' %}{% endif %}").render + ensure + Liquid::Template.tags['include'] = original_tag + end + end + + class CustomInclude < Liquid::Tag + include Liquid + Syntax = /(#{QuotedFragment}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?/o + + def initialize(tag_name, markup, tokens) + markup =~ Syntax + @template_name = $1 + super + end + + def parse(tokens) + end + + def blank? + false + end + + def render(context) + @template_name[1..-2] + end + end end # IncludeTagTest