class Bootstrap4Helper::Badge

Creates Bootstrap badge components that can be used anywhere.

Public Class Methods

new(template, context_or_options = nil, opts = {}, &block) click to toggle source

Class constructor

@param [ActionView] template @param [NilClass|String|Symbol|Hash] context_or_options @param [Hash] opts

Calls superclass method
# File lib/bootstrap4_helper/badge.rb, line 12
def initialize(template, context_or_options = nil, opts = {}, &block)
  super(template)
  @context, args = parse_arguments(context_or_options, opts)

  @id      = args.fetch(:id,    nil)
  @class   = args.fetch(:class, '')
  @content = block || proc { '' }
end

Public Instance Methods

to_s() click to toggle source

String representation of the object.

# File lib/bootstrap4_helper/badge.rb, line 24
def to_s
  content_tag(config(:badge, :span), id: @id, class: container_class) { @content.call(self) }
end

Private Instance Methods

container_class() click to toggle source

Used to get the container classes.

@return [String]

# File lib/bootstrap4_helper/badge.rb, line 34
def container_class
  string = 'badge '
  string += @context == 'secondary' ? 'badge-secondary' : "badge-#{@context}"
  string += " #{@class}"
  string
end