Class: Jekyll::Block::BlockTag

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll-block/block_tag.rb

Overview

A Jekyll Liquid block % block tag that generates HTML for block-styled content. The content of the block can contain Markdown, which will be parsed by kramdown.

Usage:

{% block <type> ["Title"] %}
*Markdown content*
{% endblock %}

The type argument is mandatory, and the title is optional.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ BlockTag

Returns a new instance of BlockTag.



17
18
19
20
21
# File 'lib/jekyll-block/block_tag.rb', line 17

def initialize(tag_name, text, tokens)
  @type, @title = text.match(%r!\s*(\w+)\s+(?:\"(.*)\".*)?!im).captures
  @id = @title ? @type.downcase + ":" + Jekyll::Utils.slugify(@title) : nil
  super
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/jekyll-block/block_tag.rb', line 23

def id
  @id
end

#titleObject (readonly)

Returns the value of attribute title.



23
24
25
# File 'lib/jekyll-block/block_tag.rb', line 23

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



23
24
25
# File 'lib/jekyll-block/block_tag.rb', line 23

def type
  @type
end

Instance Method Details

#render(context) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/jekyll-block/block_tag.rb', line 25

def render(context)
  text = super
  if @title
    "<div class=\"block #{@type}\" id=\"#{@id}\" markdown=\"block\">"\
      "<a class=\"header\" href=\"##{id}\">"\
        "#{@type.capitalize}: #{@title}"\
      "</a>"\
      "\n#{text}\n"\
    "</div>"
  else
    "<div class=\"block #{@type}\" markdown=\"block\">"\
      "<span class=\"header\">#{@type.capitalize}</span>"\
      "\n#{text}\n"\
    "</div>"
  end
end