Class: Padrino::Helpers::OutputHelpers::ErbHandler
- Inherits:
-
AbstractHandler
- Object
- AbstractHandler
- Padrino::Helpers::OutputHelpers::ErbHandler
- Defined in:
- lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/erb_handler.rb,
lib/middleman-more/core_extensions/default_helpers.rb
Overview
Handler for reading and writing from an erb template.
Instance Attribute Summary collapse
-
#output_buffer ⇒ Object
readonly
Returns the value of attribute output_buffer.
Attributes inherited from AbstractHandler
Instance Method Summary collapse
-
#block_is_type?(block) ⇒ Boolean
Returns true if the block given is of the handler’s template type; false otherwise.
-
#capture_from_template(*args, &block) ⇒ Object
Force Erb capture not to use safebuffer.
-
#concat_to_template(text = "") ⇒ Object
Outputs the given text to the templates buffer directly.
-
#engines ⇒ Object
Returns an array of engines used for the template.
-
#initialize(template) ⇒ ErbHandler
constructor
A new instance of ErbHandler.
-
#is_type? ⇒ Boolean
Returns true if the current template type is same as this handlers; false otherwise.
Methods inherited from AbstractHandler
Constructor Details
#initialize(template) ⇒ ErbHandler
Returns a new instance of ErbHandler.
10 11 12 13 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/erb_handler.rb', line 10 def initialize(template) super @output_buffer = template.instance_variable_get(:@_out_buf) end |
Instance Attribute Details
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
8 9 10 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/erb_handler.rb', line 8 def output_buffer @output_buffer end |
Instance Method Details
#block_is_type?(block) ⇒ Boolean
Returns true if the block given is of the handler’s template type; false otherwise.
55 56 57 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/erb_handler.rb', line 55 def block_is_type?(block) is_type? || (block && eval('defined?(__in_erb_template)', block.binding)) end |
#capture_from_template(*args, &block) ⇒ Object
Force Erb capture not to use safebuffer
30 31 32 33 34 35 36 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/erb_handler.rb', line 30 def capture_from_template(*args, &block) self.output_buffer, _buf_was = ActiveSupport::SafeBuffer.new, self.output_buffer captured_block = block.call(*args) ret = eval("@_out_buf", block.binding) self.output_buffer = _buf_was [ ret, captured_block ] end |
#concat_to_template(text = "") ⇒ Object
Outputs the given text to the templates buffer directly
44 45 46 47 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/erb_handler.rb', line 44 def concat_to_template(text="") self.output_buffer << text if is_type? && text nil end |
#engines ⇒ Object
Returns an array of engines used for the template
65 66 67 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/erb_handler.rb', line 65 def engines @_engines ||= [:erb, :erubis] end |
#is_type? ⇒ Boolean
Returns true if the current template type is same as this handlers; false otherwise.
21 22 23 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/erb_handler.rb', line 21 def is_type? !self.output_buffer.nil? end |