[HN Gopher] Using ELisp as an HTML templating engine
       ___________________________________________________________________
        
       Using ELisp as an HTML templating engine
        
       Author : todsacerdoti
       Score  : 26 points
       Date   : 2022-04-09 10:51 UTC (1 days ago)
        
 (HTM) web link (bitspook.in)
 (TXT) w3m dump (bitspook.in)
        
       | b3morales wrote:
       | Why an alist for the properties rather than a plist?
        
       | tonetheman wrote:
       | This 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 wrote:
         | Isn'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 wrote:
           | Reading your description is pretty cool. I too will look at
           | emacs again.
        
       | MarkSweep wrote:
       | It'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
       | 
       | [2]: https://github.com/phplang/xhp
       | 
       | [3]: https://docs.microsoft.com/dotnet/visual-
       | basic/programming-g...
        
         | foldr wrote:
         | You 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.
        
       | neilv wrote:
       | For 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
       | 
       | 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/
        
         | nerdponx wrote:
         | Big +1 and thank you for reminding me to try making a Hy
         | implementation.
        
       | User23 wrote:
       | The quasiquote is one of the many really cool things about Lisp.
       | It makes all kinds of templating really easy.
        
       | MathMonkeyMan wrote:
       | Yes, using _any_ lisp 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...
       | 
       | and a Javascript version:
       | 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
        
       | askonomm wrote:
       | This 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 (documentation pending,
       | check out example site at https://github.com/askonomm/bien.ee)
       | 
       | [1]:
       | https://github.com/askonomm/bien.ee/blob/master/src/feed.xml...
       | 
       | [2]:
       | https://github.com/askonomm/bien.ee/blob/master/src/index.ht...
        
       ___________________________________________________________________
       (page generated 2022-04-10 23:01 UTC)