Herb: Powerful and seamless HTML-aware ERB parsing and tooling
herb-tools.dev
herb-tools.dev
Initially thought it was an addon (or JS lib) that allowed for using Ruby as an embedded client-side scripting language that would parse in-line Ruby in the HTML.
Clearer once I realized it was closer to PHP or similar language usages.
Second also to the recommendation about a quick definition of ERB (Embedded RuBy). Had to look it up.
A few practical examples of what an actual user might want to do with HTML + ERB could be helpful.
- Client characteristics customization
- Previous use history customization
- The database Create, Read, Update, and Delete cycle using Herb
- A basic Content Management System example
- A basic e-commerce example
- A basic RESTful API example
Note: These are just my guesses based on what I "believe" its for.Wow!!! Cool to see ERB being embraced and enhanced in this way, I’ll have to check it out
I was thinking about something like this, but with some blend of Jinja2 / Twig / Nunjucks [1] syntax and Svelte/JSX-like use of variables in element attributes:
{% for para in page.body %}
<p class={{ para.class }} {{ **para.attrs }}>
{{ para.text }}
</p>
{% endfor %}
---[1]: the irony is not lost on me that I’m mentioning Python, PHP and JS template engines in a Ruby discussion :-) Liquid is the closest equivalent I think, but there was some crucial piece missing last time I had to use it, though I can’t remember what exactly.
It works pretty seamlessly and you get something like this:
@app.post('/part/add')
def create_part(part_number: str, name: str, description: str):
p = Part(part_number=part_number, name=name, description=description)
p.save()
return (p,
Input(placeholder="part number", id="part_number", hx_swap_oob='true'),
Input(placeholder="description", id="description", hx_swap_oob='true'),
Input(placeholder="name", id="name", hx_swap_oob='true'))
Note, I'm not using FastHTML's built-in database interface. I prefer a little less implicit than the strict FastHTML style. <p :for={para <- paras} class={para.class} {para.attrs}>
{para.text}
</p>
With :for being a list comprehension.Template engines like liquid are good for simpler use cases where you'd want your end users to write templates (who aren't programmers)
And no, it’s not only good for simple use cases. Template inheritnace alone is a killer feature for bigger projects: https://jinja.palletsprojects.com/en/stable/templates/#templ...
I realize this is new, but as tools start using herb, it would nice to link to those tools from the herb website and or github readme.
(ERB is, I think, “embedded Ruby”, and it functions basically like old school PHP: you just insert pieces of Ruby code wrapped by <% .. %> or <%= .. %>: https://github.com/ruby/erb#recognized-tags)
Oh, wait...