module Jekyll::Filters::Assertion

Public Instance Methods

blank(input) click to toggle source

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
equals(input, comparison) click to toggle source

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
gt(input, comparison) click to toggle source

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
gte(input, comparison) click to toggle source

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
input_if(input, value) click to toggle source

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
input_unless(input, value) click to toggle source

{{ 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
lt(input, comparison) click to toggle source

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
lte(input, comparison) click to toggle source

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
not(input, comparison) click to toggle source

The two values must be different

   # File lib/jekyll/filters/assertion.rb
20 def not(input, comparison)
21   input != comparison
22 end
presence(input) click to toggle source

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
present(input) click to toggle source

The opposite of blank

{{ post.title | present }} => true

    # File lib/jekyll/filters/assertion.rb
133 def present(input)
134   !blank(input)
135 end
ternary(input, value, alternative) click to toggle source

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
value_if(input, value) click to toggle source

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
value_unless(input, value) click to toggle source

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