Class: Padrino::Helpers::OutputHelpers::SlimHandler

Inherits:
AbstractHandler show all
Defined in:
lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/slim_handler.rb

Overview

Handler for reading and writing from a slim template.

Instance Attribute Summary collapse

Attributes inherited from AbstractHandler

#template

Instance Method Summary collapse

Methods inherited from AbstractHandler

#template_extension

Constructor Details

#initialize(template) ⇒ SlimHandler

Returns a new instance of SlimHandler.



12
13
14
15
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/slim_handler.rb', line 12

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.



10
11
12
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/slim_handler.rb', line 10

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)


57
58
59
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/slim_handler.rb', line 57

def block_is_type?(block)
  is_type? || (block && eval('defined? __in_erb_template', block.binding))
end

#capture_from_template(*args, &block) ⇒ Object

Captures the html from a block of template code for this handler

Examples:

@handler.capture_from_template(&block) => "...html..."


32
33
34
35
36
37
38
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/slim_handler.rb', line 32

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")


46
47
48
49
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/slim_handler.rb', line 46

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]


67
68
69
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/slim_handler.rb', line 67

def engines
  @_engines ||= [:slim]
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)


23
24
25
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/output_helpers/slim_handler.rb', line 23

def is_type?
  !self.output_buffer.nil?
end