class SparkComponents::Attributes::Tag
Attributes
attrs[R]
Public Class Methods
new(obj = {})
click to toggle source
# File lib/spark_components/attributes.rb, line 118 def initialize(obj = {}) @attrs = Attributes::Hash.new merge!(obj) end
Public Instance Methods
add_class(*args)
click to toggle source
# File lib/spark_components/attributes.rb, line 146 def add_class(*args) classnames.add(*args) end
aria(obj = {})
click to toggle source
# File lib/spark_components/attributes.rb, line 128 def aria(obj = {}) attrs[:aria] ||= Aria.new attrs[:aria].add(obj) unless obj.empty? attrs[:aria] end
base_class(name)
click to toggle source
# File lib/spark_components/attributes.rb, line 150 def base_class(name) classnames.base = name unless name.nil? classnames.base end
classnames(*args)
click to toggle source
# File lib/spark_components/attributes.rb, line 140 def classnames(*args) attrs[:class] ||= Classname.new attrs[:class].add(*args) unless args.empty? attrs[:class] end
data(obj = {})
click to toggle source
# File lib/spark_components/attributes.rb, line 134 def data(obj = {}) attrs[:data] ||= Data.new attrs[:data].add(obj) unless obj.empty? attrs[:data] end
dup()
click to toggle source
Ensure each attribute is distinct
# File lib/spark_components/attributes.rb, line 164 def dup new(attrs.each_with_object(Attributes::Hash.new) do |(k, v), obj| obj[k] = v.dup end) end
join_class(*args)
click to toggle source
# File lib/spark_components/attributes.rb, line 155 def join_class(*args) classnames.join_class(*args) end
merge(obj = {})
click to toggle source
# File lib/spark_components/attributes.rb, line 174 def merge(obj = {}) merge_obj(dup, obj) end
merge!(obj = {})
click to toggle source
# File lib/spark_components/attributes.rb, line 170 def merge!(obj = {}) merge_obj(self, obj) end
merge_obj(tag, obj = {})
click to toggle source
# File lib/spark_components/attributes.rb, line 178 def merge_obj(tag, obj = {}) # If merging another Tag, extract attrs to merge obj = obj.attrs if obj.is_a?(Tag) obj.each do |key, val| if val.is_a?(Classname) # preserve object state tag.attrs[:class] = val else case key.to_sym when :class then tag.classnames.add(val) when :data, :aria then tag.send(key).add(val) else; tag.attrs[key] = val end end end tag end
new(obj = {})
click to toggle source
# File lib/spark_components/attributes.rb, line 159 def new(obj = {}) self.class.new(obj) end
root(obj = {})
click to toggle source
# File lib/spark_components/attributes.rb, line 123 def root(obj = {}) attrs.add(obj) unless obj.empty? attrs end
to_s()
click to toggle source
# File lib/spark_components/attributes.rb, line 197 def to_s attrs.to_s end