Class: H2o::Tags::With

Inherits:
Tag show all
Defined in:
lib/h2o/tags/with.rb

Constant Summary collapse

Syntax =
/(#{NAME_RE})\s+as\s+(#{NAME_RE})/

Instance Method Summary collapse

Constructor Details

#initialize(parser, argstring) ⇒ With

Returns a new instance of With.



6
7
8
9
10
11
12
13
14
15
# File 'lib/h2o/tags/with.rb', line 6

def initialize(parser, argstring)
  @body = parser.parse(:endwith)
  
  if argstring =~ Syntax
    @name = $1.to_sym
    @shortcut = $2.to_sym
  else
    raise SyntaxError, "Invalid with syntax "
  end
end

Instance Method Details

#render(context, stream) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/h2o/tags/with.rb', line 17

def render(context, stream)
  object = context.resolve(@name)
  context.stack do
    context[@shortcut] = object
    @body.render(context, stream)
  end
end