4 ms·
I wrote a library a little while ago which is intended to be the simplest possible expression of this idea: https://github.com/j4mie/hotmetal/ https://github.c
by j4mie 3y ago
I wrote a library a little while ago which is intended to be the simplest possible expression of this idea:
https://github.com/j4mie/hotmetal/ https://github.com/j4mie/hotmetal/
The core implementation is only 85 lines of Python, and has no imports at all, so works nicely on minimal/alternative Pythons like Micropython.
I'm using it on a medium-sized side project and it's shockingly productive compared to string templates. I don't think anyone is using it except me, though.
- eddieroger 3y agoWe've come full circle on naming HTML tools! https://en.wikipedia.org/wiki/HoTMetaL https://en.wikipedia.org/wiki/HoTMetaL
- j4mie 3y agoGlad someone got the reference!
- eddieroger 3y agoI'm glad it was intentional. :-) I don't feel as old. Still old. But less so.
- slifin 3y agoSearch for "clojure hiccup"
- egeozcan 3y agoI use gomponents with go, which is very similar. The productivity increase is immense. https://github.com/maragudk/gomponents https://github.com/maragudk/gomponents
- tzimo 3y agoThis looks really neat. One suggestion is that in your readme, show the webpage output with your examples. It’s hard to image exactly what the page will look like just looking at the hotmetal python code
- fermigier 3y agoCool idea. I had a similar one a few weeks ago, with this additional idea of turning this into a "real" templating language (e.g. by adding a special construct for conditionals, looping, variables, macro expansion...).
- samdudley 3y agoYour project looks great and I like the fact you can use it with MicroPython. I've also been working on a library with a similar idea: https://github.com/SamDudley/neat-html https://github.com/SamDudley/neat-html It's still a work in progress so an example might be better to look at: https://github.com/SamDudley/neat-html/blob/main/examples/forms.py https://github.com/SamDudley/neat-html/blob/main/examples/fo... I was inspired by some JavaScript libraries that I've used in the past: - https://github.com/jorgebucaran/hyperapp https://github.com/jorgebucaran/hyperapp - https://github.com/hyperhype/hyperscript https://github.com/hyperhype/hyperscript There is also a working integration with Django that enables the use of neat-html as a template backend, however it isn't up on GitHub yet. I find the space of HTML generation libraries which can leverage the power of Python, really interesting.
- borntyping 3y agoI've been looking for something exactly like this for a while — a small Python library for generating HTML that isn't prescriptive about framework and doesn't introduce any particually weird syntax. Jinja2 macros are... not great when you want to turn your HTML into lots of smaller functions.
- baq 3y agosee also: twisted nevow + stan, which I believe predate the term 'AJAX'. https://github.com/twisted/nevow/blob/master/examples/simple/simple.py#L19-L21 https://github.com/twisted/nevow/blob/master/examples/simple...
- elbear 3y agoThis looks like a similar model to how Elm handles HTML. Except Elm provides functions for each tag, so it also does type checking to ensure that the passed arguments correspond to the actual attributes of the tag.
- mixmastamyk 3y agoReminds me of dominate.
- polyrand 3y agoThis is wonderful, I love it. I recently wrote a blog post about generating HTML in Python using LXML (https://ricardoanderegg.com/posts/python-build-html-components-lxml/ https://ricardoanderegg.com/posts/python-build-html-componen...) and I didn't know about your library. I'll update it to add a mention to it. Apart from the simplicity, I like the fact you can "install" it by copy-pasting the code at the top of your script, or running: curl -L https://raw.githubusercontent.com/j4mie/hotmetal/main/hotmetal/__init__.py >> myscript.py which is nice when you want a self-contained file. I think I'll be using this in the future.
- asa400 3y agoNice work! There are a few expressions of this idea. There's a reason people keep coming back to it: it's actually really nice to write markup this way. https://github.com/weavejester/hiccup https://github.com/weavejester/hiccup https://github.com/JuneKelly/sneeze https://github.com/JuneKelly/sneeze
- deleted 3y ago[deleted]
- giovannibonetti 3y agoElm [1] is based on a similar idea. Build your app from pure functions that return HTML tags. [1] https://elm-lang.org/ https://elm-lang.org/