Class: Phlexi::Menu::Badge

Inherits:
COMPONENT_BASE
  • Object
show all
Defined in:
lib/phlexi/menu/badge.rb

Overview

A component for rendering badge elements in menus

Examples:

Basic usage

Badge.new("New!", class: "badge-primary")

With custom styling

Badge.new("2", class: "badge-notification")

Direct Known Subclasses

Component::Badge

Instance Method Summary collapse

Constructor Details

#initialize(content, **options) ⇒ Badge

Initialize a new badge component

Parameters:

  • content (String)

    The text content to display in the badge

  • options (Hash)

    Additional HTML attributes for the badge element

Options Hash (**options):

  • :class (String)

    CSS classes to apply to the badge



21
22
23
24
25
# File 'lib/phlexi/menu/badge.rb', line 21

def initialize(content, **options)
  @content = content
  @options = options
  super()
end

Instance Method Details

#view_templateObject



27
28
29
# File 'lib/phlexi/menu/badge.rb', line 27

def view_template
  span(class: @options[:class]) { @content }
end