Compare commits

...

3 Commits

Author SHA1 Message Date
Thierry Joyal
3f439f73ba Add osx 2019-12-13 09:47:29 -05:00
Thierry Joyal
5face68cc8 Experiment with ruby 2.7 2019-12-13 09:13:32 -05:00
Mike Angell
57c9cf64eb Allow render to handle with and for correctly (#1193)
* Allow render to handle with and for correctly

* code improvements
2019-10-23 04:12:46 +10:00
3 changed files with 32 additions and 4 deletions

View File

@@ -1,11 +1,15 @@
language: ruby
cache: bundler
os: [osx, linux]
rvm:
- 2.4
- 2.5
- &latest_ruby 2.6
- 2.7
- 2.7.0-preview1
- 2.7.0-preview2
- 2.7.0-preview3
- ruby-head
matrix:
@@ -15,6 +19,9 @@ matrix:
name: Profiling Memory Usage
allow_failures:
- rvm: ruby-head
- rvm: 2.7
- rvm: 2.7.0-preview2
- rvm: 2.7.0-preview3
branches:
only:

View File

@@ -2,7 +2,8 @@
module Liquid
class Render < Tag
SYNTAX = /(#{QuotedString}+)(\s+(?:with|for)\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
FOR = 'for'
SYNTAX = /(#{QuotedString}+)(\s+(with|#{FOR})\s+(#{QuotedFragment}+))?(\s+(?:as)\s+(#{VariableSegment}+))?/o
disable_tags "include"
@@ -14,11 +15,13 @@ module Liquid
raise SyntaxError, options[:locale].t("errors.syntax.render") unless markup =~ SYNTAX
template_name = Regexp.last_match(1)
variable_name = Regexp.last_match(3)
with_or_for = Regexp.last_match(3)
variable_name = Regexp.last_match(4)
@alias_name = Regexp.last_match(5)
@alias_name = Regexp.last_match(6)
@variable_name_expr = variable_name ? Expression.parse(variable_name) : nil
@template_name_expr = Expression.parse(template_name)
@for = (with_or_for == FOR)
@attributes = {}
markup.scan(TagAttributes) do |key, value|
@@ -58,7 +61,7 @@ module Liquid
}
variable = @variable_name_expr ? context.evaluate(@variable_name_expr) : nil
if variable.is_a?(Array)
if @for && variable.respond_to?(:each) && variable.respond_to?(:count)
forloop = Liquid::ForloopDrop.new(template_name, variable.count, nil)
variable.each { |var| render_partial_func.call(var, forloop) }
else

View File

@@ -214,4 +214,22 @@ class RenderTagTest < Minitest::Test
assert_template_result("Product: Draft 151cm first index:1 Product: Element 155cm last index:2 ",
"{% render 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
end
def test_render_tag_for_drop
Liquid::Template.file_system = StubFileSystem.new(
'loop' => "{{ value.foo }}",
)
assert_template_result("123",
"{% render 'loop' for loop as value %}", "loop" => TestEnumerable.new)
end
def test_render_tag_with_drop
Liquid::Template.file_system = StubFileSystem.new(
'loop' => "{{ value }}",
)
assert_template_result("TestEnumerable",
"{% render 'loop' with loop as value %}", "loop" => TestEnumerable.new)
end
end