Method: Padrino::Helpers::AssetTagHelpers#flash_tag

Defined in:
padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb

#flash_tag(*args) ⇒ String

Creates a div to display the flash of given type if it exists.

Examples:

flash_tag(:notice, :id => 'flash-notice')
# Generates: <div class="notice" id="flash-notice">flash-notice</div>
flash_tag(:error, :success)
# Generates: <div class="error">flash-error</div>
# <div class="success">flash-success</div>

Parameters:

  • kind (Symbol)

    The type of flash to display in the tag.

  • options (Hash)

    The html options for this section. use :bootstrap => true to support Twitter’s bootstrap dismiss alert button.

Returns:

  • (String)

    Flash tag html with specified options.


32
33
34
35
36
37
38
39
40
41
# File 'padrino-helpers/lib/padrino-helpers/asset_tag_helpers.rb', line 32

def flash_tag(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  bootstrap = options.delete(:bootstrap) if options[:bootstrap]
  args.inject(SafeBuffer.new) do |html,kind|
    next html unless flash[kind]
    flash_text = SafeBuffer.new << flash[kind]
    flash_text << (:button, '&times;'.html_safe, {:type => :button, :class => :close, :'data-dismiss' => :alert}) if bootstrap
    html << (:div, flash_text, { :class => kind }.update(options))
  end
end