Class: JekyllBlocker::BlockTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- JekyllBlocker::BlockTag
- Defined in:
- lib/jekyll-blocker/tags/block_tag.rb
Instance Method Summary collapse
-
#initialize(tag_name, params, parse_context) ⇒ BlockTag
constructor
A new instance of BlockTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, params, parse_context) ⇒ BlockTag
Returns a new instance of BlockTag.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/jekyll-blocker/tags/block_tag.rb', line 3 def initialize(tag_name, params, parse_context) super parts = params.to_s.strip.split.compact if parts.count == 1 @name = @id = parts.first.strip elsif parts.count == 2 @name = parts.first @id = parts.last else raise Liquid::SyntaxError, "block tag expects 1..2 arguments, #{parts.count} given" end end |
Instance Method Details
#render(context) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/jekyll-blocker/tags/block_tag.rb', line 17 def render(context) blocks = context.registers[:site].config["blocks"] page_blocks = context.registers[:page]["blocks"] || {} block = page_blocks[@id] || { "type" => @name, "fields" => {} } raise BlockerError unless @name == block["type"] blocks.find(@name).render(block["fields"], context) end |