Module: RailsBootstrapHelpers::Helpers::OptionsHelper

Included in:
LabelHelper
Defined in:
lib/rails-bootstrap-helpers/helpers/options_helper.rb

Instance Method Summary collapse

Instance Method Details

#bs_options(options, html_options = {}) ⇒ Object

Handles general Bootstrap options available for all Bootstrap helpers.

Any option not specify below are kept intact.

Options

Parameters:

  • options (Hash)

    a hash of options

  • html_options (Hash) (defaults to: {})

    a hash of HTML options/attributes

  • :tooltip (String)

    the text of the tooltip. IF present adds attributes for a Bootstrap tooltip. This will add the data-toggle="tooltip" and title="#{tooltip}" HTML attributes if not already present

  • :tooltip_location ("left", "right", "top", "bottom")

    the position of the tooltip if :tooltip is present. Adds the data-placement="#{tooltip_position}" HTML attribute if not already present.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails-bootstrap-helpers/helpers/options_helper.rb', line 18

def bs_options (options, html_options = {})
  options = options.reverse_merge(html_options)

  if tooltip = options.delete(:tooltip)
    options[:"data-toggle"] ||= "tooltip"
    options[:title] ||= tooltip

    if tooltip_position = options.delete(:tooltip_position)
      options[:"data-placement"] ||= tooltip_position
    end
  end

  options
end