Skip to content

Releases: phlex-ruby/phlex-rails

2.1.2

07 Mar 11:22
f39547c
Compare
Choose a tag to compare

What's Changed

Full Changelog: 2.1.1...2.1.2

2.1.1

06 Mar 18:34
Compare
Choose a tag to compare

What's Changed

Full Changelog: 2.1.0...2.1.1

2.1.0

05 Mar 12:00
Compare
Choose a tag to compare

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

Full Changelog: 2.0.2...2.1.0

2.1.0.rc1

28 Feb 16:30
Compare
Choose a tag to compare
2.1.0.rc1 Pre-release
Pre-release

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

Full Changelog: 2.0.2...2.1.0.rc1

2.0.2

16 Feb 12:50
Compare
Choose a tag to compare

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

15 Feb 23:20
Compare
Choose a tag to compare

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

14 Feb 17:00
Compare
Choose a tag to compare

What's Changed

Many things [updated releases notes coming soon.]

New Contributors

Full Changelog: 1.2.2...2.0.0

2.0.0.rc1

26 Nov 21:23
Compare
Choose a tag to compare
2.0.0.rc1 Pre-release
Pre-release
Bump version

1.2.2

13 Nov 12:30
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: 1.2.1...1.2.2

1.2.1

05 Apr 22:01
Compare
Choose a tag to compare

Just a quick fix for an issue that occurred when rendering ViewComponents inside Phlex Components.

What's Changed

Full Changelog: 1.2.0...1.2.1