Class: GOVUKDesignSystemFormBuilder::Traits::HTMLAttributes::Attributes
- Inherits:
-
Object
- Object
- GOVUKDesignSystemFormBuilder::Traits::HTMLAttributes::Attributes
- Defined in:
- lib/govuk_design_system_formbuilder/traits/html_attributes.rb
Overview
Attributes eases working with default and custom attributes by:
-
deeply merging them so both the default (required) attributes are present
-
joins the arrays into strings to maintain Rails 6.0.* compatibility
Constant Summary collapse
- MERGEABLE =
Only try to combine and merge these attributes that contain a list of values separated by a space. All other values should be merged in a regular fashion (where the custom value overrides the default)
[ %i(class), %i(aria controls), %i(aria describedby), %i(aria flowto), %i(aria labelledby), %i(aria owns), ].freeze
Instance Method Summary collapse
-
#initialize(defaults, custom) ⇒ Attributes
constructor
A new instance of Attributes.
- #to_h ⇒ Object
Constructor Details
#initialize(defaults, custom) ⇒ Attributes
Returns a new instance of Attributes.
21 22 23 |
# File 'lib/govuk_design_system_formbuilder/traits/html_attributes.rb', line 21 def initialize(defaults, custom) @merged = defaults.deeper_merge(deep_split_values(custom)) end |
Instance Method Details
#to_h ⇒ Object
25 26 27 |
# File 'lib/govuk_design_system_formbuilder/traits/html_attributes.rb', line 25 def to_h deep_join_values(@merged) end |