Fork me on GitHub

Groovy MarkupTemplateEngine is a Groovy-based DSL for generated XML-like markup.

Setup

1) Add the pippo-groovy dependency to your pom.xml:

<dependency>
    <groupId>ro.pippo</groupId>
    <artifactId>pippo-groovy</artifactId>
    <version>${pippo.version}</version>
</dependency>

2) Start writing Groovy MarkupTemplateEngine templates in the templates folder of your application.
Note: The default file extension of a Groovy template is .groovy and may be omitted from your Pippo Java code but not your templates.

Integration

This engine includes some useful Pippo integration features and conveniences like…

i18n

You can access your translation resources using the i18n helper.

i18n("key.name")

You can supply arguments to your MessageFormat translation resources too.

i18n("key.name", "arg1", "arg2")
prettytime (relative time)

Teh pippo-groovy module supports automatically localized prettytime out-of-the-box and it is very easy to use.

Assuming you are providing a java.util.Date instance to prettyTime…

prettyTime(myDate)

Will produce something like…

3 days ago
formatTime

You can also automatically format localized dates using standard Java date format patterns.

formatTime(now)}
formatTime(now, "short")
formatTime(now, "medium")
formatTime(now, "long")
formatTime(now, "full")
formatTime(now, "HH:mm")
formatTime(now, "dd-MM-yyyy HH:mm")
formatTime(now, "dd-MM-yyyy HH:mm")
webjarsAt & publicAt

The pippo-groovy module supports context-aware url generation for your classpath resources using the webjarsAt and publicAt methods.

// Stylesheets
link(href: webjarsAt('bootstrap/3.3.1/css/bootstrap.min.css'), rel:'stylesheet')
link(href: webjarsAt('font-awesome/4.2.0/css/font-awesome.min.css'), rel:'stylesheet')
link(href: publicAt('css/style.css'), rel:'stylesheet')

// Scripts
script(src: webjarsAt('jquery/1.11.1/jquery.min.js')) {}
script(src: webjarsAt('bootstrap/3.3.1/js/bootstrap.min.js')) {}
script(src: publicAt('js/main.js')) {}

NOTE: Use of these methods require that you have registered a WebjarsResourceRoute and/or a PublicResourceRoute.

public class MyApplication extends Application {

    @Override
    protected void onInit() {
        // add routes for static content
        addPublicResourceRoute();
        addWebjarsResourceRoute();    
        
        // add other routes
    }
    
}
AngularJS

The pippo-groovy module comes with out-of-the-box support for the following syntax:

ng("something | or | other")

The string passed to ‘ng will produce {{something | or | other}} in your generated template.

Error Templates

The pippo-groovy module will render special templates for routing problems and exceptions. You may override these templates within your own application (put a file with the same name, to same location, in your application classpath)

  • templates/pippo/404notFound.groovy
  • templates/pippo/500interalError.groovy