Class: BulmaPhlex::Tag
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
-
#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 tag
-
‘delete` — If `true`, adds a delete button inside the tag
-
‘color` — Sets the [color of the tag](bulma.io/documentation/elements/tag/#colors)
-
‘light` — To use a light version of the color, use the key `light` instead of `color`
-
‘size` — Sets the [size of the tag](bulma.io/documentation/elements/tag/#sizes): `“normal”`,
‘“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, **) 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 |