org.wisdom-framework:wisdom-mustache-template-engine

Wisdom is a web framework and integration platform for Java, enabling modularity and dynamism.

License

License

GroupId

GroupId

org.wisdom-framework
ArtifactId

ArtifactId

wisdom-mustache-template-engine
Last Version

Last Version

0.7
Release Date

Release Date

Type

Type

wisdom
Description

Description

Wisdom is a web framework and integration platform for Java, enabling modularity and dynamism.
Project Organization

Project Organization

Wisdom Framework
Source Code Management

Source Code Management

https://github.com/wisdom-framework/wisdom-mustache-template-engine/

Download wisdom-mustache-template-engine

Dependencies

compile (4)

Group / Artifact Type Version
org.wisdom-framework : wisdom-api jar
org.apache.felix : org.apache.felix.ipojo.annotations jar 1.12.1
org.wisdom-framework : wisdom-test jar
com.github.spullara.mustache.java : compiler jar 0.9.0

provided (2)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.9
org.ow2.chameleon : chameleon-core jar 1.10.3

test (5)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 1.7.0
org.mockito : mockito-all jar 1.10.17
org.fluentlenium : fluentlenium-assertj jar 0.10.3
org.slf4j : slf4j-jcl jar 1.7.6

Project Modules

There are no modules declared in this project.

Mustache Template Engine for Wisdom

Mustache is a logic-less templates. It can be used from almost any language. This extension provides the Mustache Template Language for server-side templating. It relies on Mustache.java, and so inherits from all its features. This extension can be used along with Thymeleaf, the default template engine of Wisdom.

Usage

To use Mustache, just add the following Maven dependency to you pom.xml file:

<dependency>
    <groupId>org.wisdom-framework</groupId>
    <artifactId>wisdom-mustache-template-engine</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Then, you can write Mustache templates. These templates are either in:

  • src/main/resources/assets for templates embedded within your application
  • src/main/assets for external templates (not packaged with your application)

Mustache templates must have one of the following extension:

  • .mst - generates a text/plain output (you can also use .mst.plain)
  • .mst.html - generates a text/html output
  • .mst.json - generates a application/json output
  • .mst.xml - generates a application/xml output

For instance, let's create src/main/resources/assets/list.mst.json:

[
    {{#items}}
        {
        "Name": "{{name}}",
        "Price": "{{price}}",
        "Feature:" [
        {{#features}}
             {{description}}
         {{/features}}
         ]}
     {{/items}}
]

Once you have created your template, using them is exactly like for regular templates:

@Controller
public class MyController extends DefaultController {

    /**
     * Retrieves the list template.
     **/
    @View("list")
    Template list;

    List<Item> items() {
        return Arrays.asList(
            new Item("Romeo", "$19.99", Arrays.asList(new Feature("New!"), new Feature("Awesome!"))),
            new Item("Tom", "$29.99", Arrays.asList(new Feature("Old."), new Feature("Ugly.")))
        );
    }
        
    @Route(method = HttpMethod.GET, uri = "/list")
    public Result jen() {
        // render the template, and build the JSON response.
        return ok(render(list, "items", items()));
    }

    static class Item {
        Item(String name, String price, List<Feature> features) {
            this.name = name;
            this.price = price;
            this.features = features;
        }
        String name, price;
        List<Feature> features;
    }

    static class Feature {
        Feature(String description) {
            this.description = description;
        }
        String description;
    }
}

Accessing HTTP data from the templates

This extension automatically injects HTTP data in the template context. Are accessible:

  • session data
  • flash data
  • HTTP parameters

Template as a Service

Don't forget that every template matching one of the extensions listed above is exposed as an OSGi service, and so inherits from its dynamic. This also implies that partials are resolved at runtime.

org.wisdom-framework

Wisdom Framework

Versions

Version
0.7