Module: Spark

Defined in:
lib/spark/component/attribute.rb,
lib/spark/component.rb,
lib/spark/component/attr.rb,
lib/spark/component/element.rb,
lib/spark/component/version.rb,
lib/spark/component/tag_attr.rb,
lib/spark/component/classname.rb,
lib/spark/component/integration/action_view_component.rb

Overview

Allows components to easily manage their attributes

Example component usage:

class SomeClass
 include Spark::Component::Attribute

 # Set a :label attribute, and a :size attribute with default value :large
 attribute :label, { size: :large }

 def inialize(attributes = nil)
   initialize_attributes(attributes)
 end
end

When initialized like:

some_instance = SomeClass.new(label: "Test")

The Class's instance will now have access to

@label => "Test"
@size  => :large

And will define access methods:

some_instance.attribute_label
some_instance.attribute_size

Attributes can also be accessed with a helper method

some_instance.attribute(:label)
some_instance.attribute(:size)

Extending a class will extend its attributes and their defaults.

This supports a common set of base attributes such as id, class, data, aria, and html. The html attribute is meant to allow for passing along unaccounted for tag attributes.

Defined Under Namespace

Modules: Component