Module: RailsBootstrapHelpers::Helpers::OptionsHelper

Included in:
BaseHelper, ButtonHelper, LabelHelper, NavigationHelper
Defined in:
lib/rails-bootstrap-helpers/helpers/options_helper.rb

Instance Method Summary collapse

Instance Method Details

#append_class!(options, *new_classes) ⇒ Object

Appends the given classes on the given options hash.

It will look for both the “class” and :class key. This will create a new :class key in the given hash if neither exist.

Parameters:

  • options (Hash)

    hash of options to append the classes to

  • new_classes (Array<String>)

    the classes to append

Returns:

  • options



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rails-bootstrap-helpers/helpers/options_helper.rb', line 40

def append_class! (options, *new_classes)
  return options if new_classes.empty?
  key = options.key?("class") ? "class" : :class
  cls = options[key].to_s || ""

  if cls.present? && new_classes.first.present?
    cls << " "
  end

  cls << new_classes.join(" ")
  options[key] = cls
  options
end

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

Handles general Bootstrap options available for all Bootstrap helpers.

Any option not specify below are kept intact.

Parameters:

  • options (Hash)

    a hash of options

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

    a hash of HTML options/attributes

  • option (Hash)

    a customizable set of options

Options Hash (options):

  • :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.



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

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