sutty-liquid 0.4.1 → 0.5.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll/filters/assertion.rb +110 -10
  3. metadata +15 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d90e4da9fe0d1b7d177e20fd9a05f825a07d3465d99b1641d79b75879d526c00
4
- data.tar.gz: f467555d544fca178ba15dce7f1de53eadfcbea7a263fe91f9a6066ac92664d2
3
+ metadata.gz: 4c72d9f508299076408aafbf0aa0e75f128259b3f647b16951f4f0b3ec18233a
4
+ data.tar.gz: 6c3216caa9bf468ea6375badf89cc33eef090ce41e98c8f0f9b7c492a28626d3
5
5
  SHA512:
6
- metadata.gz: 94b85e20c7c10e267e67534ab215d94539b482cc807ff7623f03d8f281463df12395cde294d00814b0b8db04897dfde6cbe0880d882982459050f7d8f53e28eb
7
- data.tar.gz: 1dd71eb67a50c79a1f796ff0813968f2275e7b3fd56afe5f45234a2efc5244bb87c0da10fc90fb417547d64f72a3dbc534efa09c772dfe95eae063def69a2dd0
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
- empty = case input
33
- when Integer then input.zero?
34
- when Float then input.zero?
35
- when TrueClass then input
36
- when FalseClass then input
37
- when NilClass then false
38
- else input.empty?
39
- end
40
-
41
- (empty || !!input) ? value : alternative
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.1
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