Template
Paprika embeds a templating engine, based on the {{Mustache}} specifications. Paprika differs from classical Mustache engine in the way that the data are provided by Paprika, and not by the user. The template can be configured (see configuration) for each specific goal. And, like any Mustache implementation, some feature have been added and some are ignored.
Engine
Like said in introduction, the engine is based on the Mustache specifications. We suggest at least skimming the provided documentation: even if we will approach point by point the various functionalities of the framework, we will not go into the details when these are simply compliant with the standard.
Each example will be expressed in a yaml structure with three fields: the data
field represents the data, which will be generated by Paprika. The template
field is the template, configured by the user. Finally result
is the result produced by this engine.
Variables
The variable interpolation is done as it is specified in the standard. The only difference is about escaping: by default no escaping is performed, but you can change this comportment with the configuration key template.escaper
(see configuration).
data:
subject: "World"
template: "Hello, {{subject}}!"
result: "Hello, World!"
data:
person:
name: "Joe"
template: "Hello, {{person.name}}!"
result: "Hello, Joe!"
Disable escaping variable with a triple braces ({{{name}}}
) or with &
({{& name}}
) are supported.
Sections
Sections can be used to defined a context or display something conditionally or iterate on lists, as it is specified in the standard. The tag is treated as standalone when the situation is appropriate, removing the previous white spaces and the next new line characters.
data:
person:
name: "Joe"
template: "Hello, {{#person}}{{name}}{{/person}}!"
result: "Hello, Joe!"
data:
first: true
second: false
template: "{{#first}}This is rendered.{{/first}}{{#second}}And this is not.{{/second}}"
result: "This is rendered."
data:
list:
- item: 1
- item: 2
- item: 3
template: "{{#list}}{{item}}{{/list}}"
result: "123"
data:
list:
- item: 1
- item: 2
- item: 3
template: |-
My pretty list:
{{#list}}
- {{item}}
{{/list}}
result: |-
My pretty list:
- 1
- 2
- 3
The closing tag can always be abbreviated by {{/}}
:
data:
list:
- item: 1
- item: 2
- item: 3
template: "My inline list:{{#list}} {{item}}{{/}}"
result: "My inline list: 1 2 3"
You can use the implicit iterator {{.}}
to output the current context or the current iterated object:
data:
list: [ "a", "b", "c" ]
template: "My implicit list:{{#list}} {{.}}{{/}}"
result: "My implicit list: a b c"
During a list iteration, additional keys can be accessed:
@first
is true for the first item only.@last
is true for the last item only.@index
is the 0-based index of the item (0, 1, 2,…)@indexPlusOne
is the 1-based index of the item (1, 2, 3, …)@indexIsEven
is true if the 0-based index is even.
These keys only refers to the inner-most enclosing section.
data:
list: [ "a", "b", "c" ]
template: |-
My numeroted list:
{{#list}}
{{@index}}. {{item}}
{{/list}}
result: |-
My numeroted list:
1. a
2. b
3. c
Inverted Sections
Inverted section can be used as the standard specifies.
data:
first: false
second: true
template: "{{^first}}This is rendered.{{/first}}{{^second}}And this is not.{{/second}}"
result: "This is rendered."
data:
list: []
template: "{{^list}}The list is empty!{{/list}}"
result: "The list is empty!"
Like sections implicit closing tag ({{/}}
) can be used. An implicit inverted tag ({{^}}
) can also be used to create some kind of if-then-else structure:
data:
list: []
template: "My empty list:{{#list}} {{.}}{{^}} empty!{{/}}"
result: "My empty list: empty!"
Inverted section can used with the additional keys (@first
, @last
and @indexIsEven
):
data:
list: [ "a", "b", "c" ]
template: "My glamorous list: {{#list}}{{.}}{{^@last}}, {{/}}{{/}}"
result: "My glamorous list: a, b, c"
Comments
The template can contain some comments, which will be ignored during the rendering.
data:
template: "12345{{! Comment }}67890"
result: "1234567890"
data:
template: |-
Begin.
{{!
Comment can be multiline.
They are also considered as standalone,
when it is appropriate.
}}
End.
result: |-
Begin.
End.
Partials
The engine supports partials. To define a partial, see the configuration section. Indentation are respected, as the standard specifies it.
data:
text: "content"
template: ">{{>partial}}<"
partials:
partial: "*{{text}}*"
result: ">*content*<"
data:
content: |-
<
->
template: |
\
{{>partial}}
/
partials:
partial: |
|
{{{content}}}
|
result: |
\
|
<
->
|
/
Delimiters
Tag delimiters ({{
and }}
) can be redefined, as the standard specifies.
data:
text: "Hey!"
template: "{{=<% %>=}}(<%text%>)"
result: "(Hey!)"
Not implemented features
Some feature are not implemented. If they happen to be requested and necessary, they may be implemented.
Data
Data given as inputs of the templating engine are provided by the computations of Paprika. Each data types follow a model which are explained here.
Version
The data model for a version can be used to extract the different fields, according to the semver specifications.
Key | Description |
---|---|
. |
The complete version. |
major |
The major part of the version (1 in 1.2.3 ). |
minor |
The minor part of the version (2 in 1.2.3 ). |
patch |
The patch part of the version (3 in 1.2.3 ). |
prereleases |
The pre-release parts, iterable ({{#prereleases}}-{{.}}{{/}} displays each pre-release tag separated with a dash). |
prereleases.<tag> |
true if <tag> is defined as a pre-releases tag. For example, {{#prereleases.SNAPSHOT}}XXX{{/}} displays XXX only if the version is a snapshot, like in 1.2.3-SNAPSHOT . |
builds |
The build parts, iterable ({{#builds}}-{{.}}{{/}} displays each build tag separated with a dash). |
builds.<tag> |
true if <tag> is defined as a build tag. For exemple, {{#builds.LINUX}}XXX{{/}} displays XXX only if the version is containing the build tag LINUX , like in 1.2.3+LINUX . |
Date
The data model for a date, with all the imaginable formatters.
Key | Description |
---|---|
. |
The date formatted with ISO_DATE_TIME . |
format |
(lambda) Can be used to format the date. Used as a section, in inner template defines the pattern to format the date, see the table Pattern Letters and Symbols for the meanings of the available characters. For example, {{#date.format}}HH:mm:ss{{/}} extract only the time (hour:minute:seconds) of the date. |
BASIC_ISO_DATE |
BASIC_ISO_DATE formatter |
ISO_LOCAL_DATE |
ISO_LOCAL_DATE formatter |
ISO_OFFSET_DATE |
ISO_OFFSET_DATE formatter |
ISO_DATE |
ISO_DATE formatter |
ISO_LOCAL_TIME |
ISO_LOCAL_TIME formatter |
ISO_OFFSET_TIME |
ISO_OFFSET_TIME formatter |
ISO_TIME |
ISO_TIME formatter |
ISO_LOCAL_DATE_TIME |
ISO_LOCAL_DATE_TIME formatter |
ISO_OFFSET_DATE_TIME |
ISO_OFFSET_DATE_TIME formatter |
ISO_ZONED_DATE_TIME |
ISO_ZONED_DATE_TIME formatter |
ISO_DATE_TIME |
ISO_DATE_TIME formatter |
ISO_ORDINAL_DATE |
ISO_ORDINAL_DATE formatter |
ISO_WEEK_DATE |
ISO_WEEK_DATE formatter |
ISO_INSTANT |
ISO_INSTANT formatter |
RFC_1123_DATE_TIME |
RFC_1123_DATE_TIME formatter |
Identity
An identity in the Git philosophy (a name, an email and a date).
Key | Description |
---|---|
. |
The name of the identity (see name ). |
name |
The name of the identity. |
email |
The email of the identity. |
when |
The date of the identity. See Date. |
Commit
A Git commit.
Key | Description |
---|---|
. |
The short id (9 characters) of the commit (see shortId ). |
id |
The id (complete SHA-1) of the commit. |
shortId |
The short id (9 characters) of the commit. |
author |
Author of the commit. See identity. |
committer |
Committer of the commit. See identity. |
when |
Extract a date of the commit, alias for commiter.when . See date. |
message |
Message of the commit. See commit message. |
Commit Message
A Git commit message, potentially formatted with Conventional Commit with some adaptations:
- Several scopes can be defined, separated by a comma:
feat(lang,doc): add Bantu language.
- Footers are defined as one key (case insensitive) and one or several values. Each value is defined on its own line, or several footers with the same key can be defined:
feat: adding best feature ever.
Refs: #123
#456
Reviewed-by: Me
Refs: #789
In this case, the footer REFS
will contains values #123
, #456
and #789
.
- Breaking changes are indicated by adding a bang in the first line, before the first colon, or by defining a footer
BREAKING CHANGE
orBREAKING-CHANGE
(case insensitive). In accordance with the specification, if a bang is used and no footerBREAKING CHANGE
orBREAKING-CHANGE
is defined, a footerBREAKING-CHANGE
is automatically created, and contains the description as value.
Key | Description |
---|---|
. |
First line of the message (see firstLine ). |
full |
Full message. |
firstLine |
First line of the message (new line excluded). |
conventional |
true if the message follows the Commit Conventional convention. |
type |
type of the message, if the message is conventional. |
scope |
iterable list of scope of the message, if the message is conventional. |
scope.<key> |
true if the message is conventional and <key> is a scope (case insensitive) of the message. |
breaking |
true if the message if conventional and introduce a breaking change. |
body |
body of the message, if the message is conventional. |
footers |
iterable list of footers. See after for the data model of a footer. |
footer.<key> |
get the values of the footer <key> (case insensitive), if it exists. (Notice the missing s compared with the list footers .) See after for the data model of a footer. |
A footer itself have a data model:
Key | Description |
---|---|
. |
Values of the footer, separated by a new line character. |
key |
Key of the footer. The key is in upper case, and the breaking change footer key is BREAKING-CHANGE with a dash. |
breaking |
true if that footer describes a breaking change. |
Tag Commit
A tag commit is a special commit created as an annotation for a tag.
Key | Description |
---|---|
. |
The id (complete SHA-1) of the annotation commit. |
tagger |
Author of the tag. See identity. |
when |
Extract a date of the commit, alias for tagger.when . See date. |
message |
Message of the commit. See commit message. |
Release
A release is corresponds to a release of a module, which is a set of commits marked with a tag (annotated or not, but following the mandatory pattern). The most recent modifications of a module can be not associated with a tag.
Key | Description |
---|---|
. |
The version extracted from the tag, or an empty string if the release is not tagged. |
name |
The complete name of the tag. |
version |
The version extracted from the tag. See version. |
released |
true if the release is associated with an actual tag. |
tag |
Annotation of the tag, if any. See tag commit. |
tagged |
true if the tag is annotated. |
changes |
An iterable list of the commits associated with the release. See commit. |
Release Goal
When calling the release
goal, the message of the annotated tag can be customized. Follow the configuration to knowing how to configure the template. The template can use the following data:
Key | Description |
---|---|
groupId |
The group id of the released artifact. |
artifactId |
The artifact id of the released artifact. |
packaging |
The packaging of the released artifact. |
hasParent |
true if the released artifact has a parent module with a version also managed by Paprika. |
parentGroupId |
The group id of the parent of the released artifacts. |
parentArtifactId |
The artifact id of the parent of the released artifacts. |
parentPackaging |
The packaging of the parent of the released artifacts. |
version |
The new version of the released artifact. See version. |
baseVersion |
The previous version of the released artifact. See version. |
lastCommit |
The last commit bringing a modification in the module. See commit. |
The default message template is Release {{artifactId}} {{version}}
.
Changelog Goal
When calling the changelog
goal, the template of the changes can be customized. Follow the configuration to knowing how to configure the template. The template can use the following data:
Key | Description |
---|---|
releases |
The iterable list of releases. See release. |
The default template is:
{{#releases}}
{{#released}}
# {{version}}{{#tagged}} ({{tag.when.ISO_LOCAL_DATE}}){{/}}
{{^}}
# Not released
{{/released}}
{{#changes}}
{{#message.conventional}}
* [{{shortId}}] {{message.type}}{{#message.breaking}}!{{/}}: {{message.description}}
{{^}}
* [{{shortId}}] {{message.firstLine}}
{{/}}
{{^changes}}
_No change._
{{/changes}}
{{/releases}}