4 ms·
That will depend very much upon your HTML developers. Some will be able to do it, a large number will not. Even when using simple template languages I have exp
by timclark 15y ago
That will depend very much upon your HTML developers. Some will be able to do it, a large number will not.
Even when using simple template languages I have experienced the I didn't understand those funny bits in the HTML so I have removed them far too many times.
In Clojure, Enlive (https://github.com/cgrand/enlive https://github.com/cgrand/enlive) is a better solution because the HTML remains as HTML.
- markokocic 15y agoIs anyone aware of something similar to enlive in pure Java? I would certainly like to give it a try.
- SergeyHack 15y agoWicket and Tapestry are trying to do the similar thing. Not as good as Enlive though.
- ibdknox 15y agoI agree that it depends pretty heavily on who is doing your HTML. That being said, you can just not use the defpartial stuff and instead include Enlive to use with Noir just as well. There are purposefully no constraints on what you use to generate HTML. The main purpose of settling on Hiccup in this case is to provide something that I think the Clojure web community desperately needs: a single place to start and build something. The only way I can provide that start pointing is by making some choices and running with them. Also, I really love html functions as opposed to JQuery-esque template filling. It's cleaner and more flexible to me.
- weavejester 15y agoThe main advantage of writing HTML using a tool like Hiccup is that you can factor out repeated sections of markup into functions. For example, one might write a page like: (defn user-settings [user] (settings-for [user] (breadcrumbs (link home) (link settings)) (text-field :login) (text-field :email))) And the functions used would take care of generating the page, layout, form, fields, error notices, flash messages, CSRF protection and so forth. By the time you've finished with all that, those 4 lines of Clojure will be 50 lines of HTML. Hiccup tends to lend itself toward user interfaces that are uniform and predictable, with repeatable elements. Think Facebook or Github, for instance.
- swannodette 15y agoI don't see how this any different from what Enlive provides. Enlive templates/snippets create functions which generate HTML. In anycase, using Hiccup with Enlive seems to combine the best of both worlds.
- weavejester 15y agoHTML is a markup language, rather than a Turing Complete programming language, so there's a lot of redundancy in a HTML file that could be avoided in a programming language. You can get around this in Enlive and other HTML-based templating methods by taking a hybrid approach. The layout HTML is written by a designer, but all the tedious repeatable elements are written by programmers in helper functions, or factored out into dozens of smaller templates. I'm not sure I like this approach, as it (a) glues together several different methods for generating HTML, (b) encourages people to write the HTML around the page design, rather than treating HTML as purely semantic markup. I admit to being something of a purist when it comes to HTML. I'd prefer to keep the style and design of the page out of my HTML as much as possible; idiomatic HTML should be semantic markup, whilst the design of the page should be defined in CSS.
- swannodette 15y agoI don't see anything in Enlive which is at odds with your viewpoint.
- weavejester 15y agoMy viewpoint is that HTML shouldn't be written directly, because the language isn't designed to be particularly DRY. Isn't that very much at odds with Enlive?
- swannodette 15y agoEnlive does exactly what Hiccup does with the additional bonus that it allows designers who are comfortable with HTML to be a part of the process. Enlive is not page centric - that's the whole point of snippets.