module Jekyll::Filters::Assertion
Public Instance Methods
Checks if input value is empty.
{{ post.title | blank }} => false
# File lib/jekyll/filters/assertion.rb 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
Compares two values.
Example usage:
{{ item.url | equals: page.url }}
@param [Any] @param [Any] @return [TrueClass|FalseClass]
# File lib/jekyll/filters/assertion.rb 15 def equals(input, comparison) 16 input == comparison 17 end
Greater than
@param [Integer|Float] @param [Integer|Float] @return [TrueClass|FalseClass]
# File lib/jekyll/filters/assertion.rb 29 def gt(input, comparison) 30 input > comparison 31 end
Greater than or equal
@param [Integer|Float] @param [Integer|Float] @return [TrueClass|FalseClass]
# File lib/jekyll/filters/assertion.rb 47 def gte(input, comparison) 48 input >= comparison 49 end
Returns the input when value is not empty and truthy
{{ post.url | input_if
: true }} => 'url/to/post/'
# File lib/jekyll/filters/assertion.rb 101 def input_if(input, value) 102 input if present(value) && value 103 end
{{ post.url | input_unless
: false }} => nil
# File lib/jekyll/filters/assertion.rb 106 def input_unless(input, value) 107 input unless present(value) && value 108 end
Less than
@param [Integer|Float] @param [Integer|Float] @return [TrueClass|FalseClass]
# File lib/jekyll/filters/assertion.rb 38 def lt(input, comparison) 39 input < comparison 40 end
Less than or equal
@param [Integer|Float] @param [Integer|Float] @return [TrueClass|FalseClass]
# File lib/jekyll/filters/assertion.rb 56 def lte(input, comparison) 57 input <= comparison 58 end
The two values must be different
# File lib/jekyll/filters/assertion.rb 20 def not(input, comparison) 21 input != comparison 22 end
Return the input if it's not blank
{{ post.title | presence }} => 'the post title'
# File lib/jekyll/filters/assertion.rb 140 def presence(input) 141 input if present input 142 end
The opposite of blank
{{ post.title | present }} => true
# File lib/jekyll/filters/assertion.rb 133 def present(input) 134 !blank(input) 135 end
Ternary operator. If the input value is truthy, return first argument, otherwise returns the last.
Example usage:
{% assign active = item.url | equals: page.url %} {{ active | ternary: 'active', '' }}
@param [Any] @param [Any] @param [Any] @return [Any]
# File lib/jekyll/filters/assertion.rb 72 def ternary(input, value, alternative) 73 if present(input) && input 74 value 75 else 76 alternative 77 end 78 end
Returns the value when the input is not empty or falsey
If tags have something:
{{ post.tags | value_if
: “some tags” }} => “some tags”
# File lib/jekyll/filters/assertion.rb 85 def value_if(input, value) 86 value if present(input) && input 87 end
Returns the value when the input is empty or falsey
If tags are empty:
{{ post.tags | value_unless
: “no tags” }} => nil
# File lib/jekyll/filters/assertion.rb 94 def value_unless(input, value) 95 value unless present(input) && input 96 end