Releases: phlex-ruby/phlex-rails
2.1.2
2.1.1
2.1.0
Phlex now uses a completely different mechanism for interoperating with ERB templates from ActionView and ViewComponent.
This release is a minor breaking change which means it could break your code, so be careful when upgrading. If you rely on using slot-style components from ERB, you need to make sure you’re not using <%=
tags when calling slot methods on the component.
<%= render Table.new(@people) do |t| %>
<% t.column("Name") do |person| %>
<%= person.name %>
<% end %>
<% t.column("Age") do |person| %>
<%= person.age %>
<% end %>
<% end %>
For UI Kit maintainers, it’s probably a good idea to make your slot methods return nil
in case a user does pass them to <%=
output tags.
def column(header, &content)
@columns << { header:, content: }
nil # <-- return nil
end
If we didn’t return nil from column
in this example, the <%=
ERB output tags would output the to_s
of the @columns
array.
If your components are builder-style (e.g. not yielding early), you can usually just depend on the fact that most of Phlex own methods return nil
.
Impersonating a Rails builder
If you need to use Phlex to impersonate a Rails builder object where builder methods return HTML-safe strings instead of pushing output to a buffer, you will need to wrap each builder method in a capture
. I can only think of one library that might need to do this since it’s aiming for exact API compatibility with existing Rails helpers.
Here’s one example:
class Nav < Phlex::HTML
def view_template(&)
nav(class: "special-nav", &)
end
def item(href, &)
capture do
a(class: "special-nav-item", href:, &)
end
end
def divider
capture do
span(class: "special-nav-divider")
end
end
end
Using this component inside Phlex would be strange because you would have to use raw
, to render the captured strings.
render Nav do |n|
raw n.item("/") { "Home" }
end
It is possible to look at the caller location and see if the caller is an ERB file to determine whether to capture
or not, but I’ll leave that to you. Going forward, Phlex will push to the buffer rather than capture whether rendering inside Phlex or from ERB. Previously, the behaviour was different for ERB.
PRs
- Style changes on phlex initializer template by @stephannv in #269
- Direct buffering by @joeldrapper in #271
Full Changelog: 2.0.2...2.1.0
2.1.0.rc1
Summary
This is the first release candidate for v2.1
which uses a completely different architecture for interoperating with ERB templates from ActionView and ViewComponent. It does this by sharing a buffer rather than trying to patch all the different interactions.
This release is a minor breaking change which means it could break your code, so be careful when upgrading. If you rely on using slot-style components from ERB, you need to make sure you’re not using <%=
tags when calling slot methods on the component. <%=
should be used only for the render
or for rendering values. See in this example, we do not use <%=
for the t.column
call.
<%= render Table.new(@people) do |t| %>
<% t.column("Name") do |person| %>
<%= person.name %>
<% end %>
<% t.column("Age") do |person| %>
<%= person.age %>
<% end %>
<% end %>
For UI Kit maintainers, it’s probably a good idea to make your slot methods return nil
in case a user does pass them to <%=
output tags. If we didn’t return nil from column
in this example, the <%=
ERB output tags would output the to_s
of the @columns
array.
def column(header, &content)
@columns << { header:, content: }
nil # <-- return nil
end
If your components are builder-style (e.g. not yielding early), you can usually just depend on the fact that most of Phlex own methods return nil
.
Impersonating a Rails builder
If you need to use Phlex to impersonate a Rails builder object where builder methods return HTML-safe strings instead of pushing output to a buffer, you will need to wrap each builder method in a capture
. I can only think of one library that might need to do this for API compatibility.
class Nav < Phlex::HTML
def view_template(&)
nav(class: "special-nav", &)
end
def item(href, &)
capture do
a(class: "special-nav-item", href:, &)
end
end
def divider
capture do
span(class: "special-nav-divider")
end
end
end
Using this component inside Phlex would be strange because you would have to use raw
, to render the captured strings.
render Nav do |n|
raw n.item("/") { "Home" }
end
PRs
- Style changes on phlex initializer template by @stephannv in #269
- Direct buffering by @joeldrapper in #271
Full Changelog: 2.0.2...2.1.0.rc1
2.0.2
What's Changed
- Fixed an issue where rendering a Phlex component with a Rails view context but without a request would trigger an error.
- Improved the feature that suggests including a Rails view helper adapter when you call a missing helper method.
Full Changelog: 2.0.1...2.0.2
2.0.1
What's Changed
- Add X-Fragments header support for rendering phlex fragments by @willcosgrove in #265
Full Changelog: 2.0.0...2.0.1
2.0.0
What's Changed
Many things [updated releases notes coming soon.]
New Contributors
- @rubyforbusiness made their first contribution in #215
- @Vagab made their first contribution in #202
- @mjankowski made their first contribution in #216
- @trinitytakei made their first contribution in #205
- @fcheung made their first contribution in #230
Full Changelog: 1.2.2...2.0.0
2.0.0.rc1
Bump version
1.2.2
What's Changed
- [v1] Add support for Rails 8 by @pastpatryk in #243
New Contributors
- @pastpatryk made their first contribution in #243
Full Changelog: 1.2.1...1.2.2
1.2.1
Just a quick fix for an issue that occurred when rendering ViewComponents inside Phlex Components.
What's Changed
- Fix capture block issue by @joeldrapper and @willcosgrove in #193
Full Changelog: 1.2.0...1.2.1