mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Compare commits
6 Commits
order-of-o
...
remove-ext
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be02670a54 | ||
|
|
b1cdd31858 | ||
|
|
8ece160330 | ||
|
|
b9e0d28729 | ||
|
|
020f6b93c5 | ||
|
|
cfe1637bdd |
@@ -10,7 +10,7 @@ Performance:
|
||||
Enabled: true
|
||||
|
||||
AllCops:
|
||||
TargetRubyVersion: 2.4
|
||||
TargetRubyVersion: 2.5
|
||||
NewCops: disable
|
||||
Exclude:
|
||||
- 'vendor/bundle/**/*'
|
||||
@@ -18,3 +18,7 @@ AllCops:
|
||||
Naming/MethodName:
|
||||
Exclude:
|
||||
- 'example/server/liquid_servlet.rb'
|
||||
|
||||
# Backport https://github.com/Shopify/ruby-style-guide/pull/258
|
||||
Layout/BeginEndAlignment:
|
||||
Enabled: true
|
||||
|
||||
@@ -5,6 +5,7 @@ require 'bigdecimal'
|
||||
|
||||
module Liquid
|
||||
module StandardFilters
|
||||
MAX_INT = (1 << 31) - 1
|
||||
HTML_ESCAPE = {
|
||||
'&' => '&',
|
||||
'>' => '>',
|
||||
@@ -93,7 +94,13 @@ module Liquid
|
||||
words = Utils.to_integer(words)
|
||||
words = 1 if words <= 0
|
||||
|
||||
wordlist = input.split(" ", words + 1)
|
||||
wordlist = begin
|
||||
input.split(" ", words + 1)
|
||||
rescue RangeError
|
||||
raise if words + 1 < MAX_INT
|
||||
# e.g. integer #{words} too big to convert to `int'
|
||||
raise Liquid::ArgumentError, "integer #{words} too big for truncatewords"
|
||||
end
|
||||
return input if wordlist.length <= words
|
||||
|
||||
wordlist.pop
|
||||
|
||||
@@ -14,11 +14,11 @@ module ShopFilter
|
||||
end
|
||||
|
||||
def script_tag(url)
|
||||
%(<script src="#{url}" type="text/javascript"></script>)
|
||||
%(<script src="#{url}"></script>)
|
||||
end
|
||||
|
||||
def stylesheet_tag(url, media = "all")
|
||||
%(<link href="#{url}" rel="stylesheet" type="text/css" media="#{media}" />)
|
||||
%(<link href="#{url}" rel="stylesheet" #{%(media="#{media}" ) unless media == 'all'}/>)
|
||||
end
|
||||
|
||||
def link_to(link, url, title = "")
|
||||
|
||||
@@ -178,6 +178,10 @@ class StandardFiltersTest < Minitest::Test
|
||||
assert_equal('one two three...', @filters.truncatewords("one two\tthree\nfour", 3))
|
||||
assert_equal('one two...', @filters.truncatewords("one two three four", 2))
|
||||
assert_equal('one...', @filters.truncatewords("one two three four", 0))
|
||||
exception = assert_raises(Liquid::ArgumentError) do
|
||||
@filters.truncatewords("one two three four", 1 << 31)
|
||||
end
|
||||
assert_equal("Liquid error: integer #{1 << 31} too big for truncatewords", exception.message)
|
||||
end
|
||||
|
||||
def test_strip_html
|
||||
|
||||
@@ -187,49 +187,4 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user