Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow recursively nested tokens in attributes (#807)
If you have a component that you want to take in an attribute of a token list, like `class`, and you want your interface to be polymorphic like an element method's attributes would be, you currently need to type check the provided attribute and handle it manually. ```rb class Card < Phlex::HTML def initialize(class:) @Class = grab(class:) end def view_template div(class: ["component-classes", @Class]) end end ``` Before this PR, the above example will break if the person using the Card component tries to supply an array of classes, because `Array` is not a valid token type for `__nested_tokens__`. ```rb render Card.new(class: "fine") # => <div class="component-classes fine"></div> render Card.new(class: ["not-fine"]) # => 💥 ``` Now if an array is passed, it will also have `__nested_tokens__` called on it. ```rb render Card.new(class: ["now-fine"]) # => <div class="component-classes now-fine"></div> ```
- Loading branch information