Module: Bh::ModalHelper

Includes:
BaseHelper
Defined in:
lib/bh/helpers/modal_helper.rb

Overview

Provides methods to include modals.

Instance Method Summary collapse

Instance Method Details

Returns an HTML block tag that follows the Bootstrap documentation on how to display modals.

The content of the modal can either be passed as the first parameter (in which case, the options are the second parameter), or as a block (in which case, the options are the first paramter).

Examples:

An modal with plain-text content passed as the first parameter.

modal 'Your profile was updated!', context: :info, title: 'Profile'

A panel with HTML content passed as a block.

modal context: :info, title: 'Profile' do
   :div, "Your profile was updated!", class: 'modal-footer'
end

Parameters:

  • content_or_options_with_block (String) (defaults to: nil)

    the content to display in the panel.

  • options (Hash) (defaults to: nil)

    the display options for the panel.

Options Hash (options):

  • :title (#to_s) — default: 'Modal'

    the title to display inside the modal.

  • :body (#to_s)

    if present, the panel will include the provided text wrapped in a ‘modal-body’ block, for proper padding

  • :size (#to_s)

    the size of the modal.

  • :button (Hash)

    the options for the “toggle” button.

    • :caption (#to_s) (‘Modal’) the caption for the “toggle” button.

    • :context (#to_s) (:default) the context for the “toggle” button, which determines the button color

    • :size (#to_s) the size of the “toggle” button.

Returns:

  • (String)

    an HTML block tag for a panel.

See Also:



36
37
38
39
40
41
42
43
44
# File 'lib/bh/helpers/modal_helper.rb', line 36

def modal(content_or_options_with_block = nil, options = nil, &block)
  if block_given?
    modal_string content_or_options_with_block, &block
  elsif content_or_options_with_block.is_a?(Hash) && options.nil?
    modal_string content_or_options_with_block, &Proc.new { nil }
  else
    modal_string options, &Proc.new { content_or_options_with_block }
  end
end