Templates4J

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

Categories

Categories

Net
GroupId

GroupId

net.evilengineers.templates4j
ArtifactId

ArtifactId

templates4j-parent
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

pom
Description

Description

Templates4J
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

http://github.com/danishdynamite/templates4j

Download templates4j-parent

How to add to project

<!-- https://jarcasting.com/artifacts/net.evilengineers.templates4j/templates4j-parent/ -->
<dependency>
    <groupId>net.evilengineers.templates4j</groupId>
    <artifactId>templates4j-parent</artifactId>
    <version>1.1.0</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/net.evilengineers.templates4j/templates4j-parent/
implementation 'net.evilengineers.templates4j:templates4j-parent:1.1.0'
// https://jarcasting.com/artifacts/net.evilengineers.templates4j/templates4j-parent/
implementation ("net.evilengineers.templates4j:templates4j-parent:1.1.0")
'net.evilengineers.templates4j:templates4j-parent:pom:1.1.0'
<dependency org="net.evilengineers.templates4j" name="templates4j-parent" rev="1.1.0">
  <artifact name="templates4j-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='net.evilengineers.templates4j', module='templates4j-parent', version='1.1.0')
)
libraryDependencies += "net.evilengineers.templates4j" % "templates4j-parent" % "1.1.0"
[net.evilengineers.templates4j/templates4j-parent "1.1.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • templates4j-core
  • templates4j-extension-antlr
  • templates4j-extension-java
  • templates4j-extension-strings
  • templates4j-extension-xml
  • templates4j-extension-json
  • templates4j-maven-plugin

Extensible template engine for Java

Based upon StringTemplate4, this engine extends it with some very useful features making it applicable for a wider range of templating needs.

It aims to be backwards compatible with ST4-grammar.

User Functions

Since 1.0.0

Often you'll find yourself needing to navigate your model in ways that the template engine does not support natively. This is especially true for ST4, so I've introduced a way to supply user-defined functions that are callable from the template itself. These are called in the same manner as the few built-in functions (strlen, trunc, etc..), but they can accept multiple arguments, each of which can be an expression itself.

Let's say you would like to iterate over a list of objects present somewhere in a DOM-based model, you could do this by executing an XPath-query from your user-function which you'd call from the template like this:

<xpath(model, {//book/author[id='xxx']/parent::chapters}) : outputChapter()>

where model is your DOM model, xpath is your user-function, outputChapter is a another template and { ... } is an anonymous template evaluating to the XPath expression for the query.

Multi-character delimiters

Since 1.0.1

The engine uses a start- and end-delimiter to locate the expressions in your template. Previously, these were limited to a single character, but that has now been generalized so you can use strings of two or more characters as delimiters as needed. This allows you to more easily select delimiters that wont conflict with your template content, making the use of backslash-escaping unnecessary resulting in more readable templates.

To use, just specify delimiters "<#", "#>" in your .stg files, or manually supply them to the constructor of the STGroup or subclasses thereof.

Usage

<dependency>
    <groupId>net.evilengineers.templates4j</groupId>
    <artifactId>templates4j</artifactId>
    <version>1.0.0</version>
</dependency>

The artifact is released in the OSS Sonatype repository:

<repository>
    <id>sonatype-nexus</id>
    <url>http://oss.sonatype.org/content/repositories/releases/</url>
</repository>

History

This project could not have existed if it wasn't for the nice work by the authors of StringTemplate4, but as the features I found necessary in my work were not accepted and because there seems to be a general demand for them, I forked the project and extended it myself. The new projectname is to avoid confusion and possible conflict with the original engine.

The templates4j-core sub-project started its life as a fork of StringTemplate4 ver. 4.0.8 code. The templates4j-mvn-plugin sub-project was written from scratch.

All are covered by a BSD-license.

Versions

Version
1.1.0