Sha256: c530f1291f363affe9604ae3dbbb1a91d044ec2c9172c5f3487575d77e0c1c34
Contents?: true
Size: 1.31 KB
Versions: 25
Compression:
Stored size: 1.31 KB
Contents
module Coco module Concerns module AcceptsTagAttributes extend ActiveSupport::Concern TAG_ATTRIBUTE_NAMES = %i[id class data aria test_data x].freeze class_methods do def tag_name(name = nil) @_tag_name = name if name @_tag_name end def tag_attr(*attr_names) tag_attr_names.push(*attr_names) end def tag_attr_names @_tag_attr_names ||= [*TAG_ATTRIBUTE_NAMES] end end def tag_attrs @_tag_attrs ||= {} end protected def tag_name(name = nil) @tag_name = name if name @tag_name ||= self.class.tag_name end def tag_name=(name) @tag_name = name end def set_tag_attr(attr_name, value = "") tag_attrs[attr_name] = value end def set_tag_data_attr(attr_name, value = "") tag_attrs[:data] ||= {} tag_attrs[:data][attr_name] = value end def tag_attr?(attr_name) tag_attrs.key?(attr_name) end private def process_tag_attrs(args) @_tag_attrs ||= {} @_tag_attrs.merge!(args[:html].to_h) @_tag_attrs.merge!(args.slice(*self.class.tag_attr_names)) @_component_args = args.except(*self.class.tag_attr_names, :html) end end end end
Version data entries
25 entries across 25 versions & 1 rubygems