Class: Coco::Tag
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Coco::Tag
- Includes:
- AlpineHelper, TagHelper
- Defined in:
- app/components/coco/tag.rb
Constant Summary collapse
- SELF_CLOSING_TAGS =
i[area base br col hr img input link param source track wbr].freeze
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#strip ⇒ Object
readonly
Returns the value of attribute strip.
-
#tag_name ⇒ Object
readonly
Returns the value of attribute tag_name.
Instance Method Summary collapse
- #call ⇒ Object
- #content ⇒ Object
-
#initialize(tag_name = :div, strip: false, root: false, **tag_attrs) ⇒ Tag
constructor
A new instance of Tag.
- #tag_attrs ⇒ Object
Methods included from AlpineHelper
Methods included from TagHelper
#prefix_attr_keys, #random_id, #style_str
Constructor Details
#initialize(tag_name = :div, strip: false, root: false, **tag_attrs) ⇒ Tag
Returns a new instance of Tag.
10 11 12 13 14 15 |
# File 'app/components/coco/tag.rb', line 10 def initialize(tag_name = :div, strip: false, root: false, **tag_attrs) @tag_name = tag_name @strip = strip @tag_attrs = tag_attrs @root = root end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
8 9 10 |
# File 'app/components/coco/tag.rb', line 8 def root @root end |
#strip ⇒ Object (readonly)
Returns the value of attribute strip.
8 9 10 |
# File 'app/components/coco/tag.rb', line 8 def strip @strip end |
#tag_name ⇒ Object (readonly)
Returns the value of attribute tag_name.
8 9 10 |
# File 'app/components/coco/tag.rb', line 8 def tag_name @tag_name end |
Instance Method Details
#call ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/components/coco/tag.rb', line 21 def call if SELF_CLOSING_TAGS.include?(@tag_name) tag(tag_name, tag_attrs) else content_tag(tag_name, content, tag_attrs) end end |
#content ⇒ Object
17 18 19 |
# File 'app/components/coco/tag.rb', line 17 def content strip ? super.strip_heredoc.strip : super end |
#tag_attrs ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/components/coco/tag.rb', line 29 def tag_attrs attrs = @tag_attrs.except(:x, :test_data) alpine_attrs = @tag_attrs.fetch(:x, {}) if alpine_attrs.any? attrs.merge!(x_attrs(alpine_attrs, root: root)) end if dev? test_attrs = prefix_attr_keys(@tag_attrs.fetch(:test_data, {}), "test") attrs.merge!(test_attrs) end attrs end |