Module: Bootstrap::BadgeHelper

Defined in:
app/helpers/bootstrap/badge_helper.rb

Overview

Rails helper for producing Twitter Bootstrap badges

See: twitter.github.io/bootstrap/components.html#labels-badges

Default badge:

Examples:

badge('Default')

badge('Info', :info)

badge('Warning', :warning, id: 'warn-id', class: 'more-class', my_key: 'my_value')

Constant Summary collapse

InvalidBadgeTypeError =
Class.new(StandardError)
BADGE_TYPES =
%w(default primary success info warning danger)

Instance Method Summary collapse

Instance Method Details

#badge(text, options = {}) ⇒ String #badge(text, badge_type, options = {}) ⇒ String

Returns html for a Bootstrap badge.

Overloads:

  • #badge(text, options = {}) ⇒ String

    Returns html for default badge

    Parameters:

    • text (String)

      Text of badge

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

      Html attributes for badge <span>

  • #badge(text, badge_type, options = {}) ⇒ String

    Returns html for badge of type badge_type

    Parameters:

    • text (String)

      Text of badge

    • badge_type (String, Symbol)

      one of BADGE_TYPES

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

      Html attributes for badge <span>

Returns:

  • (String)

    html for badge

Raises:



32
33
34
35
36
# File 'app/helpers/bootstrap/badge_helper.rb', line 32

def badge(*args)
  text = args.shift
  options = add_badge_classes(*args)
  (:span, text, options)
end