Compare commits

..

15 Commits

Author SHA1 Message Date
Mike Angell
221b5673a0 Fix array handling shortcut in disable_tags 2019-09-26 00:09:51 +10:00
Mike Angell
68abd9c135 Switch disabled? to not mutate output 2019-09-25 23:57:55 +10:00
Mike Angell
644de4c4f5 Code improvements 2019-09-25 23:33:46 +10:00
Mike Angell
9b2d0dc145 Improve disable tag API 2019-09-25 11:34:44 +10:00
Mike Angell
5e9b0bd3e9 Improve disabled tag error output 2019-09-24 09:05:22 +10:00
Mike Angell
695378d8a4 Remove redundant nil check 2019-09-24 04:22:43 +10:00
Mike Angell
a6dfb56a5c Code improvements 2019-09-24 00:20:51 +10:00
Mike Angell
9f03dff79a Move disabled check to block_body 2019-09-24 00:07:59 +10:00
Mike Angell
7f136c8fa6 Allow multiple tags to be disabled at once 2019-09-23 23:36:27 +10:00
Mike Angell
008c22230a disabled_tags is now always avaiable 2019-09-23 22:06:31 +10:00
Mike Angell
4202976d79 Test disable_tags register 2019-09-23 22:02:13 +10:00
Mike Angell
fc4059c8dd Resolve disbale tag tests 2019-09-23 21:03:35 +10:00
Mike Angell
05234ef6de Improvements to disable tag 2019-09-23 20:45:09 +10:00
Mike Angell
6f823891bc Merge branch 'master' into disable-tag 2019-09-23 20:16:41 +10:00
Mike Angell
a39eb8581a Disable rendering of tag based on register 2019-09-18 18:33:19 +10:00
6 changed files with 4 additions and 31 deletions

View File

@@ -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)

View File

@@ -28,5 +28,5 @@ module Liquid
end
end
Template.add_register(:disabled_tags, DisabledTags.new)
Template.add_register('disabled_tags', DisabledTags.new)
end

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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],