Migrate #content to be a slot
BlakeWilliams opened this issue · comments
This could be a breaking change, but we'd want to include a way of opting into the legacy behavior for at least 1 version to make the migration easier.
I propose that we:
- Implement
content_is_a_slot!
method to allow components in this version of ViewComponent to opt-in to the new behavior as well as break inheritance of the method mentioned below once we release 4.0. - Implement a
legacy_content_behavior!
(or better named) method that can be called in components (and inherited) to opt-in to the current behavior. This would be a noop until 4.0. - Now in 4.0 or when
content_is_a_slot!
is declared, when components are passed a block the resulting HTML and string values are not passed as#content
and the block is always evaluated (unlike today). To pass content,c.content do
will need to be called in the block or via the change mentioned below. - Update
with_content
to support being passed a block, so existing components that rely on the default content behavior (without calling slots) can migrate viarender(MyComponent.new) { "hi!" }
->render(MyComponent.new).with_content { "hi" }
.