Class: Solid::ConditionalBlock

Inherits:
Liquid::Block
  • Object
show all
Includes:
Element
Defined in:
lib/solid/conditional_block.rb

Instance Method Summary collapse

Methods included from Element

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

Constructor Details

#initialize(tag_name, variable, tokens, context = {}) ⇒ ConditionalBlock

Returns a new instance of ConditionalBlock.



4
5
6
7
8
# File 'lib/solid/conditional_block.rb', line 4

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

Instance Method Details

#render(context) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/solid/conditional_block.rb', line 10

def render(context)
  with_context(context) do
    display(*arguments.interpolate(context)) do |condition_satisfied|
      block = condition_satisfied ? @blocks.first : @blocks[1]
      render_all(block, context) if block
    end
  end
end

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



19
20
21
22
23
24
25
# File 'lib/solid/conditional_block.rb', line 19

def unknown_tag(tag, markup, tokens, context = {})
  if tag == 'else'
    push_block!
  else
    super
  end
end