Module: RailsBootstrapHelpers::Helpers::LabelHelper

Includes:
OptionsHelper
Defined in:
lib/rails-bootstrap-helpers/helpers/label_helper.rb

Instance Method Summary collapse

Methods included from OptionsHelper

#bs_options

Instance Method Details

#bs_label(text, style = :default, options = {}) ⇒ Object

Renders a Bootstrap label.

Parameters:

  • text (String)

    the text rendered in the label

  • style (Symbol, Symbol) (defaults to: :default)

    the style used to render the label

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

    a hash of options. Passed straight through to the underlying “span” tag.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails-bootstrap-helpers/helpers/label_helper.rb', line 11

def bs_label (text, style = :default, options = {})
  normalize_style = lambda do |style|
    style = style.to_s

    case style
      when "inactive" then "default"
      when "active" then "success"
      when "error" then "important"
    else
      style
    end
  end

  options = options.dup
  style = normalize_style.call(style)

  cls = options[:class]
  cls ||= "label"
  cls << " label-" + style unless style == "default"

  options[:class] = cls

   :span, text, bs_options(options)
end