W3cubDocs

/Padrino

Module: Padrino::Helpers::OutputHelpers

Overview

Helpers related to buffer output for various template engines.

Defined Under Namespace

Modules: SinatraCurrentEngine Classes: AbstractHandler, ErbHandler, HamlHandler, HamlitHandler, SlimHandler

Class Method Summary

Instance Method Summary

Class Method Details

.handlers ⇒ Object

Returns the list of all available template handlers.

.register(engine, handler) ⇒ Object

Registers a new handler as available to the output helpers.

Instance Method Details

#block_is_template?(block) ⇒ Boolean

Returns true if the block is from a supported template type; false otherwise. Used to determine if html should be returned or concatenated to the view.

Examples:

block_is_template?(block) => true

Parameters:

  • block (Block) — Determine if this block is a view template.

Returns:

  • (Boolean) — True if the block is a template; false otherwise.

#capture_html(*args, &block) ⇒ String Also known as: capture

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

Be aware that trusting the html is up to the caller.

Examples:

capture_html(&block) => "...html..."
capture_html(object_for_block, &block) => "...html..."
SafeBuffer.new + capture_html { "<foo>" }
# => "&lt;foo&gt;"
SafeBuffer.new.safe_concat(capture_html { "<foo>" })
# => "<foo>"

Parameters:

  • *args (Object) — Objects yield to the captured block.
  • &block (Proc) — Template code to capture as HTML.

Returns:

  • (String) — Captured HTML resulting from the block.

#concat_content(text = "") ⇒ Object Also known as: concat

Outputs the given text to the templates buffer directly.

The output might be subject to escaping, if it is not marked as safe.

Examples:

concat_content("This will be output to the template buffer")

Parameters:

  • text (String, SafeBuffer) (defaults to: "") — Text to concatenate to the buffer.

#concat_safe_content(text = "") ⇒ Object

Outputs the given text to the templates buffer directly, assuming that it is safe.

Examples:

concat_safe_content("This will be output to the template buffer")

Parameters:

  • text (String) (defaults to: "") — Text to concatenate to the buffer.

#content_for(key, content) ⇒ Object #content_for(key, &block) ⇒ Object

Capture a block or text of content to be rendered at a later time. Your blocks can also receive values, which are passed to them by yield_content.

Examples:

content_for(:name) { ...content... }
content_for(:name) { |name| ...content... }
content_for(:name, "I'm Jeff")
content_for(:name, :flush => true) { ...new content... }

Overloads:

  • #content_for(key, content) ⇒ Object

    Parameters:

    • key (Symbol) — Name of your key for the content yield.
    • content (String) — Text to be stored for this key.
    • options (Hash) — Options associated with this method.
  • #content_for(key, &block) ⇒ Object

    Parameters:

    • key (Symbol) — Name of your key for the content yield.
    • block (Proc) — Block to be stored as content for this key.
    • options (Hash) — Options associated with this method.

Parameters:

  • options (Hash) (defaults to: {}) — a customizable set of options

Options Hash (options):

  • :flush (Boolean) — Specifies whether to replace the content.

#content_for?(key) ⇒ TrueClass, FalseClass

Is there a content block for a given key?

Examples:

content_for? :header => true

Parameters:

  • key (Symbol) — Name of content to yield.

Returns:

  • (TrueClass, FalseClass) — Result html for the given key

#yield_content(key, *args) ⇒ String

Render the captured content blocks for a given key. You can also pass values to the content blocks by passing them as arguments after the key.

Examples:

yield_content :include
yield_content :head, "param1", "param2"
yield_content(:title) || "My page title"

Parameters:

  • key (Symbol) — Name of content to yield.
  • *args — Values to pass to the content block.

Returns:

  • (String) — Result HTML for the given key.