mirror of
https://github.com/kemko/liquid.git
synced 2026-01-13 21:45:44 +03:00
Compare commits
15 Commits
sort-numer
...
disable-ta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
221b5673a0 | ||
|
|
68abd9c135 | ||
|
|
644de4c4f5 | ||
|
|
9b2d0dc145 | ||
|
|
5e9b0bd3e9 | ||
|
|
695378d8a4 | ||
|
|
a6dfb56a5c | ||
|
|
9f03dff79a | ||
|
|
7f136c8fa6 | ||
|
|
008c22230a | ||
|
|
4202976d79 | ||
|
|
fc4059c8dd | ||
|
|
05234ef6de | ||
|
|
6f823891bc | ||
|
|
a39eb8581a |
@@ -170,7 +170,7 @@ module Liquid
|
||||
|
||||
def disable_tags(context, tags, &block)
|
||||
return yield if tags.empty?
|
||||
context.registers[:disabled_tags].disable(tags, &block)
|
||||
context.registers['disabled_tags'].disable(tags, &block)
|
||||
end
|
||||
|
||||
def raise_if_resource_limits_reached(context, length)
|
||||
|
||||
@@ -28,5 +28,5 @@ module Liquid
|
||||
end
|
||||
end
|
||||
|
||||
Template.add_register(:disabled_tags, DisabledTags.new)
|
||||
Template.add_register('disabled_tags', DisabledTags.new)
|
||||
end
|
||||
|
||||
@@ -193,23 +193,6 @@ module Liquid
|
||||
end
|
||||
end
|
||||
|
||||
# Sort elements of an array in numeric order
|
||||
# provide optional property with which to sort an array of hashes or drops
|
||||
def sort_numeric(input, property = nil)
|
||||
ary = InputIterator.new(input)
|
||||
if property.nil?
|
||||
ary.sort do |a, b|
|
||||
Utils.to_number(a) <=> Utils.to_number(b)
|
||||
end
|
||||
elsif ary.empty? # The next two cases assume a non-empty array.
|
||||
[]
|
||||
elsif ary.first.respond_to?(:[]) && !ary.first[property].nil?
|
||||
ary.sort do |a, b|
|
||||
Utils.to_number(a[property]) <=> Utils.to_number(b[property])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Remove duplicate elements from an array
|
||||
# provide optional property with which to determine uniqueness
|
||||
def uniq(input, property = nil)
|
||||
|
||||
@@ -47,7 +47,7 @@ module Liquid
|
||||
end
|
||||
|
||||
def disabled?(context)
|
||||
context.registers[:disabled_tags].disabled?(tag_name)
|
||||
context.registers['disabled_tags'].disabled?(tag_name)
|
||||
end
|
||||
|
||||
def disabled_error_message
|
||||
|
||||
@@ -93,7 +93,7 @@ module Liquid
|
||||
end
|
||||
|
||||
def add_register(name, klass)
|
||||
registers[name.to_sym] = klass
|
||||
registers[name.to_s] = klass
|
||||
end
|
||||
|
||||
def registers
|
||||
|
||||
@@ -198,12 +198,6 @@ class StandardFiltersTest < Minitest::Test
|
||||
assert_equal [{ "a" => 1 }, { "a" => 2 }, { "a" => 3 }, { "a" => 4 }], @filters.sort([{ "a" => 4 }, { "a" => 3 }, { "a" => 1 }, { "a" => 2 }], "a")
|
||||
end
|
||||
|
||||
def test_sort_numeric
|
||||
assert_equal ['1', '2', '3', '10'], @filters.sort_numeric(['10', '3', '2', '1'])
|
||||
assert_equal [{ "a" => '1' }, { "a" => '2' }, { "a" => '3' }, { "a" => '10' }],
|
||||
@filters.sort_numeric([{ "a" => '10' }, { "a" => '3' }, { "a" => '1' }, { "a" => '2' }], "a")
|
||||
end
|
||||
|
||||
def test_sort_with_nils
|
||||
assert_equal [1, 2, 3, 4, nil], @filters.sort([nil, 4, 3, 2, 1])
|
||||
assert_equal [{ "a" => 1 }, { "a" => 2 }, { "a" => 3 }, { "a" => 4 }, {}], @filters.sort([{ "a" => 4 }, { "a" => 3 }, {}, { "a" => 1 }, { "a" => 2 }], "a")
|
||||
@@ -298,10 +292,6 @@ class StandardFiltersTest < Minitest::Test
|
||||
assert_equal [], @filters.sort_natural([], "a")
|
||||
end
|
||||
|
||||
def test_sort_numeric_empty_array
|
||||
assert_equal [], @filters.sort_numeric([], "a")
|
||||
end
|
||||
|
||||
def test_sort_natural_invalid_property
|
||||
foo = [
|
||||
[1],
|
||||
|
||||
Reference in New Issue
Block a user