Selector based html templating library for Java similar to Enlive
Asked Answered
T

3

6

Is anyone aware of a template library for java similar in nature to Enlive?

The concept of using plain html for pages, without any markup inside, and to use the equivalent of CSS selectors to populate the page with dynamic data seems pretty good to me.

For more information what kind of templating I am looking for take a look at this blog post for an example.

I know that it would be possible to create Enlive wrapper in Java and use that, but I am looking at the existing Java alternative.

Thalweg answered 22/6, 2011 at 10:50 Comment(0)
K
6

If it's not too late, I would suggest you have a look at Moulder, a templating library where generating a page is done by selecting elements from the original template and applying transformations on them. More resources on the subject:

Disclaimer: I am the author of this library.

Klepht answered 8/7, 2011 at 8:43 Comment(1)
Thanks for this. It was exactly what I was looking for. Still much more verbose than Enlive, but given that it is Java, it's pretty bearable.Thalweg
B
4

because enlive depends on clojure's elegance of expression to do its magic an implamentation in java would likely loose that magic.

"The Enlive approach to templating is functional and decouples design and presentation logic." and " There is a kind of inversion of control here. In most mainstream templating systems, templates drive the presentation logic.". this would likely require extensive use of "the visitor pattern" to accomplish in a strait java library.

You'll likely be better off java-wrapping the parts you need to expose to the non-clojure world. and write your templates in clojure. Though I understand there are lots of good reasons why this approach may not fit within your project/organization.

Bierce answered 22/6, 2011 at 21:10 Comment(0)
J
2

I was looking the other night at the keynote of James Strachan at ScalaExchange about Scalate.

It is a templating engine which contains a set of template langauges. I've been looking at it to use the Mustache part, bu there is a templating system in it called Scuery which is also based on CSS/JQuery like selectors.

Actually it is a good presentation which shows implementation of a wide set of templating solutions. Scaml + Markdown looks really nice too.

Strictly speaking it is scala, but AFAICT you can just use the API from Java. Of course the some of template languages have scala based DSL's embedded.

Juliettajuliette answered 22/6, 2011 at 21:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.