sutty-liquid 0.4.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/filters/assertion.rb +110 -10
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c72d9f508299076408aafbf0aa0e75f128259b3f647b16951f4f0b3ec18233a
|
4
|
+
data.tar.gz: 6c3216caa9bf468ea6375badf89cc33eef090ce41e98c8f0f9b7c492a28626d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7215373c2ff717d19d0b6593f2e938c153c2f2c7825928b9f8a88d416e61a7624e09fbcfc55f83e62859481231ae3700f7aae7a03d184e880e037d5c0362d35a
|
7
|
+
data.tar.gz: 414606c886d9e4313d405e95664ad8e108a562bb9a60490abf1f5042edb0df32533f5e30f97b1559fbe31cc55c33aca6bbfaa92e4b2ba40a0f0366a1f41b1565
|
@@ -16,6 +16,47 @@ module Jekyll
|
|
16
16
|
input == comparison
|
17
17
|
end
|
18
18
|
|
19
|
+
# The two values must be different
|
20
|
+
def not(input, comparison)
|
21
|
+
input != comparison
|
22
|
+
end
|
23
|
+
|
24
|
+
# Greater than
|
25
|
+
#
|
26
|
+
# @param [Integer|Float]
|
27
|
+
# @param [Integer|Float]
|
28
|
+
# @return [TrueClass|FalseClass]
|
29
|
+
def gt(input, comparison)
|
30
|
+
input > comparison
|
31
|
+
end
|
32
|
+
|
33
|
+
# Less than
|
34
|
+
#
|
35
|
+
# @param [Integer|Float]
|
36
|
+
# @param [Integer|Float]
|
37
|
+
# @return [TrueClass|FalseClass]
|
38
|
+
def lt(input, comparison)
|
39
|
+
input < comparison
|
40
|
+
end
|
41
|
+
|
42
|
+
# Greater than or equal
|
43
|
+
#
|
44
|
+
# @param [Integer|Float]
|
45
|
+
# @param [Integer|Float]
|
46
|
+
# @return [TrueClass|FalseClass]
|
47
|
+
def gte(input, comparison)
|
48
|
+
input >= comparison
|
49
|
+
end
|
50
|
+
|
51
|
+
# Less than or equal
|
52
|
+
#
|
53
|
+
# @param [Integer|Float]
|
54
|
+
# @param [Integer|Float]
|
55
|
+
# @return [TrueClass|FalseClass]
|
56
|
+
def lte(input, comparison)
|
57
|
+
input <= comparison
|
58
|
+
end
|
59
|
+
|
19
60
|
# Ternary operator. If the input value is truthy, return first
|
20
61
|
# argument, otherwise returns the last.
|
21
62
|
#
|
@@ -29,16 +70,75 @@ module Jekyll
|
|
29
70
|
# @param [Any]
|
30
71
|
# @return [Any]
|
31
72
|
def ternary(input, value, alternative)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
73
|
+
if present(input) && input
|
74
|
+
value
|
75
|
+
else
|
76
|
+
alternative
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns the value when the input is not empty or falsey
|
81
|
+
#
|
82
|
+
# If tags have something:
|
83
|
+
#
|
84
|
+
# {{ post.tags | value_if: "some tags" }} => "some tags"
|
85
|
+
def value_if(input, value)
|
86
|
+
value if present(input) && input
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns the value when the input is empty or falsey
|
90
|
+
#
|
91
|
+
# If tags are empty:
|
92
|
+
#
|
93
|
+
# {{ post.tags | value_unless: "no tags" }} => nil
|
94
|
+
def value_unless(input, value)
|
95
|
+
value unless present(input) && input
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns the input when value is not empty and truthy
|
99
|
+
#
|
100
|
+
# {{ post.url | input_if: true }} => 'url/to/post/'
|
101
|
+
def input_if(input, value)
|
102
|
+
input if present(value) && value
|
103
|
+
end
|
104
|
+
|
105
|
+
# {{ post.url | input_unless: false }} => nil
|
106
|
+
def input_unless(input, value)
|
107
|
+
input unless present(value) && value
|
108
|
+
end
|
109
|
+
|
110
|
+
# Checks if input value is empty.
|
111
|
+
#
|
112
|
+
# {{ post.title | blank }} => false
|
113
|
+
def blank(input)
|
114
|
+
case input
|
115
|
+
when TrueClass then false
|
116
|
+
when FalseClass then true
|
117
|
+
when NilClass then true
|
118
|
+
when Integer then false
|
119
|
+
when Float then false
|
120
|
+
when Time then false
|
121
|
+
when String then
|
122
|
+
require 'fast_blank'
|
123
|
+
input.blank?
|
124
|
+
when Array then input.compact.empty?
|
125
|
+
when Hash then input.compact.empty?
|
126
|
+
else input.respond_to?(:empty?) ? input.empty? : !!input
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# The opposite of blank
|
131
|
+
#
|
132
|
+
# {{ post.title | present }} => true
|
133
|
+
def present(input)
|
134
|
+
!blank(input)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Return the input if it's not blank
|
138
|
+
#
|
139
|
+
# {{ post.title | presence }} => 'the post title'
|
140
|
+
def presence(input)
|
141
|
+
input if present input
|
42
142
|
end
|
43
143
|
end
|
44
144
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sutty-liquid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fast_blank
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
27
41
|
description: An assorment of Liquid filters and tags for Jekyll used in Sutty
|
28
42
|
email:
|
29
43
|
- f@sutty.nl
|