Class: Lookbook::TagComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Lookbook::TagComponent
- Includes:
- ComponentHelper
- Defined in:
- app/components/lookbook/tag_component.rb
Constant Summary
Constants included from ComponentHelper
ComponentHelper::COMPONENT_CLASSES
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tag: :div, name: nil, cloak: false, **html_attrs) ⇒ TagComponent
constructor
A new instance of TagComponent.
Methods included from ComponentHelper
#class_names, #code, #icon, #render_component, #render_tag
Constructor Details
#initialize(tag: :div, name: nil, cloak: false, **html_attrs) ⇒ TagComponent
Returns a new instance of TagComponent.
5 6 7 8 9 10 11 12 |
# File 'app/components/lookbook/tag_component.rb', line 5 def initialize(tag: :div, name: nil, cloak: false, **html_attrs) @tag = tag html_attrs[:data] ||= {} html_attrs[:data][:component] = name if name.present? html_attrs[:"x-cloak"] = true if cloak == true html_attrs[self.class.escape_attribute_key] = false @html_attrs = html_attrs end |
Class Method Details
.escape_attribute_key ⇒ Object
20 21 22 |
# File 'app/components/lookbook/tag_component.rb', line 20 def self.escape_attribute_key @escape_attribute_key ||= Gem::Version.new(Rails.version) < Gem::Version.new("6.1.5.1") ? :escape_attributes : :escape end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 |
# File 'app/components/lookbook/tag_component.rb', line 14 def call tag.public_send(@tag.to_sym, **@html_attrs) do content end end |