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 Herb project introduces a novel approach to working with ERB (Embedded Ruby) templates, focusing on powerful parsing capabilities and seamless integration with HTML. Instead of treating ERB as plain text with embedded Ruby code, Herb leverages an HTML-aware parser. This allows it to understand the structure and context of the HTML within the template, leading to more accurate and robust manipulation and analysis.
Herb's core strength lies in its deep understanding of HTML syntax. By parsing both HTML and embedded Ruby code simultaneously, it avoids the pitfalls of traditional regular expression-based approaches which can struggle with complex HTML structures and edge cases. This HTML awareness allows for sophisticated tooling and transformations previously difficult to achieve with ERB.
The project offers a variety of practical tools built upon this foundation. One key feature is rewriting, which enables modifications and transformations of the ERB template based on its HTML structure. This contrasts with simpler string manipulation and allows for changes that respect and maintain the HTML integrity. For example, adding or modifying attributes of specific HTML tags becomes a straightforward operation.
Another highlighted capability is linting. Herb's linting functionalities go beyond basic syntax checking. The HTML awareness allows for more context-aware linting rules, potentially identifying issues related to HTML structure, accessibility, or best practices, in addition to standard Ruby code linting within the ERB template.
Furthermore, Herb provides formatting capabilities. By understanding the HTML structure, Herb can format both the HTML and embedded Ruby code in a consistent and aesthetically pleasing way. This ensures a standardized code style within ERB templates, enhancing readability and maintainability.
The project emphasizes a focus on performance, aiming to provide efficient parsing and tooling for even large and complex ERB files. It also strives for a seamless integration into existing developer workflows, suggesting potential for incorporation into editors and build processes. Overall, Herb positions itself as a robust and powerful solution for managing and manipulating ERB templates, addressing limitations of traditional tools through its innovative HTML-aware approach.
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.