3 ms·
I have a library for this sort of thing (but without the HAML-style # and . niceties :-/) which can also output DOM Elements or HTML (escaped by default) from t
by insin 15y ago
I have a library for this sort of thing (but without the HAML-style # and . niceties :-/) which can also output DOM Elements or HTML (escaped by default) from the same code by flipping its output mode: https://github.com/insin/DOMBuilder https://github.com/insin/DOMBuilder
The output modes are implemented as plugins, so you can also add other sorts of things, like the template mode I'm in the progress of writing, with template inheritance and the like.
Bretthopper's comment about the readability is spot on, though - you have to start using comma-first pretty quickly or you will go mad getting commas in the right places, and you're never going to get a designer writing these things.
The good thing about it is that since your templates are written in code, it's trivial to share them between client and server - this example app can also be clones and run on Node.js, which uses the same templates to serve full pages when you hit any URL and works as a forms 'n links webapp if you disable JavaScript in your browser: http://jonathan.buchanan153.users.btopenworld.com/sacrum/fragile/fragile.html http://jonathan.buchanan153.users.btopenworld.com/sacrum/fra...
- MatthewPhillips 15y agoThat looks pretty cool, but I have to ask... you're using with? Really?
- insin 15y agoYes, it's perfect for building templates in code based on an object defining your templating API - code which is run once at startup with little or no assignment and no ambiguity between the contents of the context object and anything else, e.g.: https://github.com/insin/sacrum/blob/master/fragile/lib/fragile.js#L450-482 https://github.com/insin/sacrum/blob/master/fragile/lib/frag... You could easily go back and plug in use of a single-letter variable instead of the implicit context object after the fact, but it's nicer to work with while you're building stuff up.