Module: BootstrapHelper

Defined in:
app/helpers/bootstrap_helper.rb

Overview

View helper: bootstrap.

Instance Method Summary collapse

Instance Method Details

#helper_icon(content, options = {}) ⇒ String?

Renders a help icon that shows the given content in a Bootstrap popover

Parameters:

  • content (String)

    popover body text

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

    icon and popover configuration

Options Hash (options):

  • :icon (String)

    Font Awesome icon name (default: "question-circle")

  • :icon_options (Hash)

    options forwarded to +fa_icon+

  • :tabindex (Integer, String)

    tabindex attribute (default: 0)

  • :class (String)

    CSS classes for the link

  • :title (String)

    title attribute (default: "info")

  • :placement (String)

    popover placement (default: "bottom")

Returns:

  • (String, nil)

    HTML for the icon, or nil when content is blank



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/bootstrap_helper.rb', line 14

def helper_icon(content, options = {})
  return if content.blank?

  icon = options[:icon] || "question-circle"
  icon_options = options[:icon_options] || {}
  tag.a(tabindex: options[:tabindex] || 0,
        class: options[:class],
        role: "button",
        title: options[:title] || "info",
        data: {
          'bs-toggle': 'popover',
          'bs-trigger': 'focus',
          'bs-placement': options[:placement] || 'bottom',
          'bs-content': content
        }) do
          fa_icon(icon, icon_options)
        end
end