Class: Padrino::Helpers::OutputHelpers::AbstractHandler

### Home Classes Methods

### In Files

- lib/padrino-helpers/output_helpers/abstract_handler.rb

### Parent

Object

### Methods

- ::new
- #capture_from_template
- #concat_to_template
- #engine_matches?
- #output_buffer=

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Helpers
- Padrino::Helpers::AssetTagHelpers
- Padrino::Helpers::FormBuilder
- Padrino::Helpers::FormBuilder::AbstractFormBuilder
- Padrino::Helpers::FormBuilder::DeprecatedBuilderMethods
- Padrino::Helpers::FormBuilder::StandardFormBuilder
- Padrino::Helpers::FormHelpers
- Padrino::Helpers::FormHelpers::Errors
- Padrino::Helpers::FormHelpers::Options
- Padrino::Helpers::FormHelpers::Security
- Padrino::Helpers::NumberHelpers
- Padrino::Helpers::OutputHelpers
- Padrino::Helpers::OutputHelpers::AbstractHandler
- Padrino::Helpers::OutputHelpers::ErbHandler
- Padrino::Helpers::OutputHelpers::HamlHandler
- Padrino::Helpers::OutputHelpers::SinatraCurrentEngine
- Padrino::Helpers::OutputHelpers::SlimHandler
- Padrino::Helpers::RenderHelpers
- Padrino::Helpers::TagHelpers
- Padrino::Helpers::TranslationHelpers
- Padrino::Rendering
- Padrino::Rendering::ClassMethods
- Padrino::Rendering::ErubisTemplate
- Padrino::Rendering::HamlTemplate
- Padrino::Rendering::InstanceMethods
- Padrino::Rendering::SafeBufferEnhancer
- Padrino::Rendering::SafeEruby
- Padrino::Rendering::SafeTemplate
- Padrino::Rendering::SlimTemplate
- Padrino::Rendering::TemplateNotFound
- Haml
- Haml::Helpers
- Haml::Util

No matching classes.

# Padrino::Helpers::OutputHelpers::AbstractHandler

### Attributes

output_buffer[R]
template[R]

### Public Class Methods

new(template) click to toggle source

    # File lib/padrino-helpers/output_helpers/abstract_handler.rb, line 7
    def initialize(template)
      @template = template
      @output_buffer = template.instance_variable_get(:@_out_buf)
    end

### Public Instance Methods

capture_from_template(*args, &block) click to toggle source

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

This method is called to capture content of a block-loving helpers in templates. Haml has a special method to do this, for Erb and Slim we save original buffer, call the block and then restore the buffer.

@example

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

    # File lib/padrino-helpers/output_helpers/abstract_handler.rb, line 31
    def capture_from_template(*args, &block)
      self.output_buffer, _buf_was = ActiveSupport::SafeBuffer.new, self.output_buffer
      raw = yield(*args)
      captured = template.instance_variable_get(:@_out_buf)
      self.output_buffer = _buf_was
      engine_matches?(block) && !captured.empty? ? captured : raw.to_s
    end

concat_to_template(text="") click to toggle source

Outputs the given text to the template.

This method is called when template uses block-aware helpers. For Slim and Haml such helpers just return output to use with `=`. For Erb this method is implemented in ErbHandler by concatenating given text to output buffer.

@example

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

    # File lib/padrino-helpers/output_helpers/abstract_handler.rb, line 49
    def concat_to_template(text="")
      text
    end

engine_matches?(block) click to toggle source

Returns true if the block given is of the handler's template type; false otherwise.

@example

    @handler.engine_matches?(block) => true

    # File lib/padrino-helpers/output_helpers/abstract_handler.rb, line 18
    def engine_matches?(block)
    end

### Protected Instance Methods

output_buffer=(val) click to toggle source

    # File lib/padrino-helpers/output_helpers/abstract_handler.rb, line 55
    def output_buffer=(val)
      template.instance_variable_set(:@_out_buf, val)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.