Naofumi Kagami
naofumik.bsky.social
Naofumi Kagami
@naofumik.bsky.social
Aspiring "Front-end" Ruby on Rails developer
Reposted by Naofumi Kagami
The pull request is now out.

Thank you all for your comments and encouragement. Let's see how it goes from here.

github.com/rails/rails/...
Tag helper buffer for nested elements with multiple children by naofumi · Pull Request #54042 · rails/rails
Motivation / Background This Pull Request adds a buffer to the content block in ActionView::Helpers::TagHelper#tag. This allows us to easily generate HTML for nested elements with multiple children...
github.com
December 24, 2024 at 6:48 AM
The pull request is now out.

Thank you all for your comments and encouragement. Let's see how it goes from here.

github.com/rails/rails/...
Tag helper buffer for nested elements with multiple children by naofumi · Pull Request #54042 · rails/rails
Motivation / Background This Pull Request adds a buffer to the content block in ActionView::Helpers::TagHelper#tag. This allows us to easily generate HTML for nested elements with multiple children...
github.com
December 24, 2024 at 6:48 AM
Thank you, and yes, that safe_join technique is what I have been using too.

With the excitement around Hotwire based UI component libraries and Tailwind, I think it’s time to codify that into Rails itself.
December 23, 2024 at 11:21 AM
I've just published a blog post with more details on the motivation. I also hope to get a PR out soon. Maybe I can nudge you just a bit closer to view helpers 😀

dev.to/naofumik/rai...
Rails View Helpers for Components
This post is intended to gather feedback on a proposal for a new feature for Rails, while I put...
dev.to
December 23, 2024 at 1:08 AM
Phlex is very good at aligning the two structures. However, by adding a small feature to plain view helpers, I think they can be almost just as good too. I want to discuss this approach.
December 22, 2024 at 2:02 AM
The point of my proposal is to extend the point at which you need to fall back to ERb. In my experience, the major pain point with tag helpers the Ruby code structure often deviates from the HTML structure.
December 22, 2024 at 2:02 AM
Thank you. My position is that if we can shift the middle ground just a little bit, we can have view helpers covering most primary/utility components. For example, we could probably write and compose the components in Shadcn with view helpers.

Can you share more details on the + operator approach?
December 22, 2024 at 1:37 AM
Thank you for the feedback. I fully understand your preference.

Personally, I often do something similar to this using `safe_join`, just to push the limit of helpers so that it encompasses the size of "Components", but I am looking for a better syntax. 😀
December 22, 2024 at 1:31 AM
Briefly, it will allow you to compose HTML in view helpers like this. Currently, blocks in tag helpers only use the return value so this approach was cumbersome when you had multiple tags. I'm proposing an approach that will make it more like Phlex.
December 21, 2024 at 7:56 AM