Class: Bootstrap4Helper::Badge

Inherits:
Component show all
Defined in:
lib/bootstrap4_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, #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: {})


12
13
14
15
16
17
18
19
# 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

Instance Method Details

#to_sObject

String representation of the object.



24
25
26
# File 'lib/bootstrap4_helper/badge.rb', line 24

def to_s
  (config(:badge, :span), id: @id, class: container_class) { @content.call(self) }
end