1.5.0
Highlights
Rename text → plain
We recently added support for SVGs and the SVG spec includes a <text> element. In order to support this tag and be consistent across SVG and HTML, we renamed text to plain. You can still use text in Phlex::HTML components for now, but it will be removed from the next minor release.
Switch to ERB::Escape and depend on ERB 4
Rails, in its infinite wisdom, decided to patch ERB::Util.html_escape so it doesn’t HTML-escape certain strings. In order to bypass this patch, later versions of ERB provide ERB::Escape.html_escape, which they (and we) hope Rails will not patch. Phlex switched to using this new html_escape method, which means we now depend on ERB 4. Luckily ERB is now a gem which can be upgraded independently of Ruby itself so I hope this won’t cause any issues. In fact, upgrading ERB should make your app faster even if you’re stuck on an older version of Ruby.
Make the capture method global
The capture method used to only support blocks from the same exact component instance, since it worked by temporarily replacing the component's buffer with a new string. Now, instead of temporarily pointing at a new string, it makes a copy of the original buffer, clears it, yields the block, makes another copy of the buffer, clears it again, pushes the original copy back onto the buffer and returns the new copy. This means we can yield blocks from other components and still capture the output.
As part of this change, we've also had to update the way Phlex works with explicitly provided buffers. We now maintain an internal buffer and write it to the external buffer so the external buffer only needs to support the method <<(String): -> self. This covers Strings, Arrays and Enumerators out-of-the-box. The default is a mutable string and you usually don't need to think about it.
Custom attribute pre-processing
You can now define the method process_attributes(**attributes) to return a Hash of processed attributes if you want to do your own custom processing. This method should be deterministic, since attributes will still be cached based on the original Hash not the processed Hash. If you define the process_attributes method, the attributes cache will also be isolated to the class, which comes with a ~10% performance cost compared with a shared attribute cache.
Underlying improvements to storing a registry of elements
We also made some underlying improvements to how Phlex remembers which elements have been registered. In the future, this will allow us to compile custom elements you’ve registered yourself. It also means you can register custom elements in modules that extend Phlex::Rails::Elements, which is great for the plugin ecosystem.
What's Changed
- Rename
texttoplainby @joeldrapper in #504 - Use
ERB::Escapeby @joeldrapper in #505 - Specify ERB dependency by @joeldrapper in #506
- Shim
Phlex::HTML#textmethod including deprecation warning by @marcoroth in #507 - Mention another repos on README.md by @stephannv in #509
- Refactor away the need for storing a list of registered elements by @willcosgrove in #511
- Change strategy of determining the origin of an element method by @willcosgrove in #512
- Fix element original method name change not applied to void elements by @willcosgrove in #514
- Global capture by @joeldrapper in #513
- Pre-process attributes with a class-isolated attribute cache by @joeldrapper in #515
Full Changelog: 1.4.0...1.5.0