Class: Bootstrap5Helper::Badge

Inherits:
Component show all
Defined in:
lib/bootstrap5_helper/badge.rb

Overview

Creates Bootstrap badge components that can be used anywhere.

Instance Method Summary collapse

Methods inherited from Component

#capture, #concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #parse_text_or_options, #uuid

Constructor Details

#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Badge

Class constructor

Parameters:

  • template (ActionView)
  • context_or_options (NilClass|String|Symbol|Hash) (defaults to: nil)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :id (String)
  • :class (String)
  • : (Hash)

    :data



15
16
17
18
19
20
21
22
23
# File 'lib/bootstrap5_helper/badge.rb', line 15

def initialize(template, context_or_options = nil, opts = {}, &block)
  super(template)
  @context, args = parse_context_or_options(context_or_options, opts)

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

Instance Method Details

#to_sString

String representation of the object.

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
38
# File 'lib/bootstrap5_helper/badge.rb', line 29

def to_s
  (
    config({ badges: :base }, :span),
    id:    @id,
    class: container_class,
    data:  @data
  ) do
    @content.call(self)
  end
end