Class: StupidFormatter::Erb
- Inherits:
-
AbstractFormatter
- Object
- AbstractFormatter
- StupidFormatter::Erb
- Defined in:
- lib/stupid_formatter.rb
Instance Attribute Summary
Attributes inherited from AbstractFormatter
Instance Method Summary collapse
-
#capture ⇒ Object
Helper for capturing output in a erb block for later use, i.e.
- #result(alternative_binding = nil) ⇒ Object
Methods inherited from AbstractFormatter
Constructor Details
This class inherits a constructor from StupidFormatter::AbstractFormatter
Instance Method Details
#capture ⇒ Object
Helper for capturing output in a erb block for later use, i.e.
<% @my_var = capture do %>
Bar
<% end %>
Foo<%= @my_var %>
will render FooBar.
72 73 74 75 76 77 78 |
# File 'lib/stupid_formatter.rb', line 72 def capture old_buffer, @output_buffer = @output_buffer, '' yield @output_buffer ensure @output_buffer = old_buffer end |
#result(alternative_binding = nil) ⇒ Object
61 62 63 |
# File 'lib/stupid_formatter.rb', line 61 def result(alternative_binding=nil) ERB.new(input, 0, "%<>", "@output_buffer").result(alternative_binding || binding) end |