3 ms·
Flow control does not belong in markup. My favourite templating system is enlive[1] (or enliven[2]). You use CSS-style selectors to select snippets of HTML to
by dkersten 11y ago
Flow control does not belong in markup.
My favourite templating system is enlive[1] (or enliven[2]). You use CSS-style selectors to select snippets of HTML to manipulate and then use code to duplicate, remove, move or replace these snippets, insert content, set attributes etc.
The "template" is pure HTML without any additional markup and without any logic. The code then says "repeat this snippet for every item in this list and insert it over there" (or whatever you need). Markup does what its good at, code does what its good at. Works out really nicely.
Although nowadays I use reagent and hiccup-style markup and write everything in code (but keep my components as pure and dumb as possible).
[1] https://github.com/cgrand/enlive https://github.com/cgrand/enlive
[2] https://github.com/cgrand/enliven https://github.com/cgrand/enliven
- astoilkov 11y agoWhat do you think about OneScript - https://github.com/astoilkov/OneScript https://github.com/astoilkov/OneScript?
- dkersten 11y agoCan't say I'm a fan honestly. Reminds me too much of PHP, I guess. The thing about reagent/hiccup is that the markup is just a clojurescript data structure and can be composed and manipulated like one. This also means that you can easily write pure functions to generate the UI (data in, markup out). The thing about enlive/enliven is that the markup and the logic are completely separated. OneScript has neither of the things that I like about enlive or reagent. EDIT: I should probably add that I'm not particularly a fan of JSX either, so I'm probably the wrong person to ask for an opinion on this.
- Wintamute 11y agoHow do the frontenders and CSS folk feel about you making assumptions about what CSS selectors there should be in order to render a template on the backend? Its hard enough to get dedicated frontend folk to stick to an adaptable/maintainable CSS architecture like SUITCSS, let alone backenders too. I've always thought Enlive seems to create a brittle co-dependency between frontend and backend codebases, ok for small projects with 1 or 2 devs with skills that span front and backend, but surely a nightmare for larger project with lots of people working on them?
- arnarbi 11y agoGenshi [1] is (was?) wonderful in a similar respect. Although the "code" was itself an html document, it allows master templates to fully select and manipulate nodes from child templates. [1] http://genshi.edgewall.org/ http://genshi.edgewall.org/