Class: Lookbook::TagComponent

Inherits:
ViewComponent::Base
  • Object
show all
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

Methods included from ComponentHelper

#build_tag_values, #class_names, #code, #icon, #lookbook_render, #lookbook_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_keyObject



21
22
23
# File 'app/components/lookbook/tag_component.rb', line 21

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

#callObject



14
15
16
17
18
19
# File 'app/components/lookbook/tag_component.rb', line 14

def call
  @html_attrs[:class] = class_names(@html_attrs[:class])
  tag.public_send(@tag.to_sym, **@html_attrs) do
    content
  end
end