Class: LiquidBlocks::Block

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/liquid_blocks/block.rb

Constant Summary collapse

Syntax =
/([\w!]+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ Block

Returns a new instance of Block.



19
20
21
22
23
24
25
26
27
# File 'lib/liquid_blocks/block.rb', line 19

def initialize(tag_name, markup, tokens)
  if markup =~ Syntax
    @name = $1
  else
    raise Liquid::SyntaxError.new("Syntax Error in 'block' - Valid syntax: block [name]")
  end

  super if tokens
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/liquid_blocks/block.rb', line 17

def name
  @name
end

#parentObject

Returns the value of attribute parent.



16
17
18
# File 'lib/liquid_blocks/block.rb', line 16

def parent
  @parent
end

Instance Method Details

#add_parent(nodelist) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/liquid_blocks/block.rb', line 37

def add_parent(nodelist)
  if parent
    parent.add_parent(nodelist)
  else
    begin
      self.parent = Block.parse(@tag_name, @name, nodelist, {})
    rescue
    end
    if parent != nil
      parent.nodelist = nodelist
    end
  end
end

#blank?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/liquid_blocks/block.rb', line 55

def blank?
  false
end

#call_super(context) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/liquid_blocks/block.rb', line 59

def call_super(context)
  if parent
    parent.render(context)
  else
    ''
  end
end

#nodelist=(list) ⇒ Object



51
52
53
# File 'lib/liquid_blocks/block.rb', line 51

def nodelist=(list)
  @nodelist = list
end

#render(context) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/liquid_blocks/block.rb', line 29

def render(context)
  context.stack do
    context['block'] = BlockDrop.new(self)

    render_all(@nodelist, context)
  end
end