mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 11:20:41 -07:00
Merge pull request #441 from Shopify/remove_context_from_read_template_file
Removed context from read_template_file, fixed tests to match new arity
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
* Block parsing moved to BlockBody class (#458) [Dylan Thacker-Smith, dylanahsmith]
|
* Block parsing moved to BlockBody class (#458) [Dylan Thacker-Smith, dylanahsmith]
|
||||||
* Add concat filter to concatenate arrays (#429) [Diogo Beato, dvbeato]
|
* Add concat filter to concatenate arrays (#429) [Diogo Beato, dvbeato]
|
||||||
* Ruby 1.9 support dropped (#491) [Justin Li, pushrax]
|
* Ruby 1.9 support dropped (#491) [Justin Li, pushrax]
|
||||||
|
* Liquid::Template.file_system's read_template_file method is no longer passed the context. (#441) [James Reid-Smith, sunblaze]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
* Fix capturing into variables with a hyphen in the name (#505) [Florian Weingarten, fw42]
|
* Fix capturing into variables with a hyphen in the name (#505) [Florian Weingarten, fw42]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ module Liquid
|
|||||||
# This will parse the template with a LocalFileSystem implementation rooted at 'template_path'.
|
# This will parse the template with a LocalFileSystem implementation rooted at 'template_path'.
|
||||||
class BlankFileSystem
|
class BlankFileSystem
|
||||||
# Called by Liquid to retrieve a template file
|
# Called by Liquid to retrieve a template file
|
||||||
def read_template_file(template_path, context)
|
def read_template_file(template_path)
|
||||||
raise FileSystemError, "This liquid context does not allow includes."
|
raise FileSystemError, "This liquid context does not allow includes."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -49,7 +49,7 @@ module Liquid
|
|||||||
@pattern = pattern
|
@pattern = pattern
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_template_file(template_path, context)
|
def read_template_file(template_path)
|
||||||
full_path = full_path(template_path)
|
full_path = full_path(template_path)
|
||||||
raise FileSystemError, "No such template '#{template_path}'" unless File.exists?(full_path)
|
raise FileSystemError, "No such template '#{template_path}'" unless File.exists?(full_path)
|
||||||
|
|
||||||
|
|||||||
@@ -81,15 +81,7 @@ module Liquid
|
|||||||
def read_template_from_file_system(context)
|
def read_template_from_file_system(context)
|
||||||
file_system = context.registers[:file_system] || Liquid::Template.file_system
|
file_system = context.registers[:file_system] || Liquid::Template.file_system
|
||||||
|
|
||||||
# make read_template_file call backwards-compatible.
|
file_system.read_template_file(context.evaluate(@template_name))
|
||||||
case file_system.method(:read_template_file).arity
|
|
||||||
when 1
|
|
||||||
file_system.read_template_file(context.evaluate(@template_name))
|
|
||||||
when 2
|
|
||||||
file_system.read_template_file(context.evaluate(@template_name), context)
|
|
||||||
else
|
|
||||||
raise ArgumentError, "file_system.read_template_file expects two parameters: (template_name, context)"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def pass_options
|
def pass_options
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class ThemeRunner
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Called by Liquid to retrieve a template file
|
# Called by Liquid to retrieve a template file
|
||||||
def read_template_file(template_path, context)
|
def read_template_file(template_path)
|
||||||
File.read(@path + '/' + template_path + '.liquid')
|
File.read(@path + '/' + template_path + '.liquid')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class FoobarTag < Liquid::Tag
|
|||||||
end
|
end
|
||||||
|
|
||||||
class BlankTestFileSystem
|
class BlankTestFileSystem
|
||||||
def read_template_file(template_path, context)
|
def read_template_file(template_path)
|
||||||
template_path
|
template_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class RenderProfilingTest < Minitest::Test
|
|||||||
include Liquid
|
include Liquid
|
||||||
|
|
||||||
class ProfilingFileSystem
|
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 }}"
|
"Rendering template {% assign template_name = '#{template_path}'%}\n{{ template_name }}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class TestFileSystem
|
class TestFileSystem
|
||||||
def read_template_file(template_path, context)
|
def read_template_file(template_path)
|
||||||
case template_path
|
case template_path
|
||||||
when "product"
|
when "product"
|
||||||
"Product: {{ product.title }} "
|
"Product: {{ product.title }} "
|
||||||
@@ -37,14 +37,14 @@ class TestFileSystem
|
|||||||
end
|
end
|
||||||
|
|
||||||
class OtherFileSystem
|
class OtherFileSystem
|
||||||
def read_template_file(template_path, context)
|
def read_template_file(template_path)
|
||||||
'from OtherFileSystem'
|
'from OtherFileSystem'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class CountingFileSystem
|
class CountingFileSystem
|
||||||
attr_reader :count
|
attr_reader :count
|
||||||
def read_template_file(template_path, context)
|
def read_template_file(template_path)
|
||||||
@count ||= 0
|
@count ||= 0
|
||||||
@count += 1
|
@count += 1
|
||||||
'from CountingFileSystem'
|
'from CountingFileSystem'
|
||||||
@@ -132,7 +132,7 @@ class IncludeTagTest < Minitest::Test
|
|||||||
def test_recursively_included_template_does_not_produce_endless_loop
|
def test_recursively_included_template_does_not_produce_endless_loop
|
||||||
|
|
||||||
infinite_file_system = Class.new do
|
infinite_file_system = Class.new do
|
||||||
def read_template_file(template_path, context)
|
def read_template_file(template_path)
|
||||||
"-{% include 'loop' %}"
|
"-{% include 'loop' %}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -145,18 +145,6 @@ class IncludeTagTest < Minitest::Test
|
|||||||
|
|
||||||
end
|
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
|
def test_dynamically_choosen_template
|
||||||
assert_template_result "Test123", "{% include template %}", "template" => 'Test123'
|
assert_template_result "Test123", "{% include template %}", "template" => 'Test123'
|
||||||
assert_template_result "Test321", "{% include template %}", "template" => 'Test321'
|
assert_template_result "Test321", "{% include template %}", "template" => 'Test321'
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class FileSystemUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_default
|
def test_default
|
||||||
assert_raises(FileSystemError) do
|
assert_raises(FileSystemError) do
|
||||||
BlankFileSystem.new.read_template_file("dummy", {'dummy'=>'smarty'})
|
BlankFileSystem.new.read_template_file("dummy")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user