liquid-nested-sort 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/liquid_nested_sort.rb +41 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7cb5f83d18f3c4ce3def897442ccaa8ba84030eacbc44bba5a4d0ac1b5def404
|
4
|
+
data.tar.gz: e8a6bab9cf5492b641b50cad2b986913eec5c9e94d1d30dc351962978cd31db0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8a516483651ec92099adebe1a73045392ddb1db642771f92619a6250ca73addef147f3140e9dd1dda6222601857e1b5b44c1c69b3307f835ace16cd98e1a9fd
|
7
|
+
data.tar.gz: 26a5a00c0ee15b020f07ab86a5fa5d067e5ad50b661e2c56f1d77142bfa2a007f9c9ef077704efb6d12dccb0a3ab1c7a1f15a2828497320b3ca7e029231b2415
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NestedFilter
|
4
|
+
def nested_sort(input, property = nil)
|
5
|
+
ary = InputIterator.new(input, context)
|
6
|
+
|
7
|
+
return [] if ary.empty?
|
8
|
+
|
9
|
+
if property.nil?
|
10
|
+
ary.sort do |a, b|
|
11
|
+
nil_safe_compare(a, b)
|
12
|
+
end
|
13
|
+
elsif ary.all? { |el| el.respond_to?(:[]) }
|
14
|
+
begin
|
15
|
+
ary.sort { |a, b| nil_safe_compare(a[property], b[property]) }
|
16
|
+
rescue TypeError
|
17
|
+
raise_property_error(property)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def nested_sort_natural(input, property = nil)
|
23
|
+
ary = InputIterator.new(input, context)
|
24
|
+
|
25
|
+
return [] if ary.empty?
|
26
|
+
|
27
|
+
if property.nil?
|
28
|
+
ary.sort do |a, b|
|
29
|
+
nil_safe_compare(a, b)
|
30
|
+
end
|
31
|
+
elsif ary.all? { |el| el.respond_to?(:[]) }
|
32
|
+
begin
|
33
|
+
ary.sort { |a, b| nil_safe_compare(a[property], b[property]) }
|
34
|
+
rescue TypeError
|
35
|
+
raise_property_error(property)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Liquid::Template.register_filter(NestedFilter)
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: liquid-nested-sort
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fabio Bonelli
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: liquid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
description: Liquid's sort and sort_natural don't support nested fields out of the
|
34
|
+
box.This gems provides nested_sort and nester_sort_natural.
|
35
|
+
email: fb@fabiobonelli.it
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- lib/liquid_nested_sort.rb
|
41
|
+
homepage: https://github.com/bfabio/liquid-nested-sort
|
42
|
+
licenses:
|
43
|
+
- BSD-3-Clause
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.4'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.7.6.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: sort and sort_natural filters with nested fields support for Liquid
|
65
|
+
test_files: []
|