Class: Padrino::Helpers::OutputHelpers::ErbHandler

Inherits:
AbstractHandler show all
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

Attributes inherited from AbstractHandler

#template

Instance Method Summary collapse

Methods inherited from AbstractHandler

#template_extension

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_bufferObject

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.

Examples:

@handler.block_is_type?(block) => true

Returns:

  • (Boolean)


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

Examples:

@handler.concat_to_template("This will be output to the template buffer")


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

#enginesObject

Returns an array of engines used for the template

Examples:

@handler.engines => [:erb, :erubis]


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.

Examples:

@handler.is_type? => true

Returns:

  • (Boolean)


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