Simple Object-oriented Mustache rendering engine

Mustache rendering engine which follows Object-oriented practices.

Лицензия

Лицензия

Группа

Группа

com.github.piotrkot
Идентификатор

Идентификатор

mustache
Последняя версия

Последняя версия

1.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

Simple Object-oriented Mustache rendering engine
Mustache rendering engine which follows Object-oriented practices.
Ссылка на сайт

Ссылка на сайт

https://github.com/piotrkot/simple-mustache
Система контроля версий

Система контроля версий

https://github.com/piotrkot/simple-mustache

Скачать mustache

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.piotrkot/mustache/ -->
<dependency>
    <groupId>com.github.piotrkot</groupId>
    <artifactId>mustache</artifactId>
    <version>1.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.piotrkot/mustache/
implementation 'com.github.piotrkot:mustache:1.2'
// https://jarcasting.com/artifacts/com.github.piotrkot/mustache/
implementation ("com.github.piotrkot:mustache:1.2")
'com.github.piotrkot:mustache:jar:1.2'
<dependency org="com.github.piotrkot" name="mustache" rev="1.2">
  <artifact name="mustache" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.piotrkot', module='mustache', version='1.2')
)
libraryDependencies += "com.github.piotrkot" % "mustache" % "1.2"
[com.github.piotrkot/mustache "1.2"]

Зависимости

compile (5)

Идентификатор библиотеки Тип Версия
com.google.guava : guava jar 18.0
org.cactoos : cactoos jar 0.42
org.slf4j : slf4j-api jar 1.7.18
org.slf4j : slf4j-simple jar 1.7.18
org.hamcrest : hamcrest-all jar 1.3

provided (1)

Идентификатор библиотеки Тип Версия
org.projectlombok : lombok jar 1.16.6

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12

Модули Проекта

Данный проект не имеет модулей.

Simple-mustache

This is simple object-oriented Java implementation of mustache templates. Although there is already available one from spullara I personally find it difficult to extend and fix, with unclear API, and few bugs when different tag delimiter used.

For that I propose a simpler and object-oriented alternative.

Tag types supported

Variables

The basic tag {{name}} Example:

new Mustache("Hello {{name}}").supply(ImmutableMap.of("name", "John"));

returns Hello John.

Sections

Tag composed of two tags {{#name}} {{/name}} for which content within the tags is rendered one or more times. Example:

new Mustache("Greetings to{{#friends}} {{name}}{{/friends}}").supply(
  ImmutableMap.of(
    "friends", ImmutableList.of(
      ImmutableMap.of("name", "John"),
      ImmutableMap.of("name", "Mark"),
      ImmutableMap.of("name", "Ann")
    )
  )
);

returns Greetings to John Mark Ann.

Inverted sections

Tag composed of two tags {{^name}} {{/name}} which is the inversion of the section tag. That is content is rendered only once on the inverse value of the tag name (tag key). Example:

new Mustache("Greetings in return{{^greets}} - none{{/greets}}").supply(
  ImmutableMap.of("greets", Collections.emptyList())
);

returns Greetings in return - none.

Partials

It's of a form {{>name}} where value for the tag name is file content. File content can be a String, Path or InputStream. The content can contain other Tag types except partials. Recursive partials are not supported to avoid infinite loops. Example:

new Mustache("Hope to get a {{>surprise}}").supply(
  ImmutableMap.of("surprise", new ByteArrayInputStream("gift!".getBytes()))
);

returns Hope to get a gift!.

Delimiters

Arbitrarily any delimiter can be used but use it with care. Otherwise you will end up with unexpected outcome. Example:

public final class SquareMustache extends AbstractMustache {
    public SquareMustache(final String content) {
        super(content);
    }
    @Override
    public String start() {
        return "[[";
    }
    @Override
    public String end() {
        return "]]";
    }
}

Limitations

There is no validation phase for content generation. Illegal template or tags will be unrecognized without a warning.

Tag names must be composed of any word characters (A-Za-z0-9_) including dot (.).

Within tags spaces are allowed as long as they do not split the tag names.

To get started, add dependency to your project:

<dependency>
    <groupId>com.github.piotrkot</groupId>
    <artifactId>mustache</artifactId>
    <version>1.2</version>
</dependency>

Feel free to fork me on GitHub, report bugs or post comments.

For Pull Requests, please run mvn clean package -Pqulice, first.

Версии библиотеки

Версия
1.2
1.1
1.0