Class: ERBB::Parser
- Inherits:
-
ERB
- Object
- ERB
- ERBB::Parser
- Defined in:
- lib/erbb/parser.rb
Overview
Parses ERBB files (erb files with #named_block calls in them). Use like you would the ERB class, except instead of passing a binding when getting the result, you pass in an object which will be the implicit receiver for all ruby calls made in the erb template. This object will be decorated with the instance methods in ERBB::Receiver when rendering.
Instance Method Summary collapse
-
#initialize(str, safe_level = nil, trim_mode = '>', eoutvar = nil) ⇒ Parser
constructor
A new instance of Parser.
-
#result(b = new_toplevel) ⇒ ERBB::Result
A string decorated with named blocks.
Constructor Details
#initialize(str, safe_level = nil, trim_mode = '>', eoutvar = nil) ⇒ Parser
Returns a new instance of Parser.
13 14 15 16 17 18 19 |
# File 'lib/erbb/parser.rb', line 13 def initialize(str, safe_level=nil, trim_mode='>', eoutvar=nil) # The fourth arg is the name of the variable defined on the receiver # which is used to store the rendered output when parsing a template. # ERBB works by exploiting that, so it has to control it. raise ArgumentError, "In ERBB, the template ivar can’t be set" if eoutvar super(str, safe_level, trim_mode, Receiver::RENDERED_TEMPLATE) end |
Instance Method Details
#result(b = new_toplevel) ⇒ ERBB::Result
Returns a string decorated with named blocks.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/erbb/parser.rb', line 24 def result(b=new_toplevel) receiver = extract_receiver_from_binding(b) # Render the template using the binding and return the result along with # the output of any named blocks. ERBB::Result.new( super(b), receiver.named_blocks ) end |