Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selector based html templating library for Java similar to Enlive

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.

like image 940
Marko Avatar asked Jun 22 '11 10:06

Marko


3 Answers

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:

  • On templating, and a shameless plug of Moulder
  • Moulder in action

Disclaimer: I am the author of this library.

like image 66
Jawher Avatar answered Oct 15 '22 08:10

Jawher


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.

like image 32
Arthur Ulfeldt Avatar answered Oct 15 '22 09:10

Arthur Ulfeldt


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.

like image 2
Peter Tillemans Avatar answered Oct 15 '22 08:10

Peter Tillemans