4 ms·
Using ELisp as an HTML templating engine
- tonetheman 5y agoThis is interesting to me. It feels like you just moved the problem though. Now you have to remember HTML and your mapping from elisp to HTML. If you really like elisp maybe that is not a bad trade off.
- rurusnapsnap 5y agoIsn't the mapping 1-1? Lisp is pretty much what you'd get after parsing HTML; Elisp shown in the post isn't even code (as in it don't really execute). It is just text which is native to ELisp, hence is much easier to manipulate. I like it, because this is essentially removing a layer of abstraction. What would otherwise be 'code -> templating-engine -> html', is now 'code -> html'. Saying it out loud, it is sort of beautiful :) May be I should dust-off my ol' Emacs again.
- tonetheman 5y agoReading your description is pretty cool. I too will look at emacs again.
- fiddlerwoaroof 5y agoHiccup[1] in Clojure and spinneret[2] in Common Lisp are implementations of a similar idea. [1]: https://practical.li/clojurescript/hiccup-style-syntax.html https://practical.li/clojurescript/hiccup-style-syntax.html [2]: https://github.com/ruricolist/spinneret https://github.com/ruricolist/spinneret
- b3morales 5y agoWhy an alist for the properties rather than a plist?
- User23 5y agoThe quasiquote is one of the many really cool things about Lisp. It makes all kinds of templating really easy.
- MarkSweep 5y agoIt’s cool that you can express this sort of structure in Lisp without any change to the language. This contrasts to extensions to other languages that allow an XML-like syntax. For example JSX for JavaScript [1], XHP for PHP [2], and XML Literals for VB.NET[3]. [1]: https://reactjs.org/docs/introducing-jsx.html https://reactjs.org/docs/introducing-jsx.html [2]: https://github.com/phplang/xhp https://github.com/phplang/xhp [3]: https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/xml/xml-literals-overview https://docs.microsoft.com/dotnet/visual-basic/programming-g...
- foldr 5y agoYou could use exactly the same encoding in Javascript with just a little more syntactic overhead (and strings instead of symbols). The syntactic overhead could easily be reduced by defining some functions and constants. This sort of approach to HTML generation is popular in the Lisp community, but it doesn't really rely on any features unique to Lisp.
- User23 5y agoLisp has served as an inspiration to so many programming language designs, Javascript included, that saying a language feature isn't really unique to Lisp is a bit like saying that The Lord of the Rings is just a bunch of fantasy clichés. It's true in some sense, but it also conveys a deeply flawed understanding. Here[1] is a fun example of what's possible with a Common Lisp library that would be difficult to do in many other languages without language changes or essentially just giving up and dumping the C style code in a string and calling some sort of eval on it. That is very much not the same thing. [1] https://github.com/y2q-actionman/with-c-syntax/ https://github.com/y2q-actionman/with-c-syntax/
- foldr 5y agoWhat you link to is an example of something that you can only really do in Lisp, yes. However, using nested lists to represent an HTML document - which is what I was actually talking about - is not something that you can only do in Lisp. In the version of English that I speak, “features unique to Lisp” does not mean “features that no language had prior to Lisp” or “features that were inspired by Lisp” but rather “features that no language other than Lisp has”.
- neilv 5y agoFor HTML and XML in S-expressions, people might want to consider standardizing on Oleg Kiselyov's SXML representation, as a lot of others have. https://okmij.org/ftp/Scheme/xml.html#SXML-spec https://okmij.org/ftp/Scheme/xml.html#SXML-spec SXML is a little harder to process in libraries, compared to some representations we initially try, but SXML turns out to be easier to use in practice, at least by users of the library. For example, splices can be much more efficient, and easier to do without making a programming error that's not detected statically. You can also mimic it in syntax, like: https://docs.racket-lang.org/html-template/ https://docs.racket-lang.org/html-template/
- nerdponx 5y agoBig +1 and thank you for reminding me to try making a Hy implementation.
- askonomm 5y agoThis is neat. I actually built a static site generator[0] that uses Clojure for the templating language, and that enables me to do some things like build my own RSS feed [1] or a custom archive front page [2]. Pretty happy with this over Handlebars or the like to be honest. [0]: https://github.com/askonomm/bruno https://github.com/askonomm/bruno (documentation pending, check out example site at https://github.com/askonomm/bien.ee https://github.com/askonomm/bien.ee) [1]: https://github.com/askonomm/bien.ee/blob/master/src/feed.xml.clj https://github.com/askonomm/bien.ee/blob/master/src/feed.xml... [2]: https://github.com/askonomm/bien.ee/blob/master/src/index.html.clj https://github.com/askonomm/bien.ee/blob/master/src/index.ht...
- MathMonkeyMan 5y agoYes, using anylisp as an anything templating engine. I love this stuff. It's not as ideal, but you can even get away with this in Python using comprehensions and functions. Any language with nested data structure literals will do. Really, any expression language. Here's a Python version: https://github.com/dgoffredo/dgoffredo.github.io/blob/master/bin/sxml.py https://github.com/dgoffredo/dgoffredo.github.io/blob/master... and a Javascript version: https://github.com/dgoffredo/llama/blob/master/llama/xml.js https://github.com/dgoffredo/llama/blob/master/llama/xml.js ...and as others have said, Scheme has "sxml," which I use here: https://github.com/dgoffredo/xsd-gc https://github.com/dgoffredo/xsd-gc
- smitty1e 5y agoFor python, I've used: (1) Triple-quoted strings to set up large markup forms (2) The `%()s` syntax to set up dictionary interpolations (3) Something like: def merge(template, args): return template % args to deliver the goods.
- Existenceblinks 5y agoI hate the status quo of the html template engine. They are not portable at all. No winner, not even most popular, that means no consensus. We should be able to unlock platform locked-in and be able to move/reuse templates around Shopify, Wordpress, Webflow, whatever platform/framework that can fill dynamic data into html template. Javascript based templates are the worst for portability. ELisp seems like going to the right direction but I'd like to hear more about logic-ful or logic-less, what should only be allowed in template, how context-free it is, etc. ps; as someone who hate parsing stuff with passion. give me a format that's good enough for hand authoring programmable format. S-expression is close .. but not yet a great solution.
- Existenceblinks 5y agoIs there any specification for this elisp based html template?