mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 00:05:42 +03:00
Compare commits
8 Commits
fix/echo-p
...
order-of-o
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efec04af06 | ||
|
|
eab13a07d9 | ||
|
|
ca96ca0fef | ||
|
|
4e7a953e73 | ||
|
|
6ac2499f7f | ||
|
|
ff70161512 | ||
|
|
026157e128 | ||
|
|
bf64239ea6 |
15
History.md
15
History.md
@@ -1,5 +1,20 @@
|
||||
# Liquid Change Log
|
||||
|
||||
## 5.0.2 (unreleased)
|
||||
|
||||
### Fixes
|
||||
* Fix support for using a String subclass for the liquid source (#1421) [Dylan Thacker-Smith]
|
||||
|
||||
## 5.0.1 / 2021-03-24
|
||||
|
||||
### Fixes
|
||||
* Add ParseTreeVisitor to Echo tag (#1414) [CP Clermont]
|
||||
* Test with ruby 3.0 as the latest ruby version (#1398) [Dylan Thacker-Smith]
|
||||
* Handle carriage return in newlines_to_br (#1391) [Unending]
|
||||
|
||||
### Performance Improvements
|
||||
* Use split limit in truncatewords (#1361) [Dylan Thacker-Smith]
|
||||
|
||||
## 5.0.0 / 2021-01-06
|
||||
|
||||
### Features
|
||||
|
||||
@@ -5,7 +5,7 @@ module Liquid
|
||||
attr_reader :line_number, :for_liquid_tag
|
||||
|
||||
def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false)
|
||||
@source = source
|
||||
@source = source.to_s.to_str
|
||||
@line_number = line_number || (line_numbers ? 1 : nil)
|
||||
@for_liquid_tag = for_liquid_tag
|
||||
@tokens = tokenize
|
||||
@@ -24,7 +24,7 @@ module Liquid
|
||||
private
|
||||
|
||||
def tokenize
|
||||
return [] if @source.to_s.empty?
|
||||
return [] if @source.empty?
|
||||
|
||||
return @source.split("\n") if @for_liquid_tag
|
||||
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Liquid
|
||||
VERSION = "5.0.0"
|
||||
VERSION = "5.0.2.alpha"
|
||||
end
|
||||
|
||||
@@ -187,4 +187,49 @@ class IfElseTagTest < Minitest::Test
|
||||
assert_template_result(expected.to_s, tpl, assigns, assigns.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def test_operators_order
|
||||
expected_groupings = [
|
||||
->(w, x, y, z) { (w && (x || (y && z))) },
|
||||
->(w, x, y, z) { (w || (x && (y || z))) },
|
||||
]
|
||||
|
||||
liquid_conditions = [
|
||||
'w and x or y and z',
|
||||
'w or x and y or z',
|
||||
]
|
||||
|
||||
conditions = (0..0b1111).map do |cond|
|
||||
[
|
||||
(cond & 0b1000) == 0 ? false : true,
|
||||
(cond & 0b0100) == 0 ? false : true,
|
||||
(cond & 0b0010) == 0 ? false : true,
|
||||
(cond & 0b0001) == 0 ? false : true,
|
||||
]
|
||||
end
|
||||
|
||||
expected_results = expected_groupings.map do |test|
|
||||
conditions.map do |condition|
|
||||
test.call(*condition)
|
||||
end
|
||||
end
|
||||
|
||||
liquid_results = liquid_conditions.map do |conditional_expression|
|
||||
tpl = "{% if #{conditional_expression} %}true{% else %}false{% endif %}"
|
||||
template = Liquid::Template.parse(tpl, line_numbers: true)
|
||||
conditions.map do |condition|
|
||||
w, x, y, z = condition
|
||||
assigns = { 'w' => w, 'x' => x, 'y' => y, 'z' => z }
|
||||
template.render!(assigns)
|
||||
end.map { |r| true?(r) }
|
||||
end
|
||||
|
||||
assert_equal(expected_results, liquid_results)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def true?(obj)
|
||||
obj.to_s.casecmp('true').zero?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -323,4 +323,18 @@ class TemplateTest < Minitest::Test
|
||||
result = t.render('x' => 1, 'y' => 5)
|
||||
assert_equal('12345', result)
|
||||
end
|
||||
|
||||
def test_source_string_subclass
|
||||
string_subclass = Class.new(String) do
|
||||
# E.g. ActiveSupport::SafeBuffer does this, so don't just rely on to_s to return a String
|
||||
def to_s
|
||||
self
|
||||
end
|
||||
end
|
||||
source = string_subclass.new("{% assign x = 2 -%} x= {{- x }}")
|
||||
assert_instance_of(string_subclass, source)
|
||||
output = Template.parse(source).render!
|
||||
assert_equal("x=2", output)
|
||||
assert_instance_of(String, output)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user