Class: Super::Badge
- Inherits:
-
Object
- Object
- Super::Badge
- Defined in:
- lib/super/badge.rb
Constant Summary collapse
- STYLES =
{ light: "bg-gray-100 text-black", dark: "bg-gray-900 text-white", red: "bg-red-700 text-white", yellow: "bg-yellow-400 text-black", green: "bg-green-700 text-white", blue: "bg-blue-700 text-white", purple: "bg-purple-800 text-white" }
Instance Method Summary collapse
-
#initialize(text, style:) ⇒ Badge
constructor
A new instance of Badge.
- #styles ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(text, style:) ⇒ Badge
Returns a new instance of Badge.
15 16 17 18 19 20 21 22 |
# File 'lib/super/badge.rb', line 15 def initialize(text, style:) if !STYLES.key?(style) raise Super::Error::Initialization, "`style:` must be one of #{STYLES.keys.inspect}" end @text = text @style = style end |
Instance Method Details
#styles ⇒ Object
24 25 26 27 28 |
# File 'lib/super/badge.rb', line 24 def styles return @styles if instance_variable_defined?(:@styles) @styles = COMMON_STYLES + [STYLES.fetch(@style)] end |
#to_s ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/super/badge.rb', line 30 def to_s ActionController::Base.helpers.content_tag( :span, @text, class: styles.join(" ") ) end |