Class: PhlexyUI::AttributeSet
- Inherits:
-
Object
- Object
- PhlexyUI::AttributeSet
- Defined in:
- lib/phlexy_ui/attribute_set.rb
Overview
Converts component modifiers and options into HTML attributes. This is an internal class used by Base components.
Internal Usage:
# Component defines an attributes map
ATTRIBUTES_MAP = { open: { checked: true }, closed: true }
# Attributes can come from modifiers or options:
# tab(:open) #=> { checked: true }
# tab(open: true) #=> { checked: true }
# tab(open: false) #=> {}
# tab(:closed) #=> { closed: true }
# tab(closed: true) #=> { closed: true }
# tab(closed: false) #=> {}
Instance Method Summary collapse
-
#initialize(base_modifiers, options, attributes_map) ⇒ AttributeSet
constructor
A new instance of AttributeSet.
- #to_h ⇒ Object
Constructor Details
#initialize(base_modifiers, options, attributes_map) ⇒ AttributeSet
Returns a new instance of AttributeSet.
21 22 23 24 25 |
# File 'lib/phlexy_ui/attribute_set.rb', line 21 def initialize(base_modifiers, , attributes_map) @base_modifiers = base_modifiers = @attributes_map = attributes_map end |
Instance Method Details
#to_h ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/phlexy_ui/attribute_set.rb', line 27 def to_h result = {} # Process modifiers first base_modifiers.each do |modifier| next unless attributes_map.key?(modifier) next if .key?(modifier) process_attribute(modifier, true, result) end # Then process options (overriding modifiers) .each do |key, value| next unless attributes_map.key?(key) next unless value process_attribute(key, value, result) end result end |