Class: Jekyll::UJPowertools::IfTruthyTag
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Jekyll::UJPowertools::IfTruthyTag
- Defined in:
- lib/tags/iftruthy.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ IfTruthyTag
constructor
A new instance of IfTruthyTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ IfTruthyTag
Returns a new instance of IfTruthyTag.
8 9 10 11 |
# File 'lib/tags/iftruthy.rb', line 8 def initialize(tag_name, markup, tokens) super @variable = markup.strip end |
Instance Method Details
#render(context) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tags/iftruthy.rb', line 13 def render(context) # Use Liquid's variable lookup to handle nested properties value = context.scopes.last[@variable] || context[@variable] # For nested properties like page.my.variable if @variable.include?('.') parts = @variable.split('.') value = context[parts.first] parts[1..-1].each do |part| value = value.is_a?(Hash) ? value[part] : nil break if value.nil? end end # Check if the value is truthy (not nil, not false, not empty string, not 0) if value && value != false && value != "" && value != 0 super else "" end end |