Sha256: 2773757d46e77d477fd52ba143d143795831865861f2a4f415c7b5cd05b27755

Contents?: true

Size: 704 Bytes

Versions: 12

Compression:

Stored size: 704 Bytes

Contents

module Lookbook
  class TagComponent < ViewComponent::Base
    include Lookbook::ComponentHelper

    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

    def call
      tag.public_send(@tag.to_sym, **@html_attrs) do
        content
      end
    end

    def self.escape_attribute_key
      @escape_attribute_key ||= Gem::Version.new(Rails.version) < Gem::Version.new("6.1.5.1") ? :escape_attributes : :escape
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lookbook-1.0.8 app/components/lookbook/tag_component.rb
lookbook-1.0.7 app/components/lookbook/tag_component.rb
lookbook-1.0.6 app/components/lookbook/tag_component.rb
lookbook-1.0.5 app/components/lookbook/tag_component.rb
lookbook-1.0.4 app/components/lookbook/tag_component.rb
lookbook-1.0.3 app/components/lookbook/tag_component.rb
lookbook-1.0.2 app/components/lookbook/tag_component.rb
lookbook-1.0.1 app/components/lookbook/tag_component.rb
lookbook-1.0.0 app/components/lookbook/tag_component.rb
lookbook-1.0.0.rc.3 app/components/lookbook/tag_component.rb
lookbook-1.0.0.rc.2 app/components/lookbook/tag_component.rb
lookbook-1.0.0.rc.1 app/components/lookbook/tag_component.rb