Class: Jekyll::EvalAssignTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll/tags/eval_assign.rb

Constant Summary collapse

Syntax =
/([^\s]*)\s*=\s*(.*)/

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ EvalAssignTag

Returns a new instance of EvalAssignTag.



5
6
7
8
9
10
11
12
13
# File 'lib/jekyll/tags/eval_assign.rb', line 5

def initialize(tag_name, markup, tokens)
  if markup =~ Syntax
    @to = $1.to_s.chomp
    @from = $2
  else
    raise SyntaxError.new("SyntaxError in 'evalassign' - Valid syntax: evalassign [var] = [ruby expression]")
  end
  super
end

Instance Method Details

#render(context) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/jekyll/tags/eval_assign.rb', line 15

def render(context)
  post = context.scopes[0]["post"] if context.scopes[0]
  site = context.scopes[1]["site"] if context.scopes[1]
  page = context.scopes[1]["page"] if context.scopes[1]
  context.scopes.last[@to.to_s.chomp] = eval(@from)
  ""
end