Module: Bootstrap::StampHelper

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

Overview

Rails helper for producing Twitter Bootstrap labels. We use #stamp() because #label() is a standard Rails helper method.

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

Examples:

stamp('Default')
stamp('Info', :info)  
stamp('Warning', :warning, id: 'warn-id', class: 'more-class', my_key: 'my_value')

Constant Summary collapse

InvalidStampTypeError =
Class.new(StandardError)
LABEL_TYPES =
%w(default primary success info warning danger)

Instance Method Summary collapse

Instance Method Details

#stamp(text, options = {}) ⇒ String #stamp(text, type, options = {}) ⇒ String

Returns a Bootstrap label

Overloads:

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

    Returns a label of type :default

    Parameters:

    • text (String)

      text of the label

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

      html attributes for returned <span>

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

    Returns a label of type type

    Parameters:

    • text (String)

      text of the label

    • type (Symbol, String)

      type of label see LABEL_TYPES

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

      html attributes for returned <span>

Returns:

  • (String)


30
31
32
33
34
# File 'app/helpers/bootstrap/stamp_helper.rb', line 30

def stamp(*args)
  text = args.shift
  options = add_label_classes(*args)
  (:span, text, options)
end