module Padrino::Helpers::OutputHelpers

def self.handlers

Other tags:
    Private: -
def self.handlers
  @_template_handlers ||= []
end

def self.included(base) # @private

Other tags:
    Private: -
def self.included(base) # @private
  base.send(:include, SinatraCurrentEngine) unless base.method_defined?(:current_engine)
end

def self.register(handler)

Other tags:
    Private: -
def self.register(handler)
  handlers << handler
end

def block_is_template?(block)

Other tags:
    Api: - semipublic

Returns:
  • (Boolean) - True if the block is a template; false otherwise.

Parameters:
  • block (Block) --
def block_is_template?(block)
  handler = find_proper_handler
  block && handler && handler.block_is_type?(block)
end

def capture_html(*args, &block)

Other tags:
    Api: - semipublic

Returns:
  • (String) - Captured html resulting from the block

Parameters:
  • &block (Proc) --
  • *args (Object) --
def capture_html(*args, &block)
  handler = find_proper_handler
  captured_block, captured_html = nil, ""
  if handler && handler.is_type? && handler.block_is_type?(block)
    captured_html, captured_block = handler.capture_from_template(*args, &block)
  end
  # invoking the block directly if there was no template
  captured_html = block_given? && ( captured_block || block.call(*args) )  if captured_html.blank?
  captured_html
end

def concat_content(text="")

Other tags:
    Api: - semipublic

Parameters:
  • text (String, SafeBuffer) --
def concat_content(text="")
  handler = find_proper_handler
  if handler && handler.is_type?
    handler.concat_to_template(text)
  else # theres no template to concat, return the text directly
    text
  end
end

def concat_safe_content(text="")

Other tags:
    Api: - semipublic

Parameters:
  • text (String) --
def concat_safe_content(text="")
  concat_content text.html_safe
end

def content_blocks


content_blocks[:name] => ['...', '...']
@example

Retrieves content_blocks stored by content_for or within yield_content
#
def content_blocks
  @content_blocks ||= Hash.new { |h,k| h[k] = [] }
end

def content_for(key, content = nil, &block)

Other tags:
    Api: - public

Parameters:
  • block (Proc) -- Block to be stored as content for this key.
  • key (Symbol) -- Name of your key for the content yield.
  • content (String) -- Text to be stored for this key.
  • key (Symbol) -- Name of your key for the content yield.

Overloads:
  • content_for(key, &block)
  • content_for(key, content)
def content_for(key, content = nil, &block)
  content_blocks[key.to_sym] << (block_given? ? block : Proc.new { content })
end

def content_for?(key)

Other tags:
    Api: - public

Returns:
  • (TrueClass, FalseClass) - Result html for the given +key+

Parameters:
  • key (Symbol) --
def content_for?(key)
  content_blocks[key.to_sym].present?
end

def find_proper_handler


find_proper_handler =>
@example

Can handle any output related to capturing or concating in a given template.
Retrieves the template handler for the given output context.
#
def find_proper_handler
  OutputHelpers.handlers.map { |h| h.new(self) }.find { |h| h.engines.include?(current_engine) && h.is_type? }
end

def mark_safe(value)

Returns:
  • (ActiveSupport::SafeBuffer, Array) -

Parameters:
  • the (String, Array) -- values to be marked safe.
def mark_safe(value)
  if value.respond_to? :map!
    value.map!{|v| v.html_safe if v }
  else
    value.html_safe if value
  end
end

def yield_content(key, *args)

Other tags:
    Api: - public

Returns:
  • (String) - Result html for the given +key+

Parameters:
  • *args () --
  • key (Symbol) --
def yield_content(key, *args)
  blocks = content_blocks[key.to_sym]
  return nil if blocks.empty?
  mark_safe(blocks.map { |content| capture_html(*args, &content) }.join)
end