Class: StupidFormatter::Erb

Inherits:
AbstractFormatter show all
Defined in:
lib/stupid_formatter.rb

Instance Attribute Summary

Attributes inherited from AbstractFormatter

#input

Instance Method Summary collapse

Methods inherited from AbstractFormatter

#initialize

Constructor Details

This class inherits a constructor from StupidFormatter::AbstractFormatter

Instance Method Details

#captureObject

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