Add Dialect to Thymeleaf module

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Add Dialect to Thymeleaf module

Paul_Fairless
Hi,

Firstly just to say thanks for adding the thymeleaf support.

I'm looking to add the Layout Dialect plugin (https://github.com/ultraq/thymeleaf-layout-dialect), so I can use a decorator view pattern.

Is there a way to get the templateEngine so I can do this?
templateEngine.addDialect(new LayoutDialect());

Thanks
Paul
Reply | Threaded
Open this post in threaded view
|

Re: Add Dialect to Thymeleaf module

Luke Daley
Administrator
There's no formal hook for this kind of thing right now.

ATM you can do this inside the handlers {} block like this:
https://github.com/ratpack/example-books/blob/master/src/ratpack/Ratpack.groovy#L33

Instead of the closure param being BookService it would be your
templateEngine type.
Reply | Threaded
Open this post in threaded view
|

Re: Add Dialect to Thymeleaf module

Paul_Fairless
OK cool,

I think we will be using a few dialects for Joda time and layout decorator. We will also likely write some of our own to encapsulate some display logic. This leads me onto some of the (minor) grievances we've had with thymeleaf - only because you asked :)

* Parses templates with XML parser - HTML5 has elements that you wouldn't normally close. Thymeleaf will do tag balancing with a LEGACYHTML5 template mode, but it doesn't feel quite right
* BEM css naming syntax breaks pre-processor - raised issue https://github.com/thymeleaf/thymeleaf/issues/249
* The name spaced attributes start to clutter the markup making it difficult to read. It can also lead to adding extra spans and divs from time to time
* Creating dialects is far more complex than grails tag-libs ever were, and more difficult to test - element of learning curve with this one I suspect

Like I said, nothing major but they guys felt like they were battling with it, as opposed to it making their lives easier.
Reply | Threaded
Open this post in threaded view
|

Re: Add Dialect to Thymeleaf module

Marcin Erdmann
Paul, did you have a look at Handlebars.java? At least creating helper methods seems to be much simpler there... And there is support for it in Ratpack.
Reply | Threaded
Open this post in threaded view
|

Re: Add Dialect to Thymeleaf module

Paul_Fairless
Hi Marcin,

Yeah we tried handlebars, but really missed using the decorator pattern, although i think there is some support in the java implementation we needed to pass variables around which we weren't able to set. We couldn't quite make the leap into logic-less templating.
Reply | Threaded
Open this post in threaded view
|

Re: Add Dialect to Thymeleaf module

Luke Daley
Administrator
Forgot to mention that there are now init hooks…

so…

<code>
modules {
  register new ThymeleafModule()
  init { TemplateEngine templateEngine -> templateEngine.addDialect(new SomeDialect()) }
}
</code>

Some more examples: https://github.com/ratpack/ratpack/blob/master/ratpack-guice/src/test/groovy/ratpack/guice/GuiceInitSpec.groovy#L57