Module: Bh::ButtonHelper

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

Overview

Provides methods to include buttons.

Instance Method Summary collapse

Instance Method Details

#button(content_or_options_with_block = nil, options = nil, &block) ⇒ String

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

The content of the button 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 button with plain-text content passed as the first parameter.

<%= button 'Your profile was updated!', context: :info %>

A button with HTML content passed as a block.

<%= button context: :info %>
  <%= glyphicon :star %> Star
<% end %>

Parameters:

  • content_or_options_with_block (String) (defaults to: nil)

    the content to display in the button.

  • options (Hash) (defaults to: nil)

    the display options for the button.

Options Hash (options):

  • :context (#to_s) — default: :default

    the contextual alternative to apply to the button depending on its importance. Can be :default, :primary, :success, :info, :warning, :danger or :link.

  • :size (#to_s)

    the size of the button.

  • :layout (#to_s)

    if set to :block, span the button for the full width of the parent.

Returns:

  • (String)

    an HTML block tag for a button.



32
33
34
35
36
37
38
# File 'lib/bh/helpers/button_helper.rb', line 32

def button(content_or_options_with_block = nil, options = nil, &block)
  if block_given?
    button_string capture(&block), content_or_options_with_block || {}
  else
    button_string content_or_options_with_block, options || {}
  end
end