Class: Solid::LiquidExtensions::IfTag

Inherits:
Liquid::Block
  • Object
show all
Extended by:
TagHighjacker
Includes:
Element
Defined in:
lib/solid/liquid_extensions/if_tag.rb

Direct Known Subclasses

UnlessTag

Instance Method Summary collapse

Methods included from TagHighjacker

load!, tag_name, unload!

Methods included from Element

#arguments, #current_context, #display, included, #with_context

Constructor Details

#initialize(tag_name, expression, tokens, context = {}) ⇒ IfTag

Returns a new instance of IfTag.



9
10
11
12
13
# File 'lib/solid/liquid_extensions/if_tag.rb', line 9

def initialize(tag_name, expression, tokens, context = {})
  @blocks = []
  push_block!(expression)
  super
end

Instance Method Details

#render(context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/solid/liquid_extensions/if_tag.rb', line 15

def render(context)
  with_context(context) do
    @blocks.each do |expression, blocks|
      if expression.evaluate(context)
        return render_all(blocks, context)
      end
    end
  end
  ''
end

#unknown_tag(tag, expression, tokens, context = {}) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/solid/liquid_extensions/if_tag.rb', line 26

def unknown_tag(tag, expression, tokens, context = {})
  if tag == 'elsif'
    push_block!(expression)
  elsif tag == 'else'
    push_block!('true')
  end
end