|
|
|
|
|
by axelthegerman
478 days ago
|
|
Nice write up, however personally I'd take ERB over Phlex a million times. Sure ERB is another DSL and some things are not perfect. But for the mark-up you write actual HTML instead of having to learn and get used to writing blocks for each element. I guess to each their own, you enjoy rails with Phlex and I will with ERB. I think the bigger challenges with emails is that action mailer itself is a little dated and feels cluttered. Most email clients being a nightmare with the actual rendering and not being able to use stylesheets etc makes it even harder... So I'd love to see a general iteration on action mailer to bring it up to the level of Rails 8 |
|
Agreed.
This has been tried so many times, and non of them really "stuck". HAML, slim, liquid and now phlex. All "DSLs" to some extent that solve the problem of "not having to write HTML".
Is that a problem, really? People writing Rails apps are developing web-apps. Writing HTML is part of the skillset, and of all the things in a Rails app, really not the most difficult, boring or inefficient ones.
I've found the opposite to be true: another layer of abstraction that new hires need to understand. Another DSL to learn. Another syntax/LSP/docs to add to the IDE, or editor. Another leaky abstraction that has to be debugged, monitored, performance-tested. And a very strongly and tightly coupled dependency: it's almost undoable to just move from, say, HAML back to erb in a 10k+LoC rails app: you're effectively married to HAML, and truly in trouble when (not if) the gem gets abandoned.
Now, like Cells[1], Phlex main "problem it solves" isn't "HTML is hard" but "Rails' templates are too simple/poorly designed". Rails templates push a lot of magic (global) state around, is bidirectional (you can update the database from within a template just fine. Both intentional and accidental), it's not isolated, and because of all this, very hard to test. All this becomes worse if you want to re-use components.
But, like Cells, Phlex solves this problem by introducing some DSL to abstract the HTML. Which then makes up the largest part of the gem. Why? Really. OOP templates can be classes that have a "render" and that then use (scoped) "erb" files just fine. This pattern is both easy and available - no gems needed even.
So, yes. My opinionated, advice, fed by decades of struggling with numerous rails projects, is to stay away from such gems: KISS.
¹ edit : https://trailblazer.to/2.1/docs/cells/