Class: BulmaPhlex::Tag

Inherits:
Base
  • Object
show all
Defined in:
lib/bulma_phlex/tag.rb

Overview

Renders the [Bulma tag](bulma.io/documentation/elements/tag/) component.

Generates a ‘<span>`, `<a>`, or `<button>` element depending on the provided attributes. Supports Bulma options for color, size, and shape (rounded), with an optional **delete button** that can appear inside the tag.

Constant Summary collapse

TAG_OPTIONS =
%i[delete color light size rounded].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, **options_and_html_attributes) ⇒ Tag

Returns a new instance of Tag.



26
27
28
29
30
# File 'lib/bulma_phlex/tag.rb', line 26

def initialize(text, **options_and_html_attributes)
  @text = text
  @html_attributes = options_and_html_attributes.except(*TAG_OPTIONS)
  @options = options_and_html_attributes.slice(*TAG_OPTIONS)
end

Class Method Details

.new(text, **options_and_html_attributes) ⇒ Object

Parameters

‘“medium”`, or `“large”`

  • ‘rounded` — If `true`, adds the `is-rounded` class to the tag

  • ‘**options_and_html_attributes` — Additional HTML attributes applied to the rendered element



22
23
24
# File 'lib/bulma_phlex/tag.rb', line 22

def self.new(text, **options_and_html_attributes)
  super
end

Instance Method Details

#view_templateObject



32
33
34
35
36
37
38
39
40
# File 'lib/bulma_phlex/tag.rb', line 32

def view_template
  if @html_attributes.key?(:href)
    a(class: tag_classes, **@html_attributes) { text_and_optional_delete_button }
  elsif @options[:delete] || !@html_attributes.dig(:data, :action).nil?
    button(class: tag_classes, **@html_attributes) { text_and_optional_delete_button }
  else
    span(class: tag_classes, **@html_attributes) { plain @text }
  end
end