Class: Admin::BadgeComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
lib/generators/infold/templates/install/app/components/admin/badge_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, color) ⇒ BadgeComponent

Returns a new instance of BadgeComponent.



5
6
7
8
# File 'lib/generators/infold/templates/install/app/components/admin/badge_component.rb', line 5

def initialize(name, color)
  @name = name
  @color = color
end

Instance Method Details

#badge_classObject



10
11
12
# File 'lib/generators/infold/templates/install/app/components/admin/badge_component.rb', line 10

def badge_class
  "badge bg-#{@color}" if @color.present?
end

#callObject



14
15
16
# File 'lib/generators/infold/templates/install/app/components/admin/badge_component.rb', line 14

def call
  "<span class=\"#{badge_class}\">#{@name}</span>".html_safe if @name.present?
end