mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 16:25:42 +03:00
Compare commits
3 Commits
parse_part
...
include_pa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5077463ec6 | ||
|
|
b765343ee2 | ||
|
|
cbd1a07c1c |
@@ -73,7 +73,7 @@ module Liquid
|
||||
if cached = cached_partials[template_name]
|
||||
cached
|
||||
else
|
||||
if @partial && context.registers[:file_system].nil?
|
||||
if @partial
|
||||
partial = @partial
|
||||
else
|
||||
partial = Liquid::Template.parse(read_template_from_file_system(context), pass_options)
|
||||
@@ -85,17 +85,9 @@ module Liquid
|
||||
end
|
||||
|
||||
def read_template_from_file_system(context)
|
||||
file_system = context.registers[:file_system] || parsed_file_system || Liquid::Template.file_system
|
||||
file_system = context.registers[:file_system] || Liquid::Template.file_system
|
||||
|
||||
# make read_template_file call backwards-compatible.
|
||||
case file_system.method(:read_template_file).arity
|
||||
when 1
|
||||
file_system.read_template_file(context[@template_name])
|
||||
when 2
|
||||
file_system.read_template_file(context[@template_name], context)
|
||||
else
|
||||
raise ArgumentError, "file_system.read_template_file expects two parameters: (template_name, context)"
|
||||
end
|
||||
file_system.read_template_file(context[@template_name])
|
||||
end
|
||||
|
||||
def read_template_from_file_system_at_parse
|
||||
|
||||
@@ -9,7 +9,7 @@ class FoobarTag < Liquid::Tag
|
||||
end
|
||||
|
||||
class BlankTestFileSystem
|
||||
def read_template_file(template_path, context)
|
||||
def read_template_file(template_path)
|
||||
template_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class RenderProfilingTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
class ProfilingFileSystem
|
||||
def read_template_file(template_path, context)
|
||||
def read_template_file(template_path)
|
||||
"Rendering template {% assign template_name = '#{template_path}'%}\n{{ template_name }}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TestFileSystem
|
||||
def read_template_file(template_path, context)
|
||||
def read_template_file(template_path)
|
||||
case template_path
|
||||
when "product"
|
||||
"Product: {{ product.title }} "
|
||||
@@ -41,14 +41,14 @@ class ParseFileSystem
|
||||
end
|
||||
|
||||
class OtherFileSystem
|
||||
def read_template_file(template_path, context)
|
||||
def read_template_file(template_path)
|
||||
'from OtherFileSystem'
|
||||
end
|
||||
end
|
||||
|
||||
class CountingFileSystem
|
||||
attr_reader :count
|
||||
def read_template_file(template_path, context)
|
||||
def read_template_file(template_path)
|
||||
@count ||= 0
|
||||
@count += 1
|
||||
'from CountingFileSystem'
|
||||
@@ -86,17 +86,12 @@ class IncludeTagTest < Minitest::Test
|
||||
|
||||
def test_include_tag_can_use_file_system_at_parse_so_it_can_be_parsed_before_rendered
|
||||
assert_equal 'from ParseFileSystem',
|
||||
Template.parse("{% include 'pick_a_source' %}",file_system: ParseFileSystem.new).render!({})
|
||||
end
|
||||
|
||||
def test_include_tag_looks_at_file_system_passed_in_registers_over_parse_options
|
||||
assert_equal 'from OtherFileSystem',
|
||||
Template.parse("{% include 'pick_a_source' %}",file_system: ParseFileSystem.new).render!({}, :registers => {:file_system => OtherFileSystem.new})
|
||||
end
|
||||
|
||||
def test_include_tag_use_parse_option_file_system_even_if_partial_can_be_preparsed
|
||||
assert_equal 'from ParseFileSystem',
|
||||
Template.parse("{% include template %}",file_system: ParseFileSystem.new).render!({})
|
||||
def test_include_tag_use_registers_file_system_when_it_cant_be_preparse
|
||||
assert_equal 'from OtherFileSystem',
|
||||
Template.parse("{% include template %}",file_system: ParseFileSystem.new).render!({}, :registers => {:file_system => OtherFileSystem.new})
|
||||
end
|
||||
|
||||
def test_include_tag_with
|
||||
@@ -146,7 +141,7 @@ class IncludeTagTest < Minitest::Test
|
||||
def test_recursively_included_template_does_not_produce_endless_loop
|
||||
|
||||
infinite_file_system = Class.new do
|
||||
def read_template_file(template_path, context)
|
||||
def read_template_file(template_path)
|
||||
"-{% include 'loop' %}"
|
||||
end
|
||||
end
|
||||
@@ -159,18 +154,6 @@ class IncludeTagTest < Minitest::Test
|
||||
|
||||
end
|
||||
|
||||
def test_backwards_compatability_support_for_overridden_read_template_file
|
||||
infinite_file_system = Class.new do
|
||||
def read_template_file(template_path) # testing only one argument here.
|
||||
"- hi mom"
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.file_system = infinite_file_system.new
|
||||
|
||||
Template.parse("{% include 'hi_mom' %}").render!
|
||||
end
|
||||
|
||||
def test_dynamically_choosen_template
|
||||
assert_template_result "Test123", "{% include template %}", "template" => 'Test123'
|
||||
assert_template_result "Test321", "{% include template %}", "template" => 'Test321'
|
||||
|
||||
Reference in New Issue
Block a user