Live data from Hacker News

Phlex for Rails Emails: Action Mailer Without ERB

camillovisini.com

11–20 of 26 posts

Re: Phlex for Rails Emails: Action Mailer Without ERB

#11
post #7
post #3

Earlier quoted context omitted.

> Nice write up, however personally I'd take ERB over Phlex a million times. 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,…

The thing I really like about Phlex is that it's not a full DSL, it's not its own language. It's an expressive Ruby API and the resulting code has the regular Ruby toolbox available. Ruby devs often call this a "DSL" and I lean away from that use of the term because I think it adds confusion in situations like this. But Phlex feels like a breath of fresh air because it's composable, testable, "just ruby", and has a l…

> I'm not sold on some of its design like the distinction between views and components

There is no distinction in Phlex. The distinction is only made in generated code in Phlex-Rails where it felt like a sensible way to fit with the existing mental model. Views are technically just components, but they are expected to be HTML documents composed of components and rendered directly from controller actions. You wouldn’t want to render a view inside another component because you’d get another doctype and `` tag. So they are sort of “entry points”.

> There's a little metaprogramming in SGML::Elements I dislike

Many crimes are committed in the name of performance. For example, we have a different code path for standard elements with attributes and content, standard elements with attributes but no content, standard elements with content but no attributes and standard elements with no attributes or content. Not to mention void elements.

This allows us to reduce the number of string concatenation operations required during rendering and is why it renders ~1.5gbps of HTML per core.

I’ve considered having an API-compatible minimal version of Phlex that would be much easier to take on and maintain yourself if it didn’t make all these performance optimisations.

Re: Phlex for Rails Emails: Action Mailer Without ERB

#12
I can't help but feel that Rails is having a comeback now. Lots of people building really cool projects like this one popping up. The stack is insanely good for doing everything I need to do and the Hotwire Native stuff is starting to get more and more solid every day.

Re: Phlex for Rails Emails: Action Mailer Without ERB

#13
post #12

I can't help but feel that Rails is having a comeback now. Lots of people building really cool projects like this one popping up. The stack is insanely good for doing everything I need to do and the Hotwire Native stuff is starting to get more and more solid every day.

I still prefer Vue3 with Vite over hotwire and stimulus. It is much easier to be productive on frontend if you need anything beyond usual CRUD

Re: Phlex for Rails Emails: Action Mailer Without ERB

#14
post #12

I can't help but feel that Rails is having a comeback now. Lots of people building really cool projects like this one popping up. The stack is insanely good for doing everything I need to do and the Hotwire Native stuff is starting to get more and more solid every day.

Adding an anecdote I'm one of those newcomers having rediscovered rails a few months ago after all the buzz around version 8.

I just got done porting https://www.skatevideosite.com (and our custom admin panel) from sveltekit/fastapi to Rails and I'm stoked on the results so far.

I need to write up my experience about the rewrite, having a blast so far.

Re: Phlex for Rails Emails: Action Mailer Without ERB

#15
post #13
post #12

I can't help but feel that Rails is having a comeback now. Lots of people building really cool projects like this one popping up. The stack is insanely good for doing everything I need to do and the Hotwire Native stuff is starting to get more and more solid every day.

I still prefer Vue3 with Vite over hotwire and stimulus. It is much easier to be productive on frontend if you need anything beyond usual CRUD

Second this - here is a guide for good setup for this https://mailsnag.com/blog/rails7-vuetify3/

Re: Phlex for Rails Emails: Action Mailer Without ERB

#16
post #7

Earlier quoted context omitted.

The thing I really like about Phlex is that it's not a full DSL, it's not its own language. It's an expressive Ruby API and the resulting code has the regular Ruby toolbox available. Ruby devs often call this a "DSL" and I lean away from that use of the term because I think it adds confusion in situations like this. But Phlex feels like a breath of fresh air because it's composable, testable, "just ruby", and has a l…

> I'm not sold on some of its design like the distinction between views and components There is no distinction in Phlex. The distinction is only made in generated code in Phlex-Rails where it felt like a sensible way to fit with the existing mental model. Views are technically just components, but they are expected to be HTML documents composed of components and rendered directly from controller actions. You wouldn’t…

You know, you've told me that about views and components before, and I keep forgetting. I am so used to getting burned by software that has two names for things because a couple months or years later, ah yes, now that you mention it there is this one tiiiiny distinction that happens to be why the app is on fire now.

It would be great if you could expand your explanation of the metaprogramming into a comment in the code. When I read it, I didn't immediately recognize the technique and its tradeoffs, so it seemed like an odd decision rather than an informed one.

Having two versions of phlex would be a strong negative to me. I don't like to see dev teams spread themselves out, it's one more choice I'd have to make when adopting, if switching between them I have new risks that they've slipped out of sync in some way, and it's altogether another odd decision that has to be explained.

What I was trying to say about the code is that I share the previous commenter's experience of "welp I guess if we want that bug fixed we have to click 'fork' on github... while we write up our plan to migrate away". Having had that experience several times, Phlex looks like an acceptable risk.

Re: Phlex for Rails Emails: Action Mailer Without ERB

#17
post #3

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 fe…

> Nice write up, however personally I'd take ERB over Phlex a million times. 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,…

> another layer of abstraction that new hires need to understand. Another DSL to learn.

The thing about Phlex is it’s actually one less thing to learn. Instead of learning Ruby and ERB and how to use them both with HTML — and all the context switching that goes with using three languages in one file, you only need to know Ruby and HTML semantics (elements, methods, attributes, text, comments, doctype).

> Another syntax/LSP/docs to add to the IDE, or editor.

If you’re writing an app in Ruby, you’ll already have Ruby LSP set up in your editor. There is no other syntax. I would strongly advise against using Phlex if not already writing an application in Ruby, though I have heard of someone using Phlex to generate PHP.

> Another leaky abstraction that has to be debugged, monitored, performance-tested.

I don’t know what you mean by “leaky abstraction”. I consider Phlex to be an air-tight abstraction around the parts of HTML I’ve ever had to use in the last 15 years of programming. There are a couple of things you can’t do without using `raw` — mainly CDATA and other non-HTML5 doctypes.

If I saw a convincing argument for supporting those parts of HTML, I would.

The real leaky abstraction for HTML is string templating, where none of the HTML semantics are validated and XSS vulnerabilities abound.

Re: Phlex for Rails Emails: Action Mailer Without ERB

#18
post #12

I can't help but feel that Rails is having a comeback now. Lots of people building really cool projects like this one popping up. The stack is insanely good for doing everything I need to do and the Hotwire Native stuff is starting to get more and more solid every day.

Adding an anecdote I'm one of those newcomers having rediscovered rails a few months ago after all the buzz around version 8. I just got done porting https://www.skatevideosite.com (and our custom admin panel) from sveltekit/fastapi to Rails and I'm stoked on the results so far. I need to write up my experience about the rewrite, having a blast so far.

wow this is the first i've seen someone port from sveltkit to rails. can't wait to read that writeup

Re: Phlex for Rails Emails: Action Mailer Without ERB

#19
post #13
post #12

I can't help but feel that Rails is having a comeback now. Lots of people building really cool projects like this one popping up. The stack is insanely good for doing everything I need to do and the Hotwire Native stuff is starting to get more and more solid every day.

I still prefer Vue3 with Vite over hotwire and stimulus. It is much easier to be productive on frontend if you need anything beyond usual CRUD

Vue3 is great. Also Svelte5. But I’m not sure I would use either of those for an email. And sometimes you don’t need any interactivity in the frontend and server-side-rendered HTML can be a good option.

Re: Phlex for Rails Emails: Action Mailer Without ERB

#20
post #12

I can't help but feel that Rails is having a comeback now. Lots of people building really cool projects like this one popping up. The stack is insanely good for doing everything I need to do and the Hotwire Native stuff is starting to get more and more solid every day.

Wonder if there is some data that backs up this claim
Post reply on HN