Class: Jekyll::UJPowertools::IfFalsyTag

Inherits:
Liquid::Block
  • Object
show all
Includes:
VariableResolver
Defined in:
lib/tags/iffalsy.rb

Instance Method Summary collapse

Methods included from VariableResolver

#is_quoted?, #parse_arguments, #parse_options, #resolve_input, #resolve_variable

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ IfFalsyTag

Returns a new instance of IfFalsyTag.



10
11
12
13
# File 'lib/tags/iffalsy.rb', line 10

def initialize(tag_name, markup, tokens)
  super
  @variable = markup.strip
end

Instance Method Details

#render(context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tags/iffalsy.rb', line 15

def render(context)
  # Use the helper to resolve input (handles both literals and variables)
  value = resolve_input(context, @variable)

  # Check if the value is falsy (nil, false, empty string, or 0)
  if value.nil? || value == false || value == "" || value == 0
    super
  else
    ""
  end
end