Sha256: 6311c2a5131fefa2d7453da703479130b3d2d011428a342fe729f6ad7a9dfc75
Contents?: true
Size: 1.11 KB
Versions: 75
Compression:
Stored size: 1.11 KB
Contents
module Coco class Tag < ViewComponent::Base include Coco::TagHelper include Coco::AlpineHelper SELF_CLOSING_TAGS = %i[area base br col embed hr img input link meta param source track wbr].freeze attr_reader :tag_name, :strip, :root def initialize(tag_name = :div, strip: false, root: false, **tag_attrs) @tag_name = tag_name @strip = strip @tag_attrs = tag_attrs @root = root end def content strip ? super.strip_heredoc.strip : super end def call if SELF_CLOSING_TAGS.include?(@tag_name) tag(tag_name, tag_attrs) else content_tag(tag_name, content, tag_attrs) end end 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 private def dev? Rails.env.test? || Rails.env.development? end end end
Version data entries
75 entries across 75 versions & 1 rubygems