Class: JekyllBlocker::BlockContainerTag

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll-blocker/tags/block_container_tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, params, parse_context) ⇒ BlockContainerTag

Returns a new instance of BlockContainerTag.



3
4
5
6
7
8
9
10
11
12
# File 'lib/jekyll-blocker/tags/block_container_tag.rb', line 3

def initialize(tag_name, params, parse_context)
  super
  parts = params.to_s.strip.split.compact
  if parts.count == 1
    @name = parts.first
  else
    msg = "block_container tag expects 1 argument, #{parts.count} given"
    raise Liquid::SyntaxError, msg
  end
end

Instance Method Details

#render(context) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-blocker/tags/block_container_tag.rb', line 14

def render(context)
  blocks           = context.registers[:site].config["blocks"]
  block_containers = context.registers[:page]["block_containers"] || {}
  block_container = block_containers[@name] ||
                    super.split.map do |block|
                      { "type" => block, "fields" => {} }
                    end


  out = ""
  block_container.each do |block|
    out << blocks.find(block["type"]).render(block["fields"], context)
  end
  out
end