Class: LiquidPlus::WrapTag

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/jekyll-liquid-plus/tags/wrap.rb

Constant Summary collapse

HAS_CONTENT =
/(.*?)({=\s*yield\s*})(.*)/im

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ WrapTag

Returns a new instance of WrapTag.



7
8
9
10
11
# File 'lib/jekyll-liquid-plus/tags/wrap.rb', line 7

def initialize(tag_name, markup, tokens)
  @tag = tag_name
  @markup = markup.strip
  super
end

Instance Method Details

#render(context) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jekyll-liquid-plus/tags/wrap.rb', line 13

def render(context)
  if super.strip =~ HAS_CONTENT
    front = $1
    back = $3

    partial = if @tag == 'wrap'
      tag = IncludeTag.new('render', @markup, [])
      tag.render(context)
    elsif @tag == 'wrap_include'
      Include.render(@markup, context)
    end

    if partial
      front + partial.strip + back
    else
      ''
    end
  else
    raise SyntaxError.new("Syntax Error in '#{@tag}' - Valid syntax: {% wrap_include template/file.html %}\n[<div>]{= yield }[</div>]\n{% end#{@tag} %}")
  end
end