Sha256: a790d2cbca5eeab349d154132b1a569019b673626021892cc08a5449063e10fd

Contents?: true

Size: 767 Bytes

Versions: 13

Compression:

Stored size: 767 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
      @html_attrs[:class] = class_names(@html_attrs[:class])
      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

13 entries across 13 versions & 1 rubygems

Version Path
lookbook-1.5.5 app/components/lookbook/tag_component.rb
lookbook-1.5.4 app/components/lookbook/tag_component.rb
lookbook-1.5.3 app/components/lookbook/tag_component.rb
lookbook-1.5.2 app/components/lookbook/tag_component.rb
lookbook-1.5.1 app/components/lookbook/tag_component.rb
lookbook-1.5.0 app/components/lookbook/tag_component.rb
lookbook-1.4.5 app/components/lookbook/tag_component.rb
lookbook-1.4.4 app/components/lookbook/tag_component.rb
lookbook-1.4.3 app/components/lookbook/tag_component.rb
lookbook-1.4.2 app/components/lookbook/tag_component.rb
lookbook-1.4.1 app/components/lookbook/tag_component.rb
lookbook-1.4.0 app/components/lookbook/tag_component.rb
lookbook-1.3.4 app/components/lookbook/tag_component.rb