Class: BulmaPhlex::Tag
- Inherits:
-
Base
- Object
- Base
- BulmaPhlex::Tag
- Defined in:
- lib/bulma_phlex/tag.rb
Overview
Renders the Bulma 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
-
#initialize(text, **options_and_html_attributes) ⇒ Tag
constructor
A new instance of Tag.
- #view_template ⇒ Object
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, **) @text = text @html_attributes = .except(*TAG_OPTIONS) @options = .slice(*TAG_OPTIONS) end |
Class Method Details
.new(text, **options_and_html_attributes) ⇒ Object
Parameters
text— The text content of the tagdelete— Iftrue, adds a delete button inside the tagcolor— Sets the color of the taglight— To use a light version of the color, use the keylightinstead ofcolorsize— Sets the size of the tag:"normal","medium", or"large"rounded— Iftrue, adds theis-roundedclass 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, **) super end |
Instance Method Details
#view_template ⇒ Object
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) { } elsif @options[:delete] || !@html_attributes.dig(:data, :action).nil? (class: tag_classes, **@html_attributes) { } else span(class: tag_classes, **@html_attributes) { plain @text } end end |