6 ms·
Hamlet: A type-safe Haml template engine for Go
- justinclift 3y agoSkimming over the README page, it reminds me of PHP from back in the day.
- lukeholder 3y agoI’m noticing most frameworks moving towards being PHP from end and backend. Smart templates with HTMX.
- eterps 3y agoI appreciate that in JSX, functions can be used as if they were first-class elements. In this case that would be accomplished by supporting the following instead: @hmlt HomePage() { %SiteLayout %p This is the home page for Hamlet. } Which is much cleaner IMO.
- gloryjulio 3y agoBecause JSX is just document.createElement() with syntax sugar. If Haml has an equivalent api, there should be a way to implement something similar.
- eterps 3y agoI don't understand, I thought document.createElement() is independent of JSX. JSX works just as well in Deno/Bun/Node.js without DOM functions.
- deleted 3y ago[deleted]
- gloryjulio 3y agoI haven't looked into the details about how server side rendering is done. It should have something equivalent to generate HTML. But the point still stands, it should be possible to follow the same pattern to create a JSXesque template for HAML
- hresvelgr 3y agoThe example has left me with a strong impression I should avoid this and HAML. That syntax frightens me.
- eterps 3y agoSLIM is similar, but a bit cleaner: https://github.com/mattn/go-slim https://github.com/mattn/go-slim Both SLIM and HAML resemble a DOM tree, it looks somewhat similar to what you would see in the browser inspector.
- toasted-subs 3y agoIs HTML really that scary for people?
- eterps 3y agoI haven't seen many projects where people attempt to use SLIM templates as an alternative to HTML; rather, they are used as a complement. SLIM is for deeply nested structures and layouts, while HTML is for actual content.
- mplewis 3y agoHTML isn’t a templating language like HAML or Slim are.
- bborud 3y agoIt looks unnecessary. The syntax is ugly and by looking at the examples I can’t say what problem it is supposed to solve.
- yoavm 3y agoI love Haml / Pug / Slim. I think it's very clear what problem it solves: you don't need to worry about closing tags, and doing it in the right order, because the tree is visually in front of you. It also means less code (because of no closing tags), which means it's easier to read. It's like HTML but less verbose, less errors prone (<p>foo<b>bar</p></b> is impossible to write), and basically the formatter is part of the language. What is there not to like?
- ceritium 3y agoThat's great; Haml is one thing I like most when doing web development on Ruby/Rails. The only thing I don't like about this implementation is the blocks with inline code: - if user != nil { %strong The user exists - }
- leipert 3y agoCouldn’t you do without the angular brackets? - if user != nil %strong The user exists (That being said, the indentation bit also tripped me up in the past)
- quechimba 3y agoI use Haml in my web framework, I use syntax_suggest [1] to count the missing pairs so I can insert them automatically at the end of the block. It would probably not be too difficult to do the same thing in Go. 1. https://github.com/ruby/syntax_suggest/blob/main/lib/syntax_suggest/left_right_lex_count.rb https://github.com/ruby/syntax_suggest/blob/main/lib/syntax_...
- stackus 3y agoThank you for posting this link. I'll check this out and see if I can get the braces dropped.
- stackus 3y agoThis is something I would like to have working, the subtraction of the braces that is. I did have a naive solution where it would insert the braces for you if the left the opening brace off and it would assume you wanted the closing brace too. This caused problems when I would put in a continuation of an if statement like: - else if other_condition %span other content - else %span another bit of content I pulled the broken solution completely and do plan to revisit dropping the brace requirement because not having the braces aligns with the idea/reason why you'd use Haml in the first place.
- 27theo 3y agoChoosing hmlt as an identifier and file extension is pretty funny and feasibly a troll. Maybe hlet or hamlt would have been more obviously not html.
- vyskocilm 3y agoLooks similar to https://templ.guide/ https://templ.guide/ Which imho has a nicer syntax for the templates.
- lukeholder 3y agoAgree. I really wish TAL template were more popular though, I’m intrigued about using them with HTMX.
- shp0ngle 3y agoit was explicitly based on templ, see the readme
- quechimba 3y agoLooks good, Haml is a great templating language. The biggest problem with Haml is probably that it's really difficult to write a tree-sitter parser for it. In this case, you would have to parse both haml, go, CSS and JavaScript and be aware of indentation.
- sbergot 3y agoThere is a similar haskell project: https://hackage.haskell.org/package/hamlet https://hackage.haskell.org/package/hamlet
- whateveracct 3y agoName collision with the same sort of library but in Haskell (it's a decade+ old too) https://hackage.haskell.org/package/hamlet https://hackage.haskell.org/package/hamlet Although to be fair, it's hard not to name a Haml library "Hamlet" ^_^