Class: Liquid::ContentFor

Inherits:
Block
  • Object
show all
Defined in:
lib/jekyll/quickstart/content_for_tag.rb

Overview

content_for sidebar %

  Monkeys!
{% endcontent_for %}
...
<h1>{{ content_for_sidebar }}</h1>

Constant Summary collapse

Syntax =
/(\w+)/

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ ContentFor

Returns a new instance of ContentFor.



15
16
17
18
19
20
21
22
23
# File 'lib/jekyll/quickstart/content_for_tag.rb', line 15

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

  super
end

Instance Method Details

#render(context) ⇒ Object



25
26
27
28
29
30
# File 'lib/jekyll/quickstart/content_for_tag.rb', line 25

def render(context)
  output = super
  name = "content_for_#{@to}"
  (context.environments.first[name] ||= "") << output
  ''
end