Herb is a new command-line tool and Rust library designed to improve the developer experience of working with ERB (Embedded Ruby) templates. It focuses on accurate and efficient parsing of HTML-aware ERB, addressing issues like incorrect syntax highlighting and code completion in existing tools. Herb offers features such as syntax highlighting, formatting, linting (with custom rules), and symbolic renaming within ERB templates, enabling more productive development and refactoring of complex view logic. By understanding the underlying HTML structure, Herb can provide more contextually relevant results and prevent issues common in tools that treat ERB as plain text or simple HTML. It aims to become an essential tool for Ruby on Rails developers and anyone working extensively with ERB.
The blog post explores using Phlex, a Ruby HTML templating library, as a replacement for ERB in Rails Action Mailer. It highlights Phlex's component-based approach, allowing for reusable email templates and a more organized code structure compared to traditional ERB files. The author demonstrates how to set up Phlex within a Rails project, including configuration adjustments and creating view components specifically for emails. They showcase the benefits of using Phlex, like cleaner syntax, improved maintainability through component reusability, and a more intuitive way to manage email layouts and partials. Ultimately, the post positions Phlex as a modern alternative to ERB for building emails in Rails, offering a more streamlined and manageable development experience.
HN users generally expressed interest in Phlex as an alternative to ERB for Rails email templating, praising its cleaner syntax and potential performance benefits due to compiled templates. Some questioned the practicality of another templating language, citing the existing ecosystem around ERB and the learning curve involved. Others noted that while Phlex offered improvements, the article's benchmark showing only a 20% improvement wasn't compelling enough to justify switching. There was also discussion around the complexity of view components within emails and whether Phlex sufficiently addressed those challenges. Finally, some users compared Phlex to other templating options like Slim and wondered about the real-world performance difference, especially within the context of email rendering where other factors might dominate performance.
Summary of Comments ( 3 )
https://news.ycombinator.com/item?id=43704853
Hacker News users generally praised Herb for its innovative approach to templating, particularly its HTML-awareness and the potential for improved refactoring capabilities. Some expressed excitement about its ability to parse and manipulate ERB templates more effectively than existing tools. A few commenters questioned the long-term viability of the project given its reliance on Tree-sitter, citing potential maintenance challenges and parser bugs. Others were curious about specific use cases and integration with existing Ruby tooling. Performance concerns and the overhead introduced by parsing were also mentioned, but overall the reception was positive, with many expressing interest in trying out Herb.
The Hacker News post titled "Herb: Powerful and seamless HTML-aware ERB parsing and tooling" has generated several comments discussing the merits and potential drawbacks of the Herb tool.
Several commenters express enthusiasm for the project, praising its ability to address the challenges of working with ERB templates, particularly within complex HTML structures. One user highlights the difficulty of refactoring ERB and how Herb seems to offer a solution to this long-standing problem. Another appreciates the ability to rename components and the potential time savings this feature offers. The clean and appealing design of the website is also mentioned positively.
Some users raise concerns and questions. One commenter questions the performance implications of parsing HTML and ERB simultaneously, expressing a preference for precompiling ERB to avoid runtime parsing overhead. This sparks a discussion about the performance characteristics of various templating approaches, with another user suggesting that the performance concerns might be negligible in many real-world scenarios. The maintainability of generated code is also raised as a potential issue.
Another thread of discussion revolves around the choice of Ruby as the implementation language for Herb. One commenter expresses a desire for similar tooling in other languages, specifically mentioning Elixir. This leads to a brief discussion about the availability (or lack thereof) of comparable tools in different ecosystems.
A few users share their personal experiences and workflows related to templating languages, offering alternative approaches and suggesting potential integrations with other tools. One user mentions using a custom DSL for templates, highlighting the benefits of a domain-specific approach.
Overall, the comments reflect a generally positive reception of Herb, acknowledging its potential to improve the developer experience when working with ERB templates. However, some pragmatic concerns regarding performance and the broader applicability of the tool are also voiced.