*
- * Default handlebars.js is handlebars-v4.7.6.js.
+ * Default handlebars.js is handlebars-v4.7.7.js.
*
* @param location A classpath location of the handlebar.js file.
*/
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
index 89820a119..aea841d99 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
@@ -313,7 +313,7 @@ public static CharSequence escapeExpression(final CharSequence input) {
private String endDelimiter = DELIM_END;
/** Location of the handlebars.js file. */
- private String handlebarsJsFile = "/handlebars-v4.7.6.js";
+ private String handlebarsJsFile = "/handlebars-v4.7.7.js";
/** List of formatters. */
private List formatters = new ArrayList<>();
diff --git a/handlebars/src/main/resources/handlebars-v4.7.6.js b/handlebars/src/main/resources/handlebars-v4.7.7.js
similarity index 99%
rename from handlebars/src/main/resources/handlebars-v4.7.6.js
rename to handlebars/src/main/resources/handlebars-v4.7.7.js
index 05d9f6141..baad5d3d9 100644
--- a/handlebars/src/main/resources/handlebars-v4.7.6.js
+++ b/handlebars/src/main/resources/handlebars-v4.7.7.js
@@ -1,7 +1,7 @@
/**!
@license
- handlebars v4.7.6
+ handlebars v4.7.7
Copyright (C) 2011-2019 by Yehuda Katz
@@ -278,7 +278,7 @@ return /******/ (function(modules) { // webpackBootstrap
var _internalProtoAccess = __webpack_require__(33);
- var VERSION = '4.7.6';
+ var VERSION = '4.7.7';
exports.VERSION = VERSION;
var COMPILER_REVISION = 8;
exports.COMPILER_REVISION = COMPILER_REVISION;
@@ -1525,7 +1525,7 @@ return /******/ (function(modules) { // webpackBootstrap
loc: loc
});
}
- return obj[name];
+ return container.lookupProperty(obj, name);
},
lookupProperty: function lookupProperty(parent, propertyName) {
var result = parent[propertyName];
@@ -3903,7 +3903,7 @@ return /******/ (function(modules) { // webpackBootstrap
return this.internalNameLookup(parent, name);
},
depthedLookup: function depthedLookup(name) {
- return [this.aliasable('container.lookup'), '(depths, "', name, '")'];
+ return [this.aliasable('container.lookup'), '(depths, ', JSON.stringify(name), ')'];
},
compilerInfo: function compilerInfo() {
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/i417/Issue417.java b/handlebars/src/test/java/com/github/jknack/handlebars/i417/Issue417.java
index 51c96833f..b78f91adb 100644
--- a/handlebars/src/test/java/com/github/jknack/handlebars/i417/Issue417.java
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/i417/Issue417.java
@@ -25,7 +25,7 @@ public void v4_0_0() throws IOException {
+ " return \"Hi \"\n"
+ " + container.escapeExpression(((helper = (helper = lookupProperty(helpers,\"var\") || (depth0 != null ? lookupProperty(depth0,\"var\") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === \"function\" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{\"name\":\"var\",\"hash\":{},\"data\":data,\"loc\":{\"start\":{\"line\":1,\"column\":3},\"end\":{\"line\":1,\"column\":10}}}) : helper)))\n"
+ " + \"!\";\n"
- + "},\"useData\":true}", new Handlebars().handlebarsJsFile("/handlebars-v4.7.6.js")
+ + "},\"useData\":true}", new Handlebars().handlebarsJsFile("/handlebars-v4.7.7.js")
.compileInline("Hi {{var}}!").toJavaScript());
}
From a79d870610fc2b79a0e2c8f5f8a82d5a3257618d Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sat, 25 Sep 2021 13:53:49 -0300
Subject: [PATCH 003/157] build: add sub-modules
---
.github/workflows/build-matrix.yml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml
index 6147ec33c..482dc4f42 100644
--- a/.github/workflows/build-matrix.yml
+++ b/.github/workflows/build-matrix.yml
@@ -14,6 +14,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v1
+ - name: Mustache Specs
+ run: |
+ git submodule update --init --recursive
- name: Set up JDK ${{ matrix.java_version }}
uses: actions/setup-java@v1
with:
From 942e34db42774c122d8f4be794a303894be56bdb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=96=B9=E5=9D=A4?=
Date: Mon, 26 Apr 2021 08:57:07 +0800
Subject: [PATCH 004/157] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 089207a23..c72106e7b 100644
--- a/README.md
+++ b/README.md
@@ -26,7 +26,7 @@ Handlebars.java is a Java port of [handlebars](http://handlebarsjs.com/).
Handlebars provides the power necessary to let you build semantic templates effectively with no frustration.
-[Mustache](http://mustache.github.com/mustache.5.html) templates are compatible with Handlebars, so you can take a [Mustache](http://mustache.github.com) template, import it into Handlebars, and start taking advantage of the extra Handlebars features.
+[Mustache](http://mustache.github.io/mustache.5.html) templates are compatible with Handlebars, so you can take a [Mustache](http://mustache.github.com) template, import it into Handlebars, and start taking advantage of the extra Handlebars features.
# Getting Started
In general, the syntax of **Handlebars** templates is a superset of [Mustache](http://mustache.github.com) templates. For basic syntax, check out the [Mustache manpage](http://mustache.github.com).
From 40ca09ab5145f735f0c1ada77e68af3159826655 Mon Sep 17 00:00:00 2001
From: Yannick Dylla
Date: Tue, 17 Aug 2021 12:06:51 +0200
Subject: [PATCH 005/157] feat(StringHelpers): add Instant support for
dateFormat
* add support for more date types like Instant, OffsetDateTime, LocalDateTime, ...
---
.../handlebars/helper/StringHelpers.java | 108 +++++++++++++-----
.../jknack/handlebars/DateFormatTest.java | 67 ++++++++++-
2 files changed, 145 insertions(+), 30 deletions(-)
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java
index 47d8c9e38..3d178653b 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java
@@ -26,11 +26,13 @@
import java.io.IOException;
import java.math.RoundingMode;
-import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
-import java.text.SimpleDateFormat;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.FormatStyle;
+import java.time.temporal.TemporalAccessor;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -501,7 +503,7 @@ protected CharSequence safeApply(final Object context, final Options options) {
*
*
*
- * {{dateFormat date ["format"] [format="format"][tz=timeZone|timeZoneId]}}
+ * {{dateFormat date ["format"] [format="format"][locale="locale"][tz=timeZone|timeZoneId][time="format"]}}
*
*
* Format parameters is one of:
@@ -510,48 +512,102 @@ protected CharSequence safeApply(final Object context, final Options options) {
*
"long": long date format. For example: June 19, 2012
*
"medium": medium date format. For example: Jun 19, 2012
*
"short": short date format. For example: 6/19/12
- *
"pattern": a date pattern.
+ *
"pattern": a {@link java.time.format.DateTimeFormatter} pattern.
*
* Otherwise, the default formatter will be used.
* The format option can be specified as a parameter or hash (a.k.a named parameter).
+ *
+ *
+ *
+ * The "locale" parameter can be use to select a locale, e.g. "de" or "en_GB".
+ * It defaults to the system locale.
+ *
+ *
+ * The "tz" parameter is the time zone to use, e.g. "Europe/Berlin" or "GMT-8:00".
+ * It defaults to the system time zone.
+ *
+ *
+ * The "time" parameter specifies the format of the time part, it can be "full", "long", "medium" or "short".
+ * If you do not specify it only the date part will appear in the output string.
+ *
- * {{dateFormat date ["format"] [format="format"][locale="locale"][tz=timeZone|timeZoneId][time="format"]}}
+ * {{dateFormat date ["format"] [format="format"][locale="locale"][tz=timeZone|timeZoneId]
+ * [time="format"]}}
*
*
* Format parameters is one of:
@@ -527,7 +528,8 @@ protected CharSequence safeApply(final Object context, final Options options) {
* It defaults to the system time zone.
*
*
- * The "time" parameter specifies the format of the time part, it can be "full", "long", "medium" or "short".
+ * The "time" parameter specifies the format of the time part, it can be "full", "long",
+ * "medium" or "short".
* If you do not specify it only the date part will appear in the output string.
*
*
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java
index 0bfb9fcd1..4cc8180e8 100644
--- a/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/AbstractTest.java
@@ -33,7 +33,7 @@ public void shouldCompileTo(final String template, final String context,
final String expected, final String message) throws IOException {
Object deserializedContext = context;
if (deserializedContext != null) {
- deserializedContext = new Yaml().load(context);
+ deserializedContext = parseYaml(context);
}
shouldCompileTo(template, deserializedContext, expected, message);
}
@@ -50,12 +50,16 @@ public void shouldCompileTo(final String template, final Object context,
public void shouldCompileTo(final String template, final String context,
final Hash helpers, final String expected) throws IOException {
- shouldCompileTo(template, new Yaml().load(context), helpers, expected, "");
+ shouldCompileTo(template, parseYaml(context), helpers, expected, "");
+ }
+
+ private Object parseYaml(String context) {
+ return new Yaml().load(context);
}
public void shouldCompileTo(final String template, final String context,
final Hash helpers, final String expected, final String message) throws IOException {
- shouldCompileTo(template, new Yaml().load(context), helpers, expected, message);
+ shouldCompileTo(template, parseYaml(context), helpers, expected, message);
}
public void shouldCompileTo(final String template, final Object context,
From 5eeab12c18270abcbc6f1e113f2e028b67f6e917 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 25 Sep 2021 17:34:47 +0000
Subject: [PATCH 021/157] Bump easymock from 4.2 to 4.3
Bumps [easymock](https://github.com/easymock/easymock) from 4.2 to 4.3.
- [Release notes](https://github.com/easymock/easymock/releases)
- [Changelog](https://github.com/easymock/easymock/blob/master/ReleaseNotes.md)
- [Commits](https://github.com/easymock/easymock/compare/easymock-4.2...easymock-4.3)
---
updated-dependencies:
- dependency-name: org.easymock:easymock
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 05af34d88..d740fbb2e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -161,7 +161,7 @@
org.easymockeasymock
- 4.2
+ 4.3
From 519de4ad64cbd2c969b8bec2448e298efa25338b Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 25 Sep 2021 17:34:50 +0000
Subject: [PATCH 022/157] Bump snakeyaml from 1.28 to 1.29
Bumps [snakeyaml](https://bitbucket.org/asomov/snakeyaml) from 1.28 to 1.29.
- [Commits](https://bitbucket.org/asomov/snakeyaml/branches/compare/snakeyaml-1.29..snakeyaml-1.28)
---
updated-dependencies:
- dependency-name: org.yaml:snakeyaml
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index d740fbb2e..04717da79 100644
--- a/pom.xml
+++ b/pom.xml
@@ -154,7 +154,7 @@
org.yamlsnakeyaml
- 1.28
+ 1.29test
From a5ca54ca5ba20648e91a0a0859ab8ec21dd3c700 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 25 Sep 2021 17:34:54 +0000
Subject: [PATCH 023/157] Bump antlr-version from 4.8-1 to 4.9.2
Bumps `antlr-version` from 4.8-1 to 4.9.2.
Updates `antlr4-runtime` from 4.8-1 to 4.9.2
- [Release notes](https://github.com/antlr/antlr4/releases)
- [Changelog](https://github.com/antlr/antlr4/blob/master/CHANGES.txt)
- [Commits](https://github.com/antlr/antlr4/commits/4.9.2)
Updates `antlr4-maven-plugin` from 4.8-1 to 4.9.2
- [Release notes](https://github.com/antlr/antlr4/releases)
- [Changelog](https://github.com/antlr/antlr4/blob/master/CHANGES.txt)
- [Commits](https://github.com/antlr/antlr4/commits/4.9.2)
---
updated-dependencies:
- dependency-name: org.antlr:antlr4-runtime
dependency-type: direct:production
- dependency-name: org.antlr:antlr4-maven-plugin
dependency-type: direct:production
...
Signed-off-by: dependabot[bot]
---
handlebars/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars/pom.xml b/handlebars/pom.xml
index 0f647daa1..2ee9ade4f 100644
--- a/handlebars/pom.xml
+++ b/handlebars/pom.xml
@@ -241,7 +241,7 @@
- 4.8-1
+ 4.9.2
From 0670733be501ee9a0793c6d510131ee81b538bc2 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 25 Sep 2021 17:34:55 +0000
Subject: [PATCH 024/157] Bump jackson-databind from 2.9.10.7 to 2.12.5
Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.9.10.7 to 2.12.5.
- [Release notes](https://github.com/FasterXML/jackson/releases)
- [Commits](https://github.com/FasterXML/jackson/commits)
---
updated-dependencies:
- dependency-name: com.fasterxml.jackson.core:jackson-databind
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 04717da79..6f08fcc12 100644
--- a/pom.xml
+++ b/pom.xml
@@ -421,7 +421,7 @@
UTF-8
- 2.9.10.7
+ 2.12.51.2.20.8.5yyyy-MM-dd HH:mm:ssa
From d82499e4cb2b90536bd79a2745af0c2d41304d60 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 25 Sep 2021 17:34:59 +0000
Subject: [PATCH 025/157] Bump joda-time from 2.10.6 to 2.10.11
Bumps [joda-time](https://github.com/JodaOrg/joda-time) from 2.10.6 to 2.10.11.
- [Release notes](https://github.com/JodaOrg/joda-time/releases)
- [Changelog](https://github.com/JodaOrg/joda-time/blob/master/RELEASE-NOTES.txt)
- [Commits](https://github.com/JodaOrg/joda-time/compare/v2.10.6...v2.10.11)
---
updated-dependencies:
- dependency-name: joda-time:joda-time
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
handlebars-helpers/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml
index f70fde687..a92c465de 100644
--- a/handlebars-helpers/pom.xml
+++ b/handlebars-helpers/pom.xml
@@ -30,7 +30,7 @@
joda-timejoda-time
- 2.10.6
+ 2.10.11true
From 8bd8febca4bb9fbeab9d3fd5d4b730088263cfd3 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 25 Sep 2021 17:35:13 +0000
Subject: [PATCH 026/157] Bump powermock-api-easymock from 2.0.7 to 2.0.9
Bumps [powermock-api-easymock](https://github.com/powermock/powermock) from 2.0.7 to 2.0.9.
- [Release notes](https://github.com/powermock/powermock/releases)
- [Changelog](https://github.com/powermock/powermock/blob/release/2.x/docs/changelog.txt)
- [Commits](https://github.com/powermock/powermock/compare/powermock-2.0.7...powermock-2.0.9)
---
updated-dependencies:
- dependency-name: org.powermock:powermock-api-easymock
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 6f08fcc12..5d312d6d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -167,7 +167,7 @@
org.powermockpowermock-api-easymock
- 2.0.7
+ 2.0.9test
From d81be3e10dbb6e7549dd34d7488012f33c4214e9 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 25 Sep 2021 17:35:17 +0000
Subject: [PATCH 027/157] Bump junit from 4.13.1 to 4.13.2
Bumps [junit](https://github.com/junit-team/junit4) from 4.13.1 to 4.13.2.
- [Release notes](https://github.com/junit-team/junit4/releases)
- [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.13.1.md)
- [Commits](https://github.com/junit-team/junit4/compare/r4.13.1...r4.13.2)
---
updated-dependencies:
- dependency-name: junit:junit
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 5d312d6d3..b51664893 100644
--- a/pom.xml
+++ b/pom.xml
@@ -148,7 +148,7 @@
junitjunittest
- 4.13.1
+ 4.13.2
From fade13e2f6298fde2c5f0d83b6c1243a1e47b7fc Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 25 Sep 2021 17:35:21 +0000
Subject: [PATCH 028/157] Bump maven-plugin-annotations from 3.6.0 to 3.6.1
Bumps [maven-plugin-annotations](https://github.com/apache/maven-plugin-tools) from 3.6.0 to 3.6.1.
- [Release notes](https://github.com/apache/maven-plugin-tools/releases)
- [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.6.0...maven-plugin-tools-3.6.1)
---
updated-dependencies:
- dependency-name: org.apache.maven.plugin-tools:maven-plugin-annotations
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
handlebars-maven-plugin/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index a38c7603b..5c8bf4714 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -56,7 +56,7 @@
org.apache.maven.plugin-toolsmaven-plugin-annotations
- 3.6.0
+ 3.6.1provided
From 490f9399b7879d4839fd2193569bb1ae77e4aab9 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sat, 25 Sep 2021 17:35:24 +0000
Subject: [PATCH 029/157] Bump maven-core from 3.6.3 to 3.8.2
Bumps [maven-core](https://github.com/apache/maven) from 3.6.3 to 3.8.2.
- [Release notes](https://github.com/apache/maven/releases)
- [Commits](https://github.com/apache/maven/compare/maven-3.6.3...maven-3.8.2)
---
updated-dependencies:
- dependency-name: org.apache.maven:maven-core
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
handlebars-maven-plugin/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index 5c8bf4714..b2feb5b2e 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -50,7 +50,7 @@
org.apache.mavenmaven-core
- 3.6.3
+ 3.8.2
From dfc2b900c0ff685d439af508cd147c1cbd8ff1c4 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sat, 25 Sep 2021 15:49:29 -0300
Subject: [PATCH 030/157] helpers: remove warn while overriding a helper
---
.../github/jknack/handlebars/helper/DefaultHelperRegistry.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java
index ee7db2d27..e921b4a86 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java
@@ -112,7 +112,7 @@ public HelperRegistry registerHelper(final String name, final Helper help
Helper> oldHelper = helpers.put(name, helper);
if (oldHelper != null) {
- logger.warn("Helper '{}' has been replaced by '{}'", name, helper);
+ logger.debug("Helper '{}' has been replaced by '{}'", name, helper);
}
return this;
}
From 1cf383b855611c18b3f31e55bdba394aa71c1bce Mon Sep 17 00:00:00 2001
From: Brian Caruso
Date: Tue, 2 Feb 2021 21:56:44 -0800
Subject: [PATCH 031/157] Add @HelperFunction annotation for overriding method
names from Helper Sources (#829)
---
.../helper/DefaultHelperRegistry.java | 3 ++-
.../handlebars/helper/HelperFunction.java | 18 ++++++++++++++++++
.../handlebars/ReflectiveHelperTest.java | 11 +++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java
index e921b4a86..3cdd33fd7 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java
@@ -234,10 +234,11 @@ private void registerDynamicHelper(final Object source, final Class> clazz) {
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
boolean isPublic = Modifier.isPublic(method.getModifiers());
- String helperName = method.getName();
if (isPublic) {
boolean isStatic = Modifier.isStatic(method.getModifiers());
if (source != null || isStatic) {
+ HelperFunction annotation = method.getAnnotation(HelperFunction.class);
+ String helperName = annotation != null ? annotation.value() : method.getName();
isTrue(overloaded.add(helperName), "name conflict found: " + helperName);
registerHelper(helperName, new MethodHelper(method, source));
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java
new file mode 100644
index 000000000..2dbc56e11
--- /dev/null
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java
@@ -0,0 +1,18 @@
+package com.github.jknack.handlebars.helper;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Decorates a method that represents a helper function extracted via a "helper source"
+ * with metadata that cannot be inferred from its signature, such as a custom helper name.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface HelperFunction {
+
+ /**
+ * The name used to invoke the decorated helper function in a handlebars template.
+ */
+ String value();
+
+}
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/ReflectiveHelperTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/ReflectiveHelperTest.java
index 192968320..fa4644390 100644
--- a/handlebars/src/test/java/com/github/jknack/handlebars/ReflectiveHelperTest.java
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/ReflectiveHelperTest.java
@@ -8,6 +8,7 @@
import java.io.IOException;
+import com.github.jknack.handlebars.helper.HelperFunction;
import org.junit.Test;
import com.github.jknack.handlebars.Handlebars.SafeString;
@@ -53,6 +54,11 @@ public void testHelperWithParamsAndOptions() throws IOException {
"helperWithParamsAndOptions:string:true:4");
}
+ @Test
+ public void testAnnotatedHelper() throws IOException {
+ shouldCompileTo("{{this-is-annotated}}", null, "i am an annotated helper function");
+ }
+
@Test
public void testBlog() throws IOException {
shouldCompileTo("{{blog this}}", new Blog("title", "body"),
@@ -155,6 +161,11 @@ public SafeString helperWithParamsAndOptions(final String context, final boolean
return new SafeString(String.format("helperWithParamsAndOptions:%s:%s:%s", context, p0, p1));
}
+ @HelperFunction("this-is-annotated")
+ public CharSequence annotatedHelper() {
+ return "i am an annotated helper function";
+ }
+
public CharSequence blog(final Blog blog, final Options options) {
assertNotNull(options);
return "blog:" + blog.toString();
From 2a4b461db20b1564c5d3ffe3e85b57baebddb2cc Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sat, 25 Sep 2021 15:52:46 -0300
Subject: [PATCH 032/157] build: keep jdk 1.8 on github actions. Will add more
jdk progressively
---
.github/workflows/build-matrix.yml | 2 +-
.../handlebars/helper/HelperFunction.java | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml
index 482dc4f42..1f61ab8fc 100644
--- a/.github/workflows/build-matrix.yml
+++ b/.github/workflows/build-matrix.yml
@@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- java_version: [1.8, 11, 13, 15, 17]
+ java_version: [1.8]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java
index 2dbc56e11..3252b8ec4 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java
@@ -1,3 +1,20 @@
+/**
+ * Copyright (c) 2012-2015 Edgar Espina
+ *
+ * This file is part of Handlebars.java.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.github.jknack.handlebars.helper;
import java.lang.annotation.Retention;
@@ -12,6 +29,7 @@
/**
* The name used to invoke the decorated helper function in a handlebars template.
+ * @return Name or null/empty to use default method name.
*/
String value();
From 76b66abe07a9314f9e6f41f12f08b4305d0f443f Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sat, 25 Sep 2021 21:12:34 -0300
Subject: [PATCH 033/157] upgrade: guava for cache but not when using humanize
- next release going to remove humanize from project (it is not active
anymore)
---
handlebars-humanize/pom.xml | 6 ++++++
pom.xml | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml
index b6c407226..61d6cc454 100644
--- a/handlebars-humanize/pom.xml
+++ b/handlebars-humanize/pom.xml
@@ -14,6 +14,12 @@
Humanize helpers
+
+ com.google.guava
+ guava
+ 23.0
+
+
com.github.jknackhandlebars
diff --git a/pom.xml b/pom.xml
index b51664893..3ea17b3ef 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,7 +78,7 @@
com.google.guavaguava
- 23.0
+ 30.0-jre
From 2afc50fd5dcd32af28f8305b59689b3fec4a3b07 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sun, 26 Sep 2021 13:01:42 -0300
Subject: [PATCH 034/157] v4.2.1
---
handlebars-guava-cache/pom.xml | 2 +-
handlebars-helpers/pom.xml | 2 +-
handlebars-humanize/pom.xml | 2 +-
handlebars-jackson2/pom.xml | 2 +-
handlebars-markdown/pom.xml | 2 +-
handlebars-maven-plugin-tests/pom.xml | 2 +-
handlebars-maven-plugin/pom.xml | 2 +-
handlebars-proto/pom.xml | 2 +-
handlebars-springmvc/pom.xml | 2 +-
handlebars/pom.xml | 2 +-
pom.xml | 2 +-
11 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml
index 87cf48f05..9b6ac5eb2 100644
--- a/handlebars-guava-cache/pom.xml
+++ b/handlebars-guava-cache/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml
index a92c465de..e127bd774 100644
--- a/handlebars-helpers/pom.xml
+++ b/handlebars-helpers/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml
index 61d6cc454..248739a53 100644
--- a/handlebars-humanize/pom.xml
+++ b/handlebars-humanize/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml
index 111bb8ad8..2f99ce448 100644
--- a/handlebars-jackson2/pom.xml
+++ b/handlebars-jackson2/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/handlebars-markdown/pom.xml b/handlebars-markdown/pom.xml
index 90b308917..8112e6758 100644
--- a/handlebars-markdown/pom.xml
+++ b/handlebars-markdown/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml
index 439b34f48..1b2865b20 100644
--- a/handlebars-maven-plugin-tests/pom.xml
+++ b/handlebars-maven-plugin-tests/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index b2feb5b2e..d51482c77 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index 3d5746cb1..3afe2ea2a 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml
index b9d8fca99..3b62f712d 100644
--- a/handlebars-springmvc/pom.xml
+++ b/handlebars-springmvc/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/handlebars/pom.xml b/handlebars/pom.xml
index 2ee9ade4f..1859aaca9 100644
--- a/handlebars/pom.xml
+++ b/handlebars/pom.xml
@@ -6,7 +6,7 @@
com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.14.0.0
diff --git a/pom.xml b/pom.xml
index 3ea17b3ef..79bc75411 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0com.github.jknackhandlebars.java
- 4.2.1-SNAPSHOT
+ 4.2.1pomHandlebars.java
From 6a4ab57f4ddfb1be05f799a3aa53530c857a8870 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sun, 26 Sep 2021 13:02:19 -0300
Subject: [PATCH 035/157] prepare for next development cycle
---
handlebars-guava-cache/pom.xml | 2 +-
handlebars-helpers/pom.xml | 2 +-
handlebars-humanize/pom.xml | 2 +-
handlebars-jackson2/pom.xml | 2 +-
handlebars-markdown/pom.xml | 2 +-
handlebars-maven-plugin-tests/pom.xml | 2 +-
handlebars-maven-plugin/pom.xml | 2 +-
handlebars-proto/pom.xml | 2 +-
handlebars-springmvc/pom.xml | 2 +-
handlebars/pom.xml | 2 +-
pom.xml | 2 +-
11 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml
index 9b6ac5eb2..bc81524da 100644
--- a/handlebars-guava-cache/pom.xml
+++ b/handlebars-guava-cache/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml
index e127bd774..2aa26507b 100644
--- a/handlebars-helpers/pom.xml
+++ b/handlebars-helpers/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml
index 248739a53..bf1159e2c 100644
--- a/handlebars-humanize/pom.xml
+++ b/handlebars-humanize/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml
index 2f99ce448..603d816c6 100644
--- a/handlebars-jackson2/pom.xml
+++ b/handlebars-jackson2/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/handlebars-markdown/pom.xml b/handlebars-markdown/pom.xml
index 8112e6758..0f098df2d 100644
--- a/handlebars-markdown/pom.xml
+++ b/handlebars-markdown/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml
index 1b2865b20..3cab1f89c 100644
--- a/handlebars-maven-plugin-tests/pom.xml
+++ b/handlebars-maven-plugin-tests/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index d51482c77..efb37c691 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index 3afe2ea2a..6fc692d54 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml
index 3b62f712d..c1b9894dd 100644
--- a/handlebars-springmvc/pom.xml
+++ b/handlebars-springmvc/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/handlebars/pom.xml b/handlebars/pom.xml
index 1859aaca9..b3e29a49d 100644
--- a/handlebars/pom.xml
+++ b/handlebars/pom.xml
@@ -6,7 +6,7 @@
com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOT4.0.0
diff --git a/pom.xml b/pom.xml
index 79bc75411..fbd91fea3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0com.github.jknackhandlebars.java
- 4.2.1
+ 4.3.0-SNAPSHOTpomHandlebars.java
From 96e61bd4b1659d3d45bdb396dffd2f1a56a75f6d Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 27 Sep 2021 09:47:24 -0300
Subject: [PATCH 036/157] build: attempt to fix windows build
---
.../jknack/handlebars/Jackson2HelperTest.java | 62 +++++++++----------
handlebars-maven-plugin/a.txt | 54 ++++++++++++++++
handlebars-maven-plugin/b.txt | 54 ++++++++++++++++
handlebars-maven-plugin/pom.xml | 8 +++
.../handlebars/maven/PrecompilePlugin.java | 1 -
.../handlebars/maven/I18nJsPluginTest.java | 19 +++++-
.../jknack/handlebars/maven/Issue230.java | 13 +++-
.../jknack/handlebars/maven/Issue234.java | 17 ++++-
.../maven/PrecompilePluginTest.java | 30 +++++----
.../test/resources/helpers-i18njs.expected | 1 -
.../src/test/resources/helpers.expected | 4 --
.../src/test/resources/i230.properties | 2 +-
.../src/test/resources/issue234.expected | 2 -
.../test/resources/specific-files.expected | 2 -
.../handlebars/IgnoreWindowsLineMatcher.java | 28 +++++++++
.../handlebars/TemporalPartialTest.java | 41 ++++++------
.../jknack/handlebars/i275/Issue275.java | 29 +++++----
.../jknack/handlebars/issues/Hbs507.java | 33 +++++-----
18 files changed, 291 insertions(+), 109 deletions(-)
create mode 100644 handlebars-maven-plugin/a.txt
create mode 100644 handlebars-maven-plugin/b.txt
create mode 100644 handlebars/src/test/java/com/github/jknack/handlebars/IgnoreWindowsLineMatcher.java
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java
index 37c6eecba..f6cbf5568 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java
@@ -13,7 +13,8 @@
*/
package com.github.jknack.handlebars;
-import static org.junit.Assert.assertEquals;
+import static com.github.jknack.handlebars.IgnoreWindowsLineMatcher.equalsToStringIgnoringWindowsNewLine;
+import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.util.HashMap;
@@ -40,10 +41,8 @@ public void toJSON() throws IOException {
Template template = handlebars.compileInline("{{@json this}}");
- CharSequence result = template.apply(new Blog("First Post", "..."));
-
- assertEquals("{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}",
- result);
+ assertThat(template.apply(new Blog("First Post", "...")), equalsToStringIgnoringWindowsNewLine(
+ "{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}"));
}
@Test
@@ -53,14 +52,12 @@ public void toPrettyJSON() throws IOException {
Template template = handlebars.compileInline("{{@json this pretty=true}}");
- CharSequence result = template.apply(new Blog("First Post", "..."));
-
- assertEquals("{\n" +
- " \"title\" : \"First Post\",\n" +
- " \"body\" : \"...\",\n" +
- " \"comments\" : [ ]\n" +
- "}",
- result);
+ assertThat(template.apply(new Blog("First Post", "...")),
+ equalsToStringIgnoringWindowsNewLine("{\n" +
+ " \"title\" : \"First Post\",\n" +
+ " \"body\" : \"...\",\n" +
+ " \"comments\" : [ ]\n" +
+ "}"));
}
@Test
@@ -71,12 +68,12 @@ public void toJSONViewInclusive() throws IOException {
Template template =
handlebars
- .compileInline("{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
-
- CharSequence result = template.apply(new Blog("First Post", "..."));
+ .compileInline(
+ "{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
- assertEquals("{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}",
- result);
+ assertThat(template.apply(new Blog("First Post", "...")),
+ equalsToStringIgnoringWindowsNewLine(
+ "{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}"));
}
@Test
@@ -90,11 +87,11 @@ public void toJSONViewExclusive() throws IOException {
Template template =
handlebars
- .compileInline("{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
+ .compileInline(
+ "{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
- CharSequence result = template.apply(new Blog("First Post", "..."));
-
- assertEquals("{\"title\":\"First Post\"}", result);
+ assertThat(template.apply(new Blog("First Post", "...")),
+ equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}
@Test
@@ -111,9 +108,8 @@ public void toJSONAliasViewExclusive() throws IOException {
handlebars
.compileInline("{{@json this view=\"myView\"}}");
- CharSequence result = template.apply(new Blog("First Post", "..."));
-
- assertEquals("{\"title\":\"First Post\"}", result);
+ assertThat(template.apply(new Blog("First Post", "...")),
+ equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}
@Test(expected = HandlebarsException.class)
@@ -129,9 +125,8 @@ public void jsonViewNotFound() throws IOException {
handlebars
.compileInline("{{@json this view=\"missing.ViewClass\"}}");
- CharSequence result = template.apply(new Blog("First Post", "..."));
-
- assertEquals("{\"title\":\"First Post\"}", result);
+ assertThat(template.apply(new Blog("First Post", "...")),
+ equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}
@Test
@@ -142,11 +137,12 @@ public void escapeHtml() throws IOException {
Map model = new HashMap();
model.put("script", "");
- assertEquals("{\"script\":\"\"}", handlebars
- .compileInline("{{@json this}}").apply(model));
+ assertThat(handlebars
+ .compileInline("{{@json this}}").apply(model), equalsToStringIgnoringWindowsNewLine(
+ "{\"script\":\"\"}"));
- assertEquals(
- "{\"script\":\"\\u003Cscript text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}",
- handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model));
+ assertThat(handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model),
+ equalsToStringIgnoringWindowsNewLine(
+ "{\"script\":\"\\u003Cscript text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}"));
}
}
diff --git a/handlebars-maven-plugin/a.txt b/handlebars-maven-plugin/a.txt
new file mode 100644
index 000000000..58bb9ad25
--- /dev/null
+++ b/handlebars-maven-plugin/a.txt
@@ -0,0 +1,54 @@
+... () {
+// Source: src[/test/resources/partials/level1/level1.html
+
+ var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
+ var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) {
+ if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
+ return parent[propertyName];
+ }
+ return undefined
+ };
+
+ return "
* Handlebars provides the power necessary to let you build semantic templates effectively with no
@@ -177,8 +176,12 @@ public boolean equals(final Object obj) {
*/
public static class Utils {
+ /** Current Java version: 8, 11, 15, etc. */
public static final int javaVersion = javaVersion();
+ /** Prefix for Java version: 1.8 (mostly). */
+ private static final String VERSION_PREFIX = "1.";
+
/**
* Evaluate the given object and return true is the object is considered
* empty. Nulls, empty list or array and false values are considered empty.
@@ -237,21 +240,9 @@ public static CharSequence escapeExpression(final CharSequence input) {
return EscapingStrategy.DEF.escape(input);
}
- private static int javaVersion() {
- String version = System.getProperty("java.version");
- if (version.startsWith("1.")) {
- version = version.substring(2, 3);
- } else {
- int dot = version.indexOf(".");
- if (dot != -1) {
- version = version.substring(0, dot);
- }
- }
- try {
- return Integer.parseInt(version);
- } catch (NumberFormatException e) {
- return 8;
- }
+ static int javaVersion() {
+ String version = System.getProperty("java.specification.version").trim();
+ return Integer.parseInt(version.replace(VERSION_PREFIX, ""));
}
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java b/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java
index ab427df70..330d57ce5 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java
@@ -57,6 +57,9 @@
*/
abstract class BaseTemplate implements Template {
+ /** Java 15. */
+ private static final int JAVA_15 = 15;
+
/**
* The handlebars object. Required.
*/
@@ -265,7 +268,7 @@ private boolean isDefault(final Method method) {
private Object invokeDefaultMethod(final Method method, final Class> lookupClass,
final Object proxy, final Object... args) throws Throwable {
- if (Handlebars.Utils.javaVersion >= 15) {
+ if (Handlebars.Utils.javaVersion >= JAVA_15) {
MethodType methodType = MethodType.methodType(method.getReturnType(),
method.getParameterTypes());
return MethodHandles.lookup()
@@ -273,10 +276,10 @@ private Object invokeDefaultMethod(final Method method, final Class> lookupCla
.bindTo(proxy)
.invokeWithArguments(args);
} else {
- // Jumping through these hoops is needed because calling unreflectSpecial requires that
- // the lookup instance have private access to the special caller. None of the static
- // factory methods for Lookup will give us an instance with the access modes we need,
- // so we work around it by calling the private constructor via reflection.
+ // Jumping through these hoops is needed because calling unreflectSpecial requires
+ // that the lookup instance have private access to the special caller. None of the
+ // static factory methods for Lookup will give us an instance with the access modes
+ // we need, so we work around it by calling the private constructor via reflection.
Constructor constructor = MethodHandles.Lookup.class
.getDeclaredConstructor(Class.class, int.class);
constructor.setAccessible(true);
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/JavaVersionTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/JavaVersionTest.java
new file mode 100644
index 000000000..e83c8c256
--- /dev/null
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/JavaVersionTest.java
@@ -0,0 +1,69 @@
+package com.github.jknack.handlebars;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeTrue;
+
+import org.junit.Test;
+
+public class JavaVersionTest {
+
+ @Test
+ public void shouldCheckVersion8() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 8);
+ assertEquals(8, Handlebars.Utils.javaVersion());
+ }
+
+ @Test
+ public void shouldCheckVersion9() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 9);
+ assertEquals(9, Handlebars.Utils.javaVersion());
+ }
+
+ @Test
+ public void shouldCheckVersion10() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 10);
+ assertEquals(10, Handlebars.Utils.javaVersion());
+ }
+
+ @Test
+ public void shouldCheckVersion11() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 11);
+ assertEquals(11, Handlebars.Utils.javaVersion());
+ }
+
+ @Test
+ public void shouldCheckVersion12() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 12);
+ assertEquals(12, Handlebars.Utils.javaVersion());
+ }
+
+ @Test
+ public void shouldCheckVersion13() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 13);
+ assertEquals(13, Handlebars.Utils.javaVersion());
+ }
+
+ @Test
+ public void shouldCheckVersion14() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 14);
+ assertEquals(14, Handlebars.Utils.javaVersion());
+ }
+
+ @Test
+ public void shouldCheckVersion15() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 15);
+ assertEquals(15, Handlebars.Utils.javaVersion());
+ }
+
+ @Test
+ public void shouldCheckVersion16() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 16);
+ assertEquals(16, Handlebars.Utils.javaVersion());
+ }
+
+ @Test
+ public void shouldCheckVersion17() {
+ assumeTrue(Handlebars.Utils.javaVersion() == 17);
+ assertEquals(17, Handlebars.Utils.javaVersion());
+ }
+}
From 3a216b297193e393c54067291ac5daac69c3950c Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sun, 3 Oct 2021 23:40:28 +0000
Subject: [PATCH 050/157] Bump maven-core from 3.8.2 to 3.8.3
Bumps [maven-core](https://github.com/apache/maven) from 3.8.2 to 3.8.3.
- [Release notes](https://github.com/apache/maven/releases)
- [Commits](https://github.com/apache/maven/compare/maven-3.8.2...maven-3.8.3)
---
updated-dependencies:
- dependency-name: org.apache.maven:maven-core
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
handlebars-maven-plugin/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index 29e39bea2..f63097529 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -50,7 +50,7 @@
org.apache.mavenmaven-core
- 3.8.2
+ 3.8.3
From 9c6b3eb4dfab71cc0ca3de3eec7afdded0a12198 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sun, 3 Oct 2021 23:40:38 +0000
Subject: [PATCH 051/157] Bump commons-text from 1.8 to 1.9
Bumps commons-text from 1.8 to 1.9.
---
updated-dependencies:
- dependency-name: org.apache.commons:commons-text
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 24835f8a8..8312274c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,7 +71,7 @@
org.apache.commonscommons-text
- 1.8
+ 1.9
From 47555403cf0be3e99614900a8ec3ec5b7b6fda2c Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Tue, 5 Oct 2021 16:48:32 -0300
Subject: [PATCH 052/157] Java 17: upgrade to Java 17
- Add TODO notes
- Turn off pegdown for now (need replacement)
---
.github/workflows/build-matrix.yml | 2 +-
TODO | 4 ++++
handlebars-markdown/pom.xml | 19 +++++++++++++++++++
handlebars-maven-plugin-tests/pom.xml | 6 ++++++
handlebars-proto/pom.xml | 10 +++++-----
.../jknack/handlebars/server/HbsServer.java | 4 +---
pom.xml | 4 ++--
7 files changed, 38 insertions(+), 11 deletions(-)
create mode 100644 TODO
diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml
index 281a4f03f..00f463866 100644
--- a/.github/workflows/build-matrix.yml
+++ b/.github/workflows/build-matrix.yml
@@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- java_version: [1.8, 11, 15]
+ java_version: [1.8, 11, 15, 17]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
diff --git a/TODO b/TODO
new file mode 100644
index 000000000..222929ab2
--- /dev/null
+++ b/TODO
@@ -0,0 +1,4 @@
+Java 15/17 Migration
+
+- Replace pegdown with something else
+- Upgrade spring
diff --git a/handlebars-markdown/pom.xml b/handlebars-markdown/pom.xml
index 0f098df2d..183605e96 100644
--- a/handlebars-markdown/pom.xml
+++ b/handlebars-markdown/pom.xml
@@ -46,6 +46,25 @@
test
+
+ org.antlr
+ antlr4-runtime
+ 4.9.2
+
+
+ org.abego.treelayout
+ org.abego.treelayout.core
+
+
+ test
+
+
+
+ org.apache.commons
+ commons-text
+ test
+
+
diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml
index 3cab1f89c..7ec6f68fd 100644
--- a/handlebars-maven-plugin-tests/pom.xml
+++ b/handlebars-maven-plugin-tests/pom.xml
@@ -41,6 +41,12 @@
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ 3.3.2
+
+
org.apache.maven.plugins
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index 6fc692d54..aa0bc1ade 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -124,11 +124,11 @@
${project.version}
-
- com.github.jknack
- handlebars-markdown
- ${project.version}
-
+
+
+
+
+
com.github.jknack
diff --git a/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java b/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java
index 475d0b43c..ffb7c8504 100644
--- a/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java
+++ b/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java
@@ -43,11 +43,9 @@
import org.slf4j.LoggerFactory;
import com.github.jknack.handlebars.Handlebars;
-import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.HelperRegistry;
import com.github.jknack.handlebars.HumanizeHelper;
import com.github.jknack.handlebars.Jackson2Helper;
-import com.github.jknack.handlebars.MarkdownHelper;
import com.github.jknack.handlebars.helper.StringHelpers;
import com.github.jknack.handlebars.io.FileTemplateLoader;
import com.github.jknack.handlebars.io.TemplateLoader;
@@ -169,7 +167,7 @@ public static void run(final Options args) throws Exception {
(context, options) -> new Handlebars.SafeString(options.fn.text())
);
handlebars.registerHelper("json", Jackson2Helper.INSTANCE);
- handlebars.registerHelper("md", new MarkdownHelper());
+// handlebars.registerHelper("md", new MarkdownHelper());
// String helpers
StringHelpers.register(handlebars);
// Humanize helpers
diff --git a/pom.xml b/pom.xml
index 8312274c2..3cf01625f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,7 @@
handlebars-helpershandlebars-jackson2
- handlebars-markdown
+
handlebars-humanizehandlebars-protohandlebars-guava-cache
@@ -271,7 +271,7 @@
org.apache.maven.pluginsmaven-deploy-plugin
- 2.8.2
+ 3.0.0-M1
From 2369eed5e96668f0ca7d5449327134ae02c74ae1 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 5 Oct 2021 18:49:27 +0000
Subject: [PATCH 053/157] Bump jackson-databind from 2.12.5 to 2.13.0
Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.12.5 to 2.13.0.
- [Release notes](https://github.com/FasterXML/jackson/releases)
- [Commits](https://github.com/FasterXML/jackson/commits)
---
updated-dependencies:
- dependency-name: com.fasterxml.jackson.core:jackson-databind
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 3cf01625f..045397454 100644
--- a/pom.xml
+++ b/pom.xml
@@ -394,7 +394,7 @@
UTF-8
- 2.12.5
+ 2.13.01.2.20.8.5yyyy-MM-dd HH:mm:ssa
From c88ed08d7cdb3ab8d136e12c9c3a94889e5bab4f Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sun, 3 Oct 2021 23:40:31 +0000
Subject: [PATCH 054/157] Bump slf4j-api from 1.7.30 to 1.7.32
Bumps [slf4j-api](https://github.com/qos-ch/slf4j) from 1.7.30 to 1.7.32.
- [Release notes](https://github.com/qos-ch/slf4j/releases)
- [Commits](https://github.com/qos-ch/slf4j/compare/v_1.7.30...v_1.7.32)
---
updated-dependencies:
- dependency-name: org.slf4j:slf4j-api
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 045397454..253325bd9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,7 +91,7 @@
org.slf4jslf4j-api
- 1.7.30
+ 1.7.32
From 28472c089d40fbac3b9ead773312e5f8890bbddf Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 27 Sep 2021 09:32:12 +0000
Subject: [PATCH 055/157] Bump jacoco.version from 0.8.5 to 0.8.7
Bumps `jacoco.version` from 0.8.5 to 0.8.7.
Updates `org.jacoco.agent` from 0.8.5 to 0.8.7
- [Release notes](https://github.com/jacoco/jacoco/releases)
- [Commits](https://github.com/jacoco/jacoco/compare/v0.8.5...v0.8.7)
Updates `jacoco-maven-plugin` from 0.8.5 to 0.8.7
- [Release notes](https://github.com/jacoco/jacoco/releases)
- [Commits](https://github.com/jacoco/jacoco/compare/v0.8.5...v0.8.7)
---
updated-dependencies:
- dependency-name: org.jacoco:org.jacoco.agent:runtime
dependency-type: direct:development
update-type: version-update:semver-patch
- dependency-name: org.jacoco:jacoco-maven-plugin
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 253325bd9..6e41d9961 100644
--- a/pom.xml
+++ b/pom.xml
@@ -396,7 +396,7 @@
UTF-82.13.01.2.2
- 0.8.5
+ 0.8.7yyyy-MM-dd HH:mm:ssa${maven.build.timestamp}
From e2f92c87aabc3ccd3017a74c3a6ff5ae68303c7f Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 27 Sep 2021 09:32:14 +0000
Subject: [PATCH 056/157] Bump maven-javadoc-plugin from 3.2.0 to 3.3.1
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.2.0 to 3.3.1.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.2.0...maven-javadoc-plugin-3.3.1)
---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 6e41d9961..32554910e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -356,7 +356,7 @@
org.apache.maven.pluginsmaven-javadoc-plugin
- 3.2.0
+ 3.3.1attach-javadocs
From 7d7c5d719c800678caeb8f0e126ea4d93d632aa5 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 27 Sep 2021 09:31:52 +0000
Subject: [PATCH 057/157] Bump maven-plugin-plugin from 3.6.0 to 3.6.1
Bumps [maven-plugin-plugin](https://github.com/apache/maven-plugin-tools) from 3.6.0 to 3.6.1.
- [Release notes](https://github.com/apache/maven-plugin-tools/releases)
- [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.6.0...maven-plugin-tools-3.6.1)
---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-plugin-plugin
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
handlebars-maven-plugin/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index f63097529..44db45ee3 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -99,7 +99,7 @@
org.apache.maven.pluginsmaven-plugin-plugin
- 3.6.0
+ 3.6.1true
From 4e378d2374cbfa08afd8dc18af293f57faf14936 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 27 Sep 2021 09:32:15 +0000
Subject: [PATCH 058/157] Bump commons-io from 2.8.0 to 2.11.0
Bumps commons-io from 2.8.0 to 2.11.0.
---
updated-dependencies:
- dependency-name: commons-io:commons-io
dependency-type: direct:development
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
handlebars-proto/pom.xml | 2 +-
handlebars/pom.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index aa0bc1ade..102ed477d 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -139,7 +139,7 @@
commons-iocommons-io
- 2.8.0
+ 2.11.0
diff --git a/handlebars/pom.xml b/handlebars/pom.xml
index f06456373..fbd19fa00 100644
--- a/handlebars/pom.xml
+++ b/handlebars/pom.xml
@@ -216,7 +216,7 @@
commons-iocommons-io
- 2.8.0
+ 2.11.0test
From e669d966c39b7b7bd30692e172be9cf1c7b5ad00 Mon Sep 17 00:00:00 2001
From: Marcel Walden
Date: Fri, 8 Oct 2021 16:38:59 -0400
Subject: [PATCH 059/157] All for null arguments to be passed again.
In order versions, This used to allow for nulls to be passed as an argument if it was not found in the options. This would add that functionality back.
---
.../java/com/github/jknack/handlebars/helper/MethodHelper.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/MethodHelper.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/MethodHelper.java
index 4c5560769..8b614e283 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/MethodHelper.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/MethodHelper.java
@@ -72,7 +72,7 @@ public Object apply(final Object context, final Options options) throws IOExcept
if (paramTypes[i] == Options.class) {
args[i] = options;
} else {
- args[i] = options.param(i - 1);
+ args[i] = options.param(i - 1, null);
}
}
}
From 3f822cfc0305c845239e9126ea600dbf3e7aec49 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Fri, 8 Oct 2021 09:21:53 +0000
Subject: [PATCH 060/157] Bump mockito-core from 3.12.0 to 4.0.0
Bumps [mockito-core](https://github.com/mockito/mockito) from 3.12.0 to 4.0.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](https://github.com/mockito/mockito/compare/v3.12.0...v4.0.0)
---
updated-dependencies:
- dependency-name: org.mockito:mockito-core
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 32554910e..3bed7ed41 100644
--- a/pom.xml
+++ b/pom.xml
@@ -154,7 +154,7 @@
org.mockitomockito-core
- 3.12.0
+ 4.0.0test
From b19fdda0f4ee36d97efb64fbe3181d3d6f604d63 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Thu, 7 Oct 2021 09:19:41 +0000
Subject: [PATCH 061/157] Bump closure-compiler from v20210601 to v20211006
Bumps closure-compiler from v20210601 to v20211006.
---
updated-dependencies:
- dependency-name: com.google.javascript:closure-compiler
dependency-type: direct:production
...
Signed-off-by: dependabot[bot]
---
handlebars-maven-plugin/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index 44db45ee3..37833b58a 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -69,7 +69,7 @@
com.google.javascriptclosure-compiler
- v20210601
+ v20211006
From 0b8ddc3129a7b68d600d9c9425908c3b4af2170d Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 5 Oct 2021 20:03:36 +0000
Subject: [PATCH 062/157] Bump maven-checkstyle-plugin from 3.1.1 to 3.1.2
Bumps [maven-checkstyle-plugin](https://github.com/apache/maven-checkstyle-plugin) from 3.1.1 to 3.1.2.
- [Release notes](https://github.com/apache/maven-checkstyle-plugin/releases)
- [Commits](https://github.com/apache/maven-checkstyle-plugin/compare/maven-checkstyle-plugin-3.1.1...maven-checkstyle-plugin-3.1.2)
---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-checkstyle-plugin
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 3bed7ed41..b0f1e899d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -210,7 +210,7 @@
org.apache.maven.pluginsmaven-checkstyle-plugin
- 3.1.1
+ 3.1.2truesrc/etc/checkstyle.xml
From 7f0774323f525f6565dfe76c20d91bef9109ec6d Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 5 Oct 2021 20:03:14 +0000
Subject: [PATCH 063/157] Bump joda-time from 2.10.11 to 2.10.12
Bumps [joda-time](https://github.com/JodaOrg/joda-time) from 2.10.11 to 2.10.12.
- [Release notes](https://github.com/JodaOrg/joda-time/releases)
- [Changelog](https://github.com/JodaOrg/joda-time/blob/master/RELEASE-NOTES.txt)
- [Commits](https://github.com/JodaOrg/joda-time/compare/v2.10.11...v2.10.12)
---
updated-dependencies:
- dependency-name: joda-time:joda-time
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
handlebars-helpers/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml
index 8e5a80ee6..e083eb122 100644
--- a/handlebars-helpers/pom.xml
+++ b/handlebars-helpers/pom.xml
@@ -30,7 +30,7 @@
joda-timejoda-time
- 2.10.11
+ 2.10.12true
From a9387b7df13e4aab7678e0b0c0e545e28b571eff Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 5 Oct 2021 20:03:06 +0000
Subject: [PATCH 064/157] Bump guava from 30.0-jre to 31.0.1-jre
Bumps [guava](https://github.com/google/guava) from 30.0-jre to 31.0.1-jre.
- [Release notes](https://github.com/google/guava/releases)
- [Commits](https://github.com/google/guava/commits)
---
updated-dependencies:
- dependency-name: com.google.guava:guava
dependency-type: direct:production
...
Signed-off-by: dependabot[bot]
---
handlebars-guava-cache/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml
index 688271702..73f91ce7d 100644
--- a/handlebars-guava-cache/pom.xml
+++ b/handlebars-guava-cache/pom.xml
@@ -25,7 +25,7 @@
com.google.guavaguava
- 30.0-jre
+ 31.0.1-jre
From 753a5cc8852277b6e8afa3835fa131d87434e68b Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 27 Sep 2021 09:32:01 +0000
Subject: [PATCH 065/157] Bump maven-gpg-plugin from 1.6 to 3.0.1
Bumps [maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 1.6 to 3.0.1.
- [Release notes](https://github.com/apache/maven-gpg-plugin/releases)
- [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-1.6...maven-gpg-plugin-3.0.1)
---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-gpg-plugin
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index b0f1e899d..e5682faf5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -371,7 +371,7 @@
org.apache.maven.pluginsmaven-gpg-plugin
- 1.6
+ 3.0.1sign-artifacts
From 9f9ecc91599891d396ae0d318662a7c1c9810eac Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 27 Sep 2021 09:31:55 +0000
Subject: [PATCH 066/157] Bump launch4j-maven-plugin from 1.7.25 to 2.1.2
Bumps [launch4j-maven-plugin](https://github.com/lukaszlenart/launch4j-maven-plugin) from 1.7.25 to 2.1.2.
- [Release notes](https://github.com/lukaszlenart/launch4j-maven-plugin/releases)
- [Commits](https://github.com/lukaszlenart/launch4j-maven-plugin/compare/launch4j-maven-plugin-1.7.25...launch4j-maven-plugin-2.1.2)
---
updated-dependencies:
- dependency-name: com.akathist.maven.plugins.launch4j:launch4j-maven-plugin
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot]
---
handlebars-proto/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index 102ed477d..6f75c052c 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -66,7 +66,7 @@
com.akathist.maven.plugins.launch4jlaunch4j-maven-plugin
- 1.7.25
+ 2.1.2l4j-clui
From ec74d0c76a584e47e0863e8e674966c3f5f9760a Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sun, 10 Oct 2021 12:10:20 -0300
Subject: [PATCH 067/157] helper: remove markdown fix #900
---
handlebars-markdown/.gitignore | 11 ---
handlebars-markdown/output.md | 7 --
handlebars-markdown/pom.xml | 70 -------------------
.../jknack/handlebars/MarkdownHelper.java | 48 -------------
.../jknack/handlebars/MarkdownHelperTest.java | 69 ------------------
pom.xml | 1 -
6 files changed, 206 deletions(-)
delete mode 100644 handlebars-markdown/.gitignore
delete mode 100644 handlebars-markdown/output.md
delete mode 100644 handlebars-markdown/pom.xml
delete mode 100644 handlebars-markdown/src/main/java/com/github/jknack/handlebars/MarkdownHelper.java
delete mode 100644 handlebars-markdown/src/test/java/com/github/jknack/handlebars/MarkdownHelperTest.java
diff --git a/handlebars-markdown/.gitignore b/handlebars-markdown/.gitignore
deleted file mode 100644
index 984f1bd66..000000000
--- a/handlebars-markdown/.gitignore
+++ /dev/null
@@ -1,11 +0,0 @@
-*.class
-
-# Package Files #
-*.jar
-*.war
-*.ear
-/target
-/.classpath
-/.project
-/.settings
-/bin
diff --git a/handlebars-markdown/output.md b/handlebars-markdown/output.md
deleted file mode 100644
index 7d0965293..000000000
--- a/handlebars-markdown/output.md
+++ /dev/null
@@ -1,7 +0,0 @@
-
Header 1
-
-
Item 1
-
Item 2
-
Item 3
-
-
Header 2
\ No newline at end of file
diff --git a/handlebars-markdown/pom.xml b/handlebars-markdown/pom.xml
deleted file mode 100644
index 183605e96..000000000
--- a/handlebars-markdown/pom.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
-
-
- com.github.jknack
- handlebars.java
- 4.3.0-SNAPSHOT
-
-
- 4.0.0
- com.github.jknack
- handlebars-markdown
-
- A Markdown Helper
- A Markdown Helper built on top of the pegdown library
-
-
-
- com.github.jknack
- handlebars
- ${project.version}
-
-
-
- org.pegdown
- pegdown
-
-
-
-
- javax.servlet
- servlet-api
- provided
-
-
-
-
- ch.qos.logback
- logback-classic
- test
-
-
-
- junit
- junit
- test
-
-
-
- org.antlr
- antlr4-runtime
- 4.9.2
-
-
- org.abego.treelayout
- org.abego.treelayout.core
-
-
- test
-
-
-
- org.apache.commons
- commons-text
- test
-
-
-
-
-
diff --git a/handlebars-markdown/src/main/java/com/github/jknack/handlebars/MarkdownHelper.java b/handlebars-markdown/src/main/java/com/github/jknack/handlebars/MarkdownHelper.java
deleted file mode 100644
index 640cba3df..000000000
--- a/handlebars-markdown/src/main/java/com/github/jknack/handlebars/MarkdownHelper.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.jknack.handlebars;
-
-import java.io.IOException;
-
-import org.pegdown.PegDownProcessor;
-
-/**
- * A markdown helper.
- *
- * @author edgar.espina
- * @since 0.1.0
- */
-public class MarkdownHelper implements Helper {
-
- /**
- * A singleton version of {@link MarkdownHelper}.
- */
- public static final Helper INSTANCE = new MarkdownHelper();
-
- @Override
- public Object apply(final Object context, final Options options)
- throws IOException {
- if (options.isFalsy(context)) {
- return "";
- }
- String markdown = context.toString();
- PegDownProcessor processor = new PegDownProcessor();
- return new Handlebars.SafeString(processor.markdownToHtml(markdown));
- }
-
-}
diff --git a/handlebars-markdown/src/test/java/com/github/jknack/handlebars/MarkdownHelperTest.java b/handlebars-markdown/src/test/java/com/github/jknack/handlebars/MarkdownHelperTest.java
deleted file mode 100644
index 5c9a19bd2..000000000
--- a/handlebars-markdown/src/test/java/com/github/jknack/handlebars/MarkdownHelperTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright (c) 2012 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.jknack.handlebars;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import org.junit.Test;
-
-/**
- * Unit test for {@link MarkdownHelper}.
- *
- * @author edgar.espina
- * @since 0.1.0
- */
-public class MarkdownHelperTest {
-
- @Test
- public void markdownFalsy() throws IOException {
- Handlebars handlebars = new Handlebars();
- handlebars.registerHelper("markdown", new MarkdownHelper());
- Template template = handlebars.compileInline("{{markdown this}}");
-
- assertEquals("", template.apply(null));
- }
-
- @Test
- public void markdown() throws IOException {
- String text = "";
- text += "# Header 1\n";
- text += "* Item 1\n";
- text += "* Item 2\n";
- text += "* Item 3\n\n";
- text += "## Header 2\n";
-
- Handlebars handlebars = new Handlebars();
- handlebars.registerHelper("markdown", new MarkdownHelper());
- Template template = handlebars.compileInline("{{markdown .}}");
-
- String expected = "
Header 1
\n"
- + "
\n"
- + "
Item 1
\n"
- + "
Item 2
\n"
- + "
Item 3
\n"
- + "
\n"
- + "
Header 2
";
- assertEquals(expected, template.apply(text));
- }
-
-}
diff --git a/pom.xml b/pom.xml
index e5682faf5..9a859d360 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,6 @@
handlebars-helpershandlebars-jackson2
-
handlebars-humanizehandlebars-protohandlebars-guava-cache
From 0c58798f1cab09f917d132b7b5dc0060a15dda9d Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sun, 10 Oct 2021 13:02:35 -0300
Subject: [PATCH 068/157] spring: upgrade spring module to 5.x #908
---
handlebars-springmvc/pom.xml | 26 ++++++++++++++++++++++++++
pom.xml | 6 +++---
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml
index 1e0848b91..ede00ae55 100644
--- a/handlebars-springmvc/pom.xml
+++ b/handlebars-springmvc/pom.xml
@@ -57,6 +57,32 @@
mockito-coretest
+
+
+ org.apache.commons
+ commons-lang3
+ test
+
+
+
+ org.antlr
+ antlr4-runtime
+ 4.9.2
+
+
+ org.abego.treelayout
+ org.abego.treelayout.core
+
+
+ test
+
+
+
+ org.apache.commons
+ commons-text
+ test
+
+
diff --git a/pom.xml b/pom.xml
index 9a859d360..531e678b6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,7 @@
handlebarshandlebars-helpers
-
+ handlebars-springmvchandlebars-jackson2handlebars-humanizehandlebars-proto
@@ -76,13 +76,13 @@
org.springframeworkspring-webmvc
- 3.1.1.RELEASE
+ 5.3.10org.springframeworkspring-test
- 3.1.1.RELEASE
+ 5.3.10test
From 17068327665110056d22f971ac2674679792ec64 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sun, 10 Oct 2021 13:28:30 -0300
Subject: [PATCH 069/157] Missing required Java version fix #864
---
README.md | 6 ++----
pom.xml | 2 ++
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 6bfae7180..cca2011fa 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,8 @@ Handlebars provides the power necessary to let you build semantic templates effe
The [Handlebars.java blog](https://jknack.github.io/handlebars.java) is a good place for getting started too. Javadoc is available at [javadoc.io](https://javadoc.io/doc/com.github.jknack/handlebars).
+ Since 4.3.0 release Handlebars.java requires Java 8 or higher.
+
## Maven
#### Stable version: [](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars)
@@ -42,10 +44,6 @@ Handlebars provides the power necessary to let you build semantic templates effe
```
-#### Development version
-
-SNAPSHOT versions are NOT synchronized to Central. If you want to use a snapshot version you need to add the https://oss.sonatype.org/content/repositories/snapshots/ repository to your pom.xml.
-
### Loading templates
Templates are loaded using the ```TemplateLoader``` class. Handlebars.java provides three implementations of a ```TemplateLoader```:
* ClassPathTemplateLoader (default)
diff --git a/pom.xml b/pom.xml
index 531e678b6..38c2da931 100644
--- a/pom.xml
+++ b/pom.xml
@@ -398,5 +398,7 @@
0.8.7yyyy-MM-dd HH:mm:ssa${maven.build.timestamp}
+ 1.8
+ 1.8
From 01c4035dac163c9d228cf9485a3b05a5864690db Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 11 Oct 2021 11:54:53 -0300
Subject: [PATCH 070/157] NullPointerException when partial is empty fix #835
- Added tests and safe-guard
---
.../handlebars/internal/HbsParserFactory.java | 4 ++-
.../jknack/handlebars/i835/Issue835.java | 35 +++++++++++++++++++
.../github/jknack/handlebars/i835/i835.hbs | 0
3 files changed, 38 insertions(+), 1 deletion(-)
create mode 100644 handlebars/src/test/java/com/github/jknack/handlebars/i835/Issue835.java
create mode 100644 handlebars/src/test/resources/com/github/jknack/handlebars/i835/i835.hbs
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/internal/HbsParserFactory.java b/handlebars/src/main/java/com/github/jknack/handlebars/internal/HbsParserFactory.java
index fd4435e72..2e2e04cf7 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/internal/HbsParserFactory.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/internal/HbsParserFactory.java
@@ -18,6 +18,7 @@
package com.github.jknack.handlebars.internal;
import java.io.IOException;
+import java.util.Optional;
import org.antlr.v4.runtime.ANTLRErrorListener;
import org.antlr.v4.runtime.CharStream;
@@ -73,7 +74,8 @@ public Template parse(final TemplateSource source) throws IOException {
final ANTLRErrorListener errorReporter = new HbsErrorReporter(sourceName);
// 1. Lexer
- String content = source.content(handlebars.getCharset());
+ String content = Optional.ofNullable(source.content(handlebars.getCharset()))
+ .orElse("");
final HbsLexer lexer = newLexer(CharStreams.fromString(content, sourceName), startDelimiter, endDelimiter);
configure(lexer, errorReporter);
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/i835/Issue835.java b/handlebars/src/test/java/com/github/jknack/handlebars/i835/Issue835.java
new file mode 100644
index 000000000..e10dee4fa
--- /dev/null
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/i835/Issue835.java
@@ -0,0 +1,35 @@
+package com.github.jknack.handlebars.i835;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import org.junit.Test;
+
+import com.github.jknack.handlebars.Handlebars;
+import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
+import com.github.jknack.handlebars.v4Test;
+
+public class Issue835 extends v4Test {
+
+ @Override protected void configure(Handlebars handlebars) {
+ handlebars.with(
+ new ClassPathTemplateLoader("/" + getClass().getPackage().getName().replace(".", "/")));
+ }
+
+ @Test
+ public void shouldIgnoreZeroSizeFileTemplate() throws IOException {
+ assertEquals(0, Files.size(
+ Paths.get("src", "test", "resources", "com", "github", "jknack", "handlebars", "i835",
+ "i835.hbs")));
+ shouldCompileTo("-{{> i835}}-", $(), "--");
+ }
+
+ @Test
+ public void shouldIgnoreEmptyTemplate() throws IOException {
+ shouldCompileTo("", $(), "");
+ }
+
+}
diff --git a/handlebars/src/test/resources/com/github/jknack/handlebars/i835/i835.hbs b/handlebars/src/test/resources/com/github/jknack/handlebars/i835/i835.hbs
new file mode 100644
index 000000000..e69de29bb
From c42e403b5442289b1aef03db6603a786c83fdf69 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 11 Oct 2021 14:45:15 -0300
Subject: [PATCH 071/157] Add support to Caffeine Cache #833Add support to
Caffeine Cache fix #833
---
handlebars-caffeine/pom.xml | 90 ++++++++++++++
.../cache/CaffeineTemplateCache.java | 88 ++++++++++++++
.../handlebars/io/CaffeineTemplateLoader.java | 114 ++++++++++++++++++
.../cache/CaffeineTemplateCacheTest.java | 105 ++++++++++++++++
.../io/GuavaCachedTemplateLoader.java | 5 +-
.../github/jknack/handlebars/Handlebars.java | 45 +++++++
pom.xml | 1 +
7 files changed, 445 insertions(+), 3 deletions(-)
create mode 100644 handlebars-caffeine/pom.xml
create mode 100644 handlebars-caffeine/src/main/java/com/github/jknack/handlebars/cache/CaffeineTemplateCache.java
create mode 100644 handlebars-caffeine/src/main/java/com/github/jknack/handlebars/io/CaffeineTemplateLoader.java
create mode 100644 handlebars-caffeine/src/test/java/com/github/jknack/handlebars/cache/CaffeineTemplateCacheTest.java
diff --git a/handlebars-caffeine/pom.xml b/handlebars-caffeine/pom.xml
new file mode 100644
index 000000000..ec0ad6e70
--- /dev/null
+++ b/handlebars-caffeine/pom.xml
@@ -0,0 +1,90 @@
+
+
+
+
+ com.github.jknack
+ handlebars.java
+ 4.3.0-SNAPSHOT
+
+
+ 4.0.0
+ com.github.jknack
+ handlebars-caffeine
+
+ Handlebars Caffeine Cache
+
+
+
+ com.github.jknack
+ handlebars
+ ${project.version}
+
+
+
+ com.github.ben-manes.caffeine
+ caffeine
+ 2.9.2
+
+
+
+
+ javax.servlet
+ servlet-api
+ provided
+
+
+
+
+ com.github.jknack
+ handlebars
+ ${project.version}
+ test
+ tests
+
+
+
+ ch.qos.logback
+ logback-classic
+ test
+
+
+
+ junit
+ junit
+ test
+
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+
+ org.apache.commons
+ commons-lang3
+ test
+
+
+
+ org.antlr
+ antlr4-runtime
+ 4.9.2
+
+
+ org.abego.treelayout
+ org.abego.treelayout.core
+
+
+ test
+
+
+
+ org.apache.commons
+ commons-text
+ test
+
+
+
+
diff --git a/handlebars-caffeine/src/main/java/com/github/jknack/handlebars/cache/CaffeineTemplateCache.java b/handlebars-caffeine/src/main/java/com/github/jknack/handlebars/cache/CaffeineTemplateCache.java
new file mode 100644
index 000000000..83dc4aa28
--- /dev/null
+++ b/handlebars-caffeine/src/main/java/com/github/jknack/handlebars/cache/CaffeineTemplateCache.java
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2012-2015 Edgar Espina
+ *
+ * This file is part of Handlebars.java.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jknack.handlebars.cache;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.IOException;
+import java.util.function.Function;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.jknack.handlebars.Handlebars;
+import com.github.jknack.handlebars.Parser;
+import com.github.jknack.handlebars.Template;
+import com.github.jknack.handlebars.io.TemplateSource;
+
+/**
+ * Caffeine template cache for handlebars.
+ *
+ * @author edgar
+ * @since 4.3.0
+ */
+public class CaffeineTemplateCache implements TemplateCache {
+
+ /**
+ * Internal cache.
+ */
+ private final Cache cache;
+
+ /**
+ * Creates a new template cache.
+ *
+ * @param cache Cache.
+ */
+ public CaffeineTemplateCache(final Cache cache) {
+ this.cache = requireNonNull(cache, "The cache is required.");
+ }
+
+ @Override public void clear() {
+ cache.invalidateAll();
+ }
+
+ @Override public void evict(final TemplateSource source) {
+ cache.invalidate(source);
+ }
+
+ @Override public Template get(final TemplateSource source, final Parser parser) {
+ return cache.get(source, parseTemplate(parser));
+ }
+
+ /**
+ * This method does nothing on Caffeine. Better option is to use a loading cache with a
+ * eviction policy of your choice.
+ *
+ * Don't use this method.
+ *
+ * @param reload Ignored.
+ * @return This template cache.
+ */
+ @Override public TemplateCache setReload(final boolean reload) {
+ // NOOP
+ return this;
+ }
+
+ private Function super TemplateSource, ? extends Template> parseTemplate(final Parser parser) {
+ return source -> {
+ try {
+ return parser.parse(source);
+ } catch (IOException ex) {
+ throw Handlebars.Utils.propagate(ex);
+ }
+ };
+ }
+}
diff --git a/handlebars-caffeine/src/main/java/com/github/jknack/handlebars/io/CaffeineTemplateLoader.java b/handlebars-caffeine/src/main/java/com/github/jknack/handlebars/io/CaffeineTemplateLoader.java
new file mode 100644
index 000000000..fa49e251f
--- /dev/null
+++ b/handlebars-caffeine/src/main/java/com/github/jknack/handlebars/io/CaffeineTemplateLoader.java
@@ -0,0 +1,114 @@
+/**
+ * Copyright (c) 2012-2015 Edgar Espina
+ *
+ * This file is part of Handlebars.java.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.jknack.handlebars.io;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.function.Function;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.jknack.handlebars.Handlebars;
+
+/**
+ * Decorates an existing TemplateLoader with a GuavaCache.
+ * This is useful to avoid constantly creating TemplateSources.
+ * @author agent
+ */
+public class CaffeineTemplateLoader implements TemplateLoader {
+
+ /**
+ * never null.
+ */
+ private final TemplateLoader delegate;
+ /**
+ * never null.
+ */
+ private final Cache cache;
+
+ /**
+ * @param delegate
+ * wrappped template loader.
+ * @param cache
+ * Guava Cache.
+ */
+ public CaffeineTemplateLoader(final TemplateLoader delegate,
+ final Cache cache) {
+ this.delegate = delegate;
+ this.cache = cache;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public TemplateSource sourceAt(final String location) {
+ return cache.get(location, loadTemplate());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String resolve(final String location) {
+ return delegate.resolve(location);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getPrefix() {
+ return delegate.getPrefix();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getSuffix() {
+ return delegate.getSuffix();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setPrefix(final String prefix) {
+ delegate.setPrefix(prefix);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setSuffix(final String suffix) {
+ delegate.setSuffix(suffix);
+ }
+
+ @Override public void setCharset(final Charset charset) {
+ delegate.setCharset(charset);
+ }
+
+ @Override public Charset getCharset() {
+ return delegate.getCharset();
+ }
+
+ private Function loadTemplate() {
+ return path -> {
+ try {
+ return delegate.sourceAt(path);
+ } catch (IOException ex) {
+ throw Handlebars.Utils.propagate(ex);
+ }
+ };
+ }
+}
diff --git a/handlebars-caffeine/src/test/java/com/github/jknack/handlebars/cache/CaffeineTemplateCacheTest.java b/handlebars-caffeine/src/test/java/com/github/jknack/handlebars/cache/CaffeineTemplateCacheTest.java
new file mode 100644
index 000000000..cb63d0bcf
--- /dev/null
+++ b/handlebars-caffeine/src/test/java/com/github/jknack/handlebars/cache/CaffeineTemplateCacheTest.java
@@ -0,0 +1,105 @@
+package com.github.jknack.handlebars.cache;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.function.Function;
+
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.jknack.handlebars.HandlebarsException;
+import com.github.jknack.handlebars.Parser;
+import com.github.jknack.handlebars.Template;
+import com.github.jknack.handlebars.io.TemplateSource;
+
+public class CaffeineTemplateCacheTest {
+
+ @Test
+ public void shouldInvalidateKeys() {
+ Cache cache = mock(Cache.class);
+
+ CaffeineTemplateCache templateCache = new CaffeineTemplateCache(cache);
+ templateCache.clear();
+
+ verify(cache).invalidateAll();
+ }
+
+ @Test
+ public void shouldInvalidateOneKey() {
+ Cache cache = mock(Cache.class);
+
+ TemplateSource key = mock(TemplateSource.class);
+
+ CaffeineTemplateCache templateCache = new CaffeineTemplateCache(cache);
+ templateCache.evict(key);
+
+ verify(cache).invalidate(key);
+ }
+
+ @Test
+ public void shouldDoNothingOnSetReload() {
+ Cache cache = mock(Cache.class);
+
+ CaffeineTemplateCache templateCache = new CaffeineTemplateCache(cache);
+
+ // Who care?
+ templateCache.setReload(true);
+ templateCache.setReload(false);
+ }
+
+ @Test
+ public void shouldGetTemplate() throws IOException {
+ Template template = mock(Template.class);
+
+ TemplateSource key = mock(TemplateSource.class);
+
+ Parser parser = mock(Parser.class);
+ when(parser.parse(key)).thenReturn(template);
+
+ ArgumentCaptor> captor = ArgumentCaptor.forClass(
+ Function.class);
+
+ Cache cache = mock(Cache.class);
+ when(cache.get(eq(key), captor.capture()))
+ .thenReturn(template);
+
+ CaffeineTemplateCache templateCache = new CaffeineTemplateCache(cache);
+
+ assertEquals(template, templateCache.get(key, parser));
+
+ captor.getValue().apply(key);
+ }
+
+ @Test
+ public void shouldReThrowExceptionOnGetTemplate() throws IOException {
+ TemplateSource key = mock(TemplateSource.class);
+
+ HandlebarsException error = new HandlebarsException("error", null);
+
+ Parser parser = mock(Parser.class);
+ when(parser.parse(key)).thenThrow(error);
+
+ ArgumentCaptor> captor = ArgumentCaptor.forClass(
+ Function.class);
+
+ Cache cache = Caffeine.newBuilder()
+ .build();
+
+ CaffeineTemplateCache templateCache = new CaffeineTemplateCache(cache);
+
+ try {
+ templateCache.get(key, parser);
+ fail("Should get error");
+ } catch (HandlebarsException x) {
+ assertEquals(error, x);
+ }
+ }
+}
diff --git a/handlebars-guava-cache/src/main/java/com/github/jknack/handlebars/io/GuavaCachedTemplateLoader.java b/handlebars-guava-cache/src/main/java/com/github/jknack/handlebars/io/GuavaCachedTemplateLoader.java
index ad8ba771a..4f976114b 100644
--- a/handlebars-guava-cache/src/main/java/com/github/jknack/handlebars/io/GuavaCachedTemplateLoader.java
+++ b/handlebars-guava-cache/src/main/java/com/github/jknack/handlebars/io/GuavaCachedTemplateLoader.java
@@ -22,7 +22,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-import com.google.common.base.Throwables;
+import com.github.jknack.handlebars.Handlebars;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
@@ -80,8 +80,7 @@ public TemplateSource sourceAt(final String location) throws IOException {
try {
return cache.get(location, () -> delegate.sourceAt(location));
} catch (ExecutionException e) {
- Throwables.propagateIfPossible(e.getCause(), IOException.class);
- throw Throwables.propagate(e.getCause());
+ throw Handlebars.Utils.propagate(e.getCause());
}
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
index 6f31d8736..d36f20a52 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
@@ -244,6 +244,51 @@ static int javaVersion() {
String version = System.getProperty("java.specification.version").trim();
return Integer.parseInt(version.replace(VERSION_PREFIX, ""));
}
+
+ /**
+ * Throws any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it
+ * onwards.
+ * The exception is still thrown - javac will just stop whining about it.
+ *
+ * Example usage:
+ *
public void run() {
+ * throw sneakyThrow(new IOException("You don't need to catch me!"));
+ * }
+ *
+ * NB: The exception is not wrapped, ignored, swallowed, or redefined. The JVM actually does
+ * not know or care about the concept of a 'checked exception'. All this method does is hide
+ * the act of throwing a checked exception from the java compiler.
+ *
+ * Note that this method has a return type of {@code RuntimeException}; it is advised you
+ * always call this method as argument to the {@code throw} statement to avoid compiler
+ * errors regarding no return statement and similar problems. This method won't of course
+ * return an actual {@code RuntimeException} - it never returns, it always throws the provided
+ * exception.
+ *
+ * @param x The throwable to throw without requiring you to catch its type.
+ * @return A dummy RuntimeException; this method never returns normally, it always
+ * throws an exception!
+ */
+ public static RuntimeException propagate(final Throwable x) {
+ if (x == null) {
+ throw new NullPointerException("x");
+ }
+
+ sneakyThrow0(x);
+ return null;
+ }
+
+ /**
+ * Make a checked exception un-checked and rethrow it.
+ *
+ * @param x Exception to throw.
+ * @param Exception type.
+ * @throws E Exception to throw.
+ */
+ @SuppressWarnings("unchecked")
+ private static void sneakyThrow0(final Throwable x) throws E {
+ throw (E) x;
+ }
}
/**
diff --git a/pom.xml b/pom.xml
index 38c2da931..e4e7eb8fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,6 +20,7 @@
handlebars-humanizehandlebars-protohandlebars-guava-cache
+ handlebars-caffeinehandlebars-maven-pluginhandlebars-maven-plugin-tests
From beee81abb7791ec89e9d31a2526ef802c7512d5a Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 11 Oct 2021 20:07:13 -0300
Subject: [PATCH 072/157] Java 14 Record is not supported fix #826
- Remove static array with default resolvers. Now it is a list
- Added ValueResolver.defaultResolvers. It adds MethodValueResolver on Java14+
---
.../springmvc/HandlebarsViewResolver.java | 13 ++++---
.../com/github/jknack/handlebars/Context.java | 34 +++++++++----------
.../github/jknack/handlebars/Handlebars.java | 6 ++++
.../jknack/handlebars/ValueResolver.java | 29 ++++++++++++----
.../handlebars/internal/BaseTemplate.java | 5 +--
.../github/jknack/handlebars/EachKeyTest.java | 11 +++++-
.../spec/BlockHelperMissingTest.java | 7 ++++
7 files changed, 72 insertions(+), 33 deletions(-)
diff --git a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java
index 83357869e..9a8998db1 100644
--- a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java
+++ b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java
@@ -17,6 +17,7 @@
*/
package com.github.jknack.handlebars.springmvc;
+import static com.github.jknack.handlebars.ValueResolver.defaultValueResolvers;
import static java.util.Objects.requireNonNull;
import java.io.File;
@@ -34,6 +35,8 @@
import java.util.Map.Entry;
import java.util.ResourceBundle;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
@@ -79,7 +82,7 @@ public class HandlebarsViewResolver extends AbstractTemplateViewResolver
/**
* The value's resolvers.
*/
- private ValueResolver[] valueResolvers = ValueResolver.VALUE_RESOLVERS;
+ private List valueResolvers = new ArrayList<>(defaultValueResolvers());
/**
* Fail on missing file. Default is: true.
@@ -197,7 +200,7 @@ protected AbstractUrlBasedView configure(final HandlebarsView view)
// Compile the template.
try {
view.setTemplate(handlebars.compile(url));
- view.setValueResolver(valueResolvers);
+ view.setValueResolver(valueResolvers.toArray(new ValueResolver[0]));
} catch (IOException ex) {
if (failOnMissingFile) {
throw ex;
@@ -331,7 +334,7 @@ public Handlebars getHandlebars() {
/**
* @return The array of resolvers.
*/
- protected ValueResolver[] getValueResolvers() {
+ protected List getValueResolvers() {
return this.valueResolvers;
}
@@ -341,8 +344,10 @@ protected ValueResolver[] getValueResolvers() {
* @param valueResolvers The value resolvers. Required.
*/
public void setValueResolvers(final ValueResolver... valueResolvers) {
- this.valueResolvers = requireNonNull(valueResolvers,
+ requireNonNull(valueResolvers,
"At least one value-resolver must be present.");
+ this.valueResolvers = Stream.of(valueResolvers)
+ .collect(Collectors.toList());
}
/**
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Context.java b/handlebars/src/main/java/com/github/jknack/handlebars/Context.java
index 758234a63..bfd16be3e 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Context.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Context.java
@@ -29,6 +29,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.github.jknack.handlebars.context.MapValueResolver;
@@ -181,22 +182,22 @@ private static class CompositeValueResolver implements ValueResolver {
/**
* The internal value resolvers.
*/
- private ValueResolver[] resolvers;
+ private List resolvers;
/**
* Creates a new {@link CompositeValueResolver}.
*
* @param resolvers The value resolvers.
*/
- CompositeValueResolver(final ValueResolver... resolvers) {
+ CompositeValueResolver(final List resolvers) {
this.resolvers = resolvers;
}
@Override
public Object resolve(final Object context, final String name) {
int i = 0;
- while (i < resolvers.length) {
- Object value = resolvers[i].resolve(context, name);
+ while (i < resolvers.size()) {
+ Object value = resolvers.get(i).resolve(context, name);
if (value != UNRESOLVED) {
return value == null ? NULL : value;
}
@@ -208,8 +209,8 @@ public Object resolve(final Object context, final String name) {
@Override
public Object resolve(final Object context) {
int i = 0;
- while (i < resolvers.length) {
- Object value = resolvers[i].resolve(context);
+ while (i < resolvers.size()) {
+ Object value = resolvers.get(i).resolve(context);
if (value != UNRESOLVED) {
return value == null ? NULL : value;
}
@@ -258,7 +259,7 @@ private Builder(final Context parent, final Object model) {
*/
private Builder(final Object model) {
context = Context.root(model);
- context.setResolver(new CompositeValueResolver(ValueResolver.VALUE_RESOLVERS));
+ context.setResolver(new CompositeValueResolver(ValueResolver.defaultValueResolvers()));
}
/**
@@ -294,19 +295,19 @@ public Builder resolver(final ValueResolver... resolvers) {
notEmpty(resolvers, "At least one value-resolver must be present.");
boolean mapResolver = Stream.of(resolvers).anyMatch(MapValueResolver.class::isInstance);
if (!mapResolver) {
- ValueResolver[] safeResolvers = new ValueResolver[resolvers.length + 1];
- System.arraycopy(resolvers, 0, safeResolvers, 0, resolvers.length);
- safeResolvers[safeResolvers.length - 1] = MapValueResolver.INSTANCE;
- context.setResolver(new CompositeValueResolver(safeResolvers));
+ context.setResolver(new CompositeValueResolver(
+ Stream.concat(Stream.of(resolvers), Stream.of(MapValueResolver.INSTANCE))
+ .collect(Collectors.toList())
+ ));
} else {
- context.setResolver(new CompositeValueResolver(resolvers));
+ context.setResolver(new CompositeValueResolver(Arrays.asList(resolvers)));
}
return this;
}
/**
* Add one or more value resolver to the defaults defined by
- * {@link ValueResolver#VALUE_RESOLVERS}.
+ * {@link ValueResolver#defaultValueResolvers()}.
*
* @param resolvers The value resolvers. Required.
* @return This builder.
@@ -314,10 +315,9 @@ public Builder resolver(final ValueResolver... resolvers) {
public Builder push(final ValueResolver... resolvers) {
notEmpty(resolvers, "At least one value-resolver must be present.");
List merged = new ArrayList<>();
- merged.addAll(Arrays.asList(ValueResolver.VALUE_RESOLVERS));
- merged.addAll(Arrays.asList(resolvers));
- context.setResolver(
- new CompositeValueResolver(merged.toArray(new ValueResolver[merged.size()])));
+ merged.addAll(ValueResolver.defaultValueResolvers());
+ Stream.of(resolvers).forEach(merged::add);
+ context.setResolver(new CompositeValueResolver(merged));
return this;
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
index d36f20a52..a63f1d1e4 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
@@ -176,9 +176,15 @@ public boolean equals(final Object obj) {
*/
public static class Utils {
+ /** Java 14. */
+ private static final int JAVA_14 = 14;
+
/** Current Java version: 8, 11, 15, etc. */
public static final int javaVersion = javaVersion();
+ /** True when running on Java 14 or higher. */
+ public static final boolean javaVersion14 = javaVersion() >= JAVA_14;
+
/** Prefix for Java version: 1.8 (mostly). */
private static final String VERSION_PREFIX = "1.";
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java b/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java
index 5c01de7bc..156d98f12 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java
@@ -17,11 +17,16 @@
*/
package com.github.jknack.handlebars;
+import static java.util.Arrays.asList;
+import static java.util.Collections.unmodifiableList;
+
+import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import com.github.jknack.handlebars.context.JavaBeanValueResolver;
import com.github.jknack.handlebars.context.MapValueResolver;
+import com.github.jknack.handlebars.context.MethodValueResolver;
/**
* A hook interface for resolving values from the {@link Context context stack}.
@@ -31,12 +36,6 @@
*/
public interface ValueResolver {
- /**
- * The default value resolvers.
- */
- ValueResolver[] VALUE_RESOLVERS = {MapValueResolver.INSTANCE,
- JavaBeanValueResolver.INSTANCE };
-
/**
* A mark object.
*/
@@ -67,7 +66,6 @@ public interface ValueResolver {
*/
Object resolve(Object context);
-
/**
* List all the properties and their values for the given object.
*
@@ -75,4 +73,21 @@ public interface ValueResolver {
* @return All the properties and their values for the given object.
*/
Set> propertySet(Object context);
+
+ /**
+ * Default value resolvers. Including:
+ *
+ * - {@link MapValueResolver}
+ * - {@link JavaBeanValueResolver}
+ * - {@link MethodValueResolver}. On Java 14 or higher.
+ *
+ * @return Immutable list of value resolvers.
+ */
+ static List defaultValueResolvers() {
+ if (Handlebars.Utils.javaVersion14) {
+ return unmodifiableList(asList(MapValueResolver.INSTANCE,
+ JavaBeanValueResolver.INSTANCE, MethodValueResolver.INSTANCE));
+ }
+ return unmodifiableList(asList(MapValueResolver.INSTANCE, JavaBeanValueResolver.INSTANCE));
+ }
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java b/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java
index 330d57ce5..4a40c04a5 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/internal/BaseTemplate.java
@@ -57,9 +57,6 @@
*/
abstract class BaseTemplate implements Template {
- /** Java 15. */
- private static final int JAVA_15 = 15;
-
/**
* The handlebars object. Required.
*/
@@ -268,7 +265,7 @@ private boolean isDefault(final Method method) {
private Object invokeDefaultMethod(final Method method, final Class> lookupClass,
final Object proxy, final Object... args) throws Throwable {
- if (Handlebars.Utils.javaVersion >= JAVA_15) {
+ if (Handlebars.Utils.javaVersion14) {
MethodType methodType = MethodType.methodType(method.getReturnType(),
method.getParameterTypes());
return MethodHandles.lookup()
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java
index 317f6130b..9bd3b252f 100644
--- a/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java
@@ -26,6 +26,9 @@
import org.junit.Ignore;
import org.junit.Test;
+import com.github.jknack.handlebars.context.JavaBeanValueResolver;
+import com.github.jknack.handlebars.context.MapValueResolver;
+
public class EachKeyTest extends AbstractTest {
public static class Blog {
@@ -48,6 +51,12 @@ public String getBody() {
}
}
+ @Override protected Object configureContext(Object context) {
+ return Context.newBuilder(context)
+ .resolver(MapValueResolver.INSTANCE, JavaBeanValueResolver.INSTANCE)
+ .build();
+ }
+
@Ignore
public void eachKeyWithString() throws IOException {
String result = compile("{{#each this}}{{@key}} {{/each}}").apply("String");
@@ -65,7 +74,7 @@ public void eachKeyWithInt() throws IOException {
@Test
public void eachKeyWithJavaBean() throws IOException {
Blog blog = new Blog("Handlebars.java", "...");
- String result = compile("{{#each this}}{{@key}}: {{this}} {{/each}}").apply(blog);
+ String result = compile("{{#each this}}{{@key}}: {{this}} {{/each}}").apply(configureContext(blog));
String expected1 = "body: ... title: Handlebars.java ";
String expected2 = "title: Handlebars.java body: ... ";
diff --git a/handlebars/src/test/java/handlebarsjs/spec/BlockHelperMissingTest.java b/handlebars/src/test/java/handlebarsjs/spec/BlockHelperMissingTest.java
index d9f0132a1..4856b1c57 100644
--- a/handlebars/src/test/java/handlebarsjs/spec/BlockHelperMissingTest.java
+++ b/handlebars/src/test/java/handlebarsjs/spec/BlockHelperMissingTest.java
@@ -15,9 +15,16 @@
import com.github.jknack.handlebars.HelperRegistry;
import com.github.jknack.handlebars.Options;
import com.github.jknack.handlebars.Template;
+import com.github.jknack.handlebars.context.JavaBeanValueResolver;
public class BlockHelperMissingTest extends AbstractTest {
+ @Override protected Object configureContext(Object context) {
+ return Context.newBuilder(context)
+ .resolver(JavaBeanValueResolver.INSTANCE)
+ .build();
+ }
+
@Test
public void ifContextIsNotFoundHelperMissingIsUsed() throws IOException {
String string = "{{hello}} {{link_to world}}";
From 56e53f3fe6574456e05e480e477e93028ebf189c Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 11 Oct 2021 20:35:52 -0300
Subject: [PATCH 073/157] conditional helpers throw ClassCastExceptions when
arguments are different classes fix #827
---
.../handlebars/helper/ConditionalHelpers.java | 57 ++++++++++++++++---
.../github/jknack/handlebars/Issue827.java | 23 ++++++++
2 files changed, 71 insertions(+), 9 deletions(-)
create mode 100644 handlebars/src/test/java/com/github/jknack/handlebars/Issue827.java
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/ConditionalHelpers.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/ConditionalHelpers.java
index dc917bdc3..55846b2c3 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/ConditionalHelpers.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/ConditionalHelpers.java
@@ -17,14 +17,15 @@
*/
package com.github.jknack.handlebars.helper;
+import static org.apache.commons.lang3.Validate.isTrue;
+
+import java.io.IOException;
+import java.util.Objects;
+
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
import com.github.jknack.handlebars.TagType;
-import static org.apache.commons.lang3.Validate.isTrue;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-
-import java.io.IOException;
/**
* Implementation of equals, greater, lessThan, and, or, etc.. operators.
@@ -59,7 +60,7 @@ public enum ConditionalHelpers implements Helper {
eq {
@Override public Object apply(final Object a, final Options options) throws IOException {
Object b = options.param(0, null);
- boolean result = new EqualsBuilder().append(a, b).isEquals();
+ boolean result = eq(a, b);
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
@@ -94,7 +95,7 @@ public enum ConditionalHelpers implements Helper {
neq {
@Override public Object apply(final Object a, final Options options) throws IOException {
Object b = options.param(0, null);
- boolean result = !new EqualsBuilder().append(a, b).isEquals();
+ boolean result = !eq(a, b);
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
@@ -394,8 +395,46 @@ public enum ConditionalHelpers implements Helper {
* @return Int.
*/
protected int cmp(final Object a, final Object b) {
- isTrue(a instanceof Comparable, "Not a comparable: " + a);
- isTrue(b instanceof Comparable, "Not a comparable: " + b);
- return ((Comparable) a).compareTo(b);
+ try {
+ isTrue(a instanceof Comparable, "Not a comparable: " + a);
+ isTrue(b instanceof Comparable, "Not a comparable: " + b);
+ return ((Comparable) a).compareTo(b);
+ } catch (ClassCastException x) {
+ return Double.compare(toDoubleOrError(a, x), toDoubleOrError(b, x));
+ }
+ }
+
+ /**
+ * Compare two values. Number equality are treated as equals on they are like: 2 vs 2.0
+ *
+ * @param a First value.
+ * @param b Second value.
+ * @return True when equals.
+ */
+ protected boolean eq(final Object a, final Object b) {
+ boolean value = Objects.equals(a, b);
+ if (!value) {
+ if (a instanceof Number && b instanceof Number) {
+ // int vs double: 2 vs 2.0
+ return ((Number) a).doubleValue() == ((Number) b).doubleValue();
+ }
+ }
+ return value;
+ }
+
+ /**
+ * Generate double from value or throw existing exception.
+ * @param value Value to cast.
+ * @param x Exception.
+ * @return Double.
+ */
+ private double toDoubleOrError(final Object value, final RuntimeException x) {
+ if (value instanceof Double) {
+ return (Double) value;
+ }
+ if (value instanceof Number) {
+ return ((Number) value).doubleValue();
+ }
+ throw x;
}
}
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/Issue827.java b/handlebars/src/test/java/com/github/jknack/handlebars/Issue827.java
new file mode 100644
index 000000000..4b6683da5
--- /dev/null
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/Issue827.java
@@ -0,0 +1,23 @@
+package com.github.jknack.handlebars;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import com.github.jknack.handlebars.helper.ConditionalHelpers;
+
+public class Issue827 extends v4Test {
+
+ @Override protected void configure(Handlebars handlebars) {
+ handlebars.registerHelpers(ConditionalHelpers.class);
+ }
+
+ @Test
+ public void shouldIgnoreDifferentNumTypes() throws IOException {
+ shouldCompileTo("{{gt 5 2.0}}", $(), "true");
+
+ shouldCompileTo("{{eq 5 2.0}}", $(), "false");
+
+ shouldCompileTo("{{eq 2 2.0}}", $(), "true");
+ }
+}
From 45d30967fdc2b95873e871e7c73447b6e60a1461 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 11 Oct 2021 20:51:17 -0300
Subject: [PATCH 074/157] cut on empty string returns unexpected result fix
#714
---
.../handlebars/helper/StringHelpers.java | 7 ++++++
.../github/jknack/handlebars/Issue714.java | 22 +++++++++++++++++++
2 files changed, 29 insertions(+)
create mode 100644 handlebars/src/test/java/com/github/jknack/handlebars/Issue714.java
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java
index 798247222..675e1ccc8 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java
@@ -103,8 +103,15 @@ protected CharSequence safeApply(final Object value, final Options options) {
* If value is "String with spaces", the output will be "Stringwithspaces".
*/
cut {
+ @Override public Object apply(Object context, Options options) throws IOException {
+ return safeApply(context, options);
+ }
+
@Override
protected CharSequence safeApply(final Object value, final Options options) {
+ if (options.isFalsy(value)) {
+ return "";
+ }
String strip = options.param(0, " ");
return value.toString().replace(strip, "");
}
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/Issue714.java b/handlebars/src/test/java/com/github/jknack/handlebars/Issue714.java
new file mode 100644
index 000000000..60c709674
--- /dev/null
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/Issue714.java
@@ -0,0 +1,22 @@
+package com.github.jknack.handlebars;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import com.github.jknack.handlebars.helper.ConditionalHelpers;
+import com.github.jknack.handlebars.helper.StringHelpers;
+
+public class Issue714 extends v4Test {
+
+ @Override protected void configure(Handlebars handlebars) {
+ handlebars.registerHelpers(StringHelpers.class);
+ }
+
+ @Test
+ public void shouldIgnoreEmptyString() throws IOException {
+ shouldCompileTo("{{cut value \"-\"}}", $("hash", $("value", "")), "");
+
+ shouldCompileTo("{{cut value \"-\"}}", $("hash", $("value", "2019-12-30")), "20191230");
+ }
+}
From bbc313de25aa3499c95affba63ba799bf11d246c Mon Sep 17 00:00:00 2001
From: Stefan Bechtold
Date: Thu, 4 Feb 2021 20:33:44 +0100
Subject: [PATCH 075/157] Update Text.java
Prior to this change, the text was internally stored by holding a char[].
This led to many calls to Arrays.copy() and reduced performance.
---
.../jknack/handlebars/internal/Text.java | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/internal/Text.java b/handlebars/src/main/java/com/github/jknack/handlebars/internal/Text.java
index 4fddbacaf..11f832a90 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/internal/Text.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/internal/Text.java
@@ -34,7 +34,7 @@ class Text extends BaseTemplate {
/**
* The plain text. Required.
*/
- private char[] text;
+ private StringBuilder text;
/** The escape's char or empty. */
private String escapeChar;
@@ -48,9 +48,7 @@ class Text extends BaseTemplate {
*/
Text(final Handlebars handlebars, final String text, final String escapeChar) {
super(handlebars);
- int length = text.length();
- this.text = new char[length];
- text.getChars(0, length, this.text, 0);
+ this.text = new StringBuilder(text);
this.escapeChar = escapeChar;
}
@@ -66,19 +64,19 @@ class Text extends BaseTemplate {
@Override
public String text() {
- return escapeChar + new String(text);
+ return escapeChar + text.toString();
}
/**
* @return Same as {@link #text()} without the escape char.
*/
public char[] textWithoutEscapeChar() {
- return text;
+ return text.toString().toCharArray();
}
@Override
protected void merge(final Context scope, final Writer writer) throws IOException {
- writer.write(text);
+ writer.write(text.toString());
}
/**
@@ -88,11 +86,7 @@ protected void merge(final Context scope, final Writer writer) throws IOExceptio
* @return This object.
*/
public Text append(final char[] text) {
- int length = this.text.length + text.length;
- char[] ntext = new char[length];
- System.arraycopy(this.text, 0, ntext, 0, this.text.length);
- System.arraycopy(text, 0, ntext, this.text.length, text.length);
- this.text = ntext;
+ this.text.append(text);
return this;
}
From 0b523739922537867e10102a1ee0a62c91937f8d Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 11 Oct 2021 21:02:56 -0300
Subject: [PATCH 076/157] Add note to readme about Java 8 requirement
---
README.md | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index cca2011fa..d0571a8d1 100644
--- a/README.md
+++ b/README.md
@@ -25,13 +25,16 @@ Handlebars provides the power necessary to let you build semantic templates effe
[Mustache](https://mustache.github.io/mustache.5.html) templates are compatible with Handlebars, so you can take a [Mustache](https://mustache.github.io) template, import it into Handlebars, and start taking advantage of the extra Handlebars features.
+# Requirements
+
+- Handlebars 4.3+ requires Java 8 or higher.
+
+
# Getting Started
In general, the syntax of **Handlebars** templates is a superset of [Mustache](https://mustache.github.io) templates. For basic syntax, check out the [Mustache manpage](https://mustache.github.io).
The [Handlebars.java blog](https://jknack.github.io/handlebars.java) is a good place for getting started too. Javadoc is available at [javadoc.io](https://javadoc.io/doc/com.github.jknack/handlebars).
- Since 4.3.0 release Handlebars.java requires Java 8 or higher.
-
## Maven
#### Stable version: [](https://maven-badges.herokuapp.com/maven-central/com.github.jknack/handlebars)
From 6c1296ee6133d12f6fedd56efa3977ffad656ce5 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 11 Oct 2021 21:09:35 -0300
Subject: [PATCH 077/157] build: fix checkstyle and some tests
---
.../com/github/jknack/handlebars/helper/StringHelpers.java | 2 +-
.../com/github/jknack/handlebars/helper/StringHelpersTest.java | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java
index 675e1ccc8..37483ea1d 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/StringHelpers.java
@@ -103,7 +103,7 @@ protected CharSequence safeApply(final Object value, final Options options) {
* If value is "String with spaces", the output will be "Stringwithspaces".
*/
cut {
- @Override public Object apply(Object context, Options options) throws IOException {
+ @Override public Object apply(final Object context, final Options options) throws IOException {
return safeApply(context, options);
}
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java
index dd69b550a..e37885bd9 100644
--- a/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/helper/StringHelpersTest.java
@@ -471,6 +471,7 @@ public void nullContext() throws IOException {
helpers.remove(StringHelpers.join);
helpers.remove(StringHelpers.yesno);
helpers.remove(StringHelpers.defaultIfEmpty);
+ helpers.remove(cut);
Options options = mock(Options.class);
when(options.isFalsy(any())).thenReturn(true);
@@ -490,6 +491,7 @@ public void nullContextWithDefault() throws IOException {
helpers.remove(StringHelpers.join);
helpers.remove(StringHelpers.yesno);
helpers.remove(StringHelpers.defaultIfEmpty);
+ helpers.remove(cut);
String nothing = "nothing";
Options options = mock(Options.class);
@@ -510,6 +512,7 @@ public void nullContextWithNumber() throws IOException {
helpers.remove(StringHelpers.join);
helpers.remove(StringHelpers.yesno);
helpers.remove(StringHelpers.defaultIfEmpty);
+ helpers.remove(cut);
Object number = 32;
Options options = mock(Options.class);
From a00892662e4449c4efb46e2996d1a6a676425431 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 11 Oct 2021 21:27:02 -0300
Subject: [PATCH 078/157] v4.3.0
---
handlebars-caffeine/pom.xml | 2 +-
handlebars-guava-cache/pom.xml | 2 +-
handlebars-helpers/pom.xml | 2 +-
handlebars-humanize/pom.xml | 2 +-
handlebars-jackson2/pom.xml | 2 +-
handlebars-maven-plugin-tests/pom.xml | 2 +-
handlebars-maven-plugin/pom.xml | 2 +-
handlebars-proto/pom.xml | 2 +-
handlebars-springmvc/pom.xml | 2 +-
handlebars/pom.xml | 2 +-
pom.xml | 2 +-
11 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/handlebars-caffeine/pom.xml b/handlebars-caffeine/pom.xml
index ec0ad6e70..1682c4026 100644
--- a/handlebars-caffeine/pom.xml
+++ b/handlebars-caffeine/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml
index 73f91ce7d..85f7e99da 100644
--- a/handlebars-guava-cache/pom.xml
+++ b/handlebars-guava-cache/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml
index e083eb122..23fbcaa79 100644
--- a/handlebars-helpers/pom.xml
+++ b/handlebars-helpers/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml
index 2c67802ff..e46e0f9ec 100644
--- a/handlebars-humanize/pom.xml
+++ b/handlebars-humanize/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml
index 4d3e7d93b..b888780f5 100644
--- a/handlebars-jackson2/pom.xml
+++ b/handlebars-jackson2/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml
index 7ec6f68fd..8ba8a23c1 100644
--- a/handlebars-maven-plugin-tests/pom.xml
+++ b/handlebars-maven-plugin-tests/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index 37833b58a..dc97a401d 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index 6f75c052c..90a3d96c4 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml
index ede00ae55..9eddbc6d4 100644
--- a/handlebars-springmvc/pom.xml
+++ b/handlebars-springmvc/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/handlebars/pom.xml b/handlebars/pom.xml
index fbd19fa00..25208b3ab 100644
--- a/handlebars/pom.xml
+++ b/handlebars/pom.xml
@@ -6,7 +6,7 @@
com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.04.0.0
diff --git a/pom.xml b/pom.xml
index e4e7eb8fe..131bbc277 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0com.github.jknackhandlebars.java
- 4.3.0-SNAPSHOT
+ 4.3.0pomHandlebars.java
From ef79693a7d49ccfe28da7da12355db331a0cb317 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Mon, 11 Oct 2021 21:27:57 -0300
Subject: [PATCH 079/157] prepare for next development cycle
---
handlebars-caffeine/pom.xml | 2 +-
handlebars-guava-cache/pom.xml | 2 +-
handlebars-helpers/pom.xml | 2 +-
handlebars-humanize/pom.xml | 2 +-
handlebars-jackson2/pom.xml | 2 +-
handlebars-maven-plugin-tests/pom.xml | 2 +-
handlebars-maven-plugin/pom.xml | 2 +-
handlebars-proto/pom.xml | 2 +-
handlebars-springmvc/pom.xml | 2 +-
handlebars/pom.xml | 2 +-
pom.xml | 2 +-
11 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/handlebars-caffeine/pom.xml b/handlebars-caffeine/pom.xml
index 1682c4026..2a36a4bdc 100644
--- a/handlebars-caffeine/pom.xml
+++ b/handlebars-caffeine/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml
index 85f7e99da..f2e74817a 100644
--- a/handlebars-guava-cache/pom.xml
+++ b/handlebars-guava-cache/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml
index 23fbcaa79..fa993494c 100644
--- a/handlebars-helpers/pom.xml
+++ b/handlebars-helpers/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml
index e46e0f9ec..d4255c258 100644
--- a/handlebars-humanize/pom.xml
+++ b/handlebars-humanize/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml
index b888780f5..55a84605f 100644
--- a/handlebars-jackson2/pom.xml
+++ b/handlebars-jackson2/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml
index 8ba8a23c1..96d256d4d 100644
--- a/handlebars-maven-plugin-tests/pom.xml
+++ b/handlebars-maven-plugin-tests/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index dc97a401d..d85687f4d 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index 90a3d96c4..92255d0e3 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml
index 9eddbc6d4..d19c95884 100644
--- a/handlebars-springmvc/pom.xml
+++ b/handlebars-springmvc/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/handlebars/pom.xml b/handlebars/pom.xml
index 25208b3ab..12f3b44db 100644
--- a/handlebars/pom.xml
+++ b/handlebars/pom.xml
@@ -6,7 +6,7 @@
com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOT4.0.0
diff --git a/pom.xml b/pom.xml
index 131bbc277..8d678f2b3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0com.github.jknackhandlebars.java
- 4.3.0
+ 4.3.1-SNAPSHOTpomHandlebars.java
From ff12b6b87f883fd8477c53a38390aad9d4457a41 Mon Sep 17 00:00:00 2001
From: Andreas Schwarte
Date: Tue, 18 Oct 2022 12:16:05 +0200
Subject: [PATCH 080/157] GH-1009: update Apache Commons Text to 1.10.0
Fix CVE-2022-42889
Note that Apache Commons Text is packaged as a shaded dependency.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 8d678f2b3..ae710c210 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,7 +71,7 @@
org.apache.commonscommons-text
- 1.9
+ 1.10.0
From 32b7b35d9bd0b0cda399ceb56a6ba1ed236fc2c0 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 18 Oct 2022 11:59:44 +0000
Subject: [PATCH 081/157] Bump jackson-databind from 2.13.0 to 2.13.2.1
Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.13.0 to 2.13.2.1.
- [Release notes](https://github.com/FasterXML/jackson/releases)
- [Commits](https://github.com/FasterXML/jackson/commits)
---
updated-dependencies:
- dependency-name: com.fasterxml.jackson.core:jackson-databind
dependency-type: direct:production
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index ae710c210..cae00d221 100644
--- a/pom.xml
+++ b/pom.xml
@@ -394,7 +394,7 @@
UTF-8
- 2.13.0
+ 2.13.2.11.2.20.8.7yyyy-MM-dd HH:mm:ssa
From 28c4e551700aadc74d5936e65bcdb389e684d735 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 18 Oct 2022 12:31:45 +0000
Subject: [PATCH 082/157] Bump snakeyaml from 1.29 to 1.31
Bumps [snakeyaml](https://bitbucket.org/snakeyaml/snakeyaml) from 1.29 to 1.31.
- [Commits](https://bitbucket.org/snakeyaml/snakeyaml/branches/compare/snakeyaml-1.31..snakeyaml-1.29)
---
updated-dependencies:
- dependency-name: org.yaml:snakeyaml
dependency-type: direct:production
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index cae00d221..a06367da3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -147,7 +147,7 @@
org.yamlsnakeyaml
- 1.29
+ 1.31test
From 74ab8faacbf546a5c381e40ab4867bdc073bbfcb Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Thu, 15 Sep 2022 09:27:16 +0000
Subject: [PATCH 083/157] Bump spring-webmvc from 5.3.10 to 5.3.23
Bumps [spring-webmvc](https://github.com/spring-projects/spring-framework) from 5.3.10 to 5.3.23.
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.3.10...v5.3.23)
---
updated-dependencies:
- dependency-name: org.springframework:spring-webmvc
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index a06367da3..a7a3c3ca3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,7 +77,7 @@
org.springframeworkspring-webmvc
- 5.3.10
+ 5.3.23
From 46df78c23183b3719143e0cb8052ffa0ef5cb313 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 10 Oct 2022 09:28:15 +0000
Subject: [PATCH 084/157] Bump logback-classic from 1.2.6 to 1.4.4
Bumps [logback-classic](https://github.com/qos-ch/logback) from 1.2.6 to 1.4.4.
- [Release notes](https://github.com/qos-ch/logback/releases)
- [Commits](https://github.com/qos-ch/logback/compare/v_1.2.6...v_1.4.4)
---
updated-dependencies:
- dependency-name: ch.qos.logback:logback-classic
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index a7a3c3ca3..567286484 100644
--- a/pom.xml
+++ b/pom.xml
@@ -133,7 +133,7 @@
ch.qos.logbacklogback-classic
- 1.2.6
+ 1.4.4test
From d8bbd04522568958aa628a839104c1e46284fe8a Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Thu, 8 Sep 2022 09:54:21 +0000
Subject: [PATCH 085/157] Bump mockito-core from 4.0.0 to 4.8.0
Bumps [mockito-core](https://github.com/mockito/mockito) from 4.0.0 to 4.8.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](https://github.com/mockito/mockito/compare/v4.0.0...v4.8.0)
---
updated-dependencies:
- dependency-name: org.mockito:mockito-core
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 567286484..c7fbebbf9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -154,7 +154,7 @@
org.mockitomockito-core
- 4.0.0
+ 4.8.0test
From 34d1d04f5d4891ca207858b7767fefee9b052e76 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 8 Nov 2021 09:20:32 +0000
Subject: [PATCH 086/157] Bump antlr-version from 4.9.2 to 4.9.3
Bumps `antlr-version` from 4.9.2 to 4.9.3.
Updates `antlr4-runtime` from 4.9.2 to 4.9.3
- [Release notes](https://github.com/antlr/antlr4/releases)
- [Changelog](https://github.com/antlr/antlr4/blob/master/CHANGES.txt)
- [Commits](https://github.com/antlr/antlr4/compare/4.9.2...4.9.3)
Updates `antlr4-maven-plugin` from 4.9.2 to 4.9.3
- [Release notes](https://github.com/antlr/antlr4/releases)
- [Changelog](https://github.com/antlr/antlr4/blob/master/CHANGES.txt)
- [Commits](https://github.com/antlr/antlr4/compare/4.9.2...4.9.3)
---
updated-dependencies:
- dependency-name: org.antlr:antlr4-runtime
dependency-type: direct:production
update-type: version-update:semver-patch
- dependency-name: org.antlr:antlr4-maven-plugin
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot]
---
handlebars-caffeine/pom.xml | 2 +-
handlebars-humanize/pom.xml | 2 +-
handlebars-springmvc/pom.xml | 2 +-
handlebars/pom.xml | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/handlebars-caffeine/pom.xml b/handlebars-caffeine/pom.xml
index 2a36a4bdc..e2400459f 100644
--- a/handlebars-caffeine/pom.xml
+++ b/handlebars-caffeine/pom.xml
@@ -70,7 +70,7 @@
org.antlrantlr4-runtime
- 4.9.2
+ 4.9.3org.abego.treelayout
diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml
index d4255c258..e84d7be9d 100644
--- a/handlebars-humanize/pom.xml
+++ b/handlebars-humanize/pom.xml
@@ -54,7 +54,7 @@
org.antlrantlr4-runtime
- 4.9.2
+ 4.9.3org.abego.treelayout
diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml
index d19c95884..ad8187ce7 100644
--- a/handlebars-springmvc/pom.xml
+++ b/handlebars-springmvc/pom.xml
@@ -67,7 +67,7 @@
org.antlrantlr4-runtime
- 4.9.2
+ 4.9.3org.abego.treelayout
diff --git a/handlebars/pom.xml b/handlebars/pom.xml
index 12f3b44db..f054d7816 100644
--- a/handlebars/pom.xml
+++ b/handlebars/pom.xml
@@ -228,7 +228,7 @@
- 4.9.2
+ 4.9.315.3
From b7c6a8c2b1455e12735a765e04bcf5d6c5348e4f Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 18 Oct 2022 12:48:46 +0000
Subject: [PATCH 087/157] Bump jetty-webapp in /handlebars-proto
Bumps [jetty-webapp](https://github.com/eclipse/jetty.project) from 9.4.43.v20210629 to 9.4.44.v20210927.
- [Release notes](https://github.com/eclipse/jetty.project/releases)
- [Commits](https://github.com/eclipse/jetty.project/compare/jetty-9.4.43.v20210629...jetty-9.4.44.v20210927)
---
updated-dependencies:
- dependency-name: org.eclipse.jetty:jetty-webapp
dependency-type: direct:production
...
Signed-off-by: dependabot[bot]
---
handlebars-proto/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index 92255d0e3..1c9261a67 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -14,7 +14,7 @@
A standalone Handlebars Server
- 9.4.43.v20210629
+ 9.4.44.v20210927
From e46ba8df082eafe9ff43d6de674f4d6bce07d209 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Thu, 13 Oct 2022 09:28:50 +0000
Subject: [PATCH 088/157] Bump joda-time from 2.10.12 to 2.12.0
Bumps [joda-time](https://github.com/JodaOrg/joda-time) from 2.10.12 to 2.12.0.
- [Release notes](https://github.com/JodaOrg/joda-time/releases)
- [Changelog](https://github.com/JodaOrg/joda-time/blob/main/RELEASE-NOTES.txt)
- [Commits](https://github.com/JodaOrg/joda-time/compare/v2.10.12...v2.12.0)
---
updated-dependencies:
- dependency-name: joda-time:joda-time
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
handlebars-helpers/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml
index fa993494c..14c00ad85 100644
--- a/handlebars-helpers/pom.xml
+++ b/handlebars-helpers/pom.xml
@@ -30,7 +30,7 @@
joda-timejoda-time
- 2.10.12
+ 2.12.0true
From 29f62966237f6dc13ff3f1751f12679060538061 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Tue, 12 Oct 2021 11:44:18 -0300
Subject: [PATCH 089/157] tests: get back some tests we removed while migrating
to Java 11
---
.../github/jknack/handlebars/EachKeyTest.java | 28 +++++++++++--------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java b/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java
index 9bd3b252f..d20026a98 100644
--- a/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java
+++ b/handlebars/src/test/java/com/github/jknack/handlebars/EachKeyTest.java
@@ -22,8 +22,11 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
-import org.junit.Ignore;
+import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import com.github.jknack.handlebars.context.JavaBeanValueResolver;
@@ -57,28 +60,29 @@ public String getBody() {
.build();
}
- @Ignore
+ @Test
public void eachKeyWithString() throws IOException {
- String result = compile("{{#each this}}{{@key}} {{/each}}").apply("String");
+ Set result = Stream.of(StringUtils.split(
+ compile("{{#each this}}{{@key}} {{/each}}").apply(configureContext("String")), " "))
+ .collect(Collectors.toSet());
- String expected1 = "empty bytes ";
- String expected2 = "bytes empty ";
- assertTrue(result.equals(expected1) || result.equals(expected2));
+ Set expected = Stream.of("empty", "bytes").collect(Collectors.toSet());
+ assertTrue(result.containsAll(expected));
}
- @Ignore
+ @Test
public void eachKeyWithInt() throws IOException {
- shouldCompileTo("{{#each this}}{{@key}} {{/each}}", 7, "");
+ shouldCompileTo("{{#each this}}{{@key}} {{/each}}", configureContext(7), "");
}
@Test
public void eachKeyWithJavaBean() throws IOException {
Blog blog = new Blog("Handlebars.java", "...");
- String result = compile("{{#each this}}{{@key}}: {{this}} {{/each}}").apply(configureContext(blog));
+ Set result = Stream.of(StringUtils.split(compile("{{#each this}}{{@key}}:{{this}} {{/each}}").apply(configureContext(blog)), " ")).collect(
+ Collectors.toSet());
- String expected1 = "body: ... title: Handlebars.java ";
- String expected2 = "title: Handlebars.java body: ... ";
- assertTrue(result.equals(expected1) || result.equals(expected2));
+ Set expected = Stream.of("body:...", "title:Handlebars.java").collect(Collectors.toSet());
+ assertTrue(result.containsAll(expected));
}
@Test
From efae7baa18fe8d4d35b5b94b15a4d306cfa15dcb Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Tue, 18 Oct 2022 10:02:27 -0300
Subject: [PATCH 090/157] version bump: jackson 2.14.0-rc2
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c7fbebbf9..3374c28e4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -394,7 +394,7 @@
UTF-8
- 2.13.2.1
+ 2.14.0-rc21.2.20.8.7yyyy-MM-dd HH:mm:ssa
From 683c5e885d5dcdf3d17b33e9667f3fb153952016 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Tue, 18 Oct 2022 10:18:01 -0300
Subject: [PATCH 091/157] v4.3.1
---
handlebars-caffeine/pom.xml | 2 +-
handlebars-guava-cache/pom.xml | 2 +-
handlebars-helpers/pom.xml | 2 +-
handlebars-humanize/pom.xml | 2 +-
handlebars-jackson2/pom.xml | 2 +-
handlebars-maven-plugin-tests/pom.xml | 2 +-
handlebars-maven-plugin/pom.xml | 2 +-
handlebars-proto/pom.xml | 2 +-
handlebars-springmvc/pom.xml | 2 +-
handlebars/pom.xml | 2 +-
pom.xml | 2 +-
11 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/handlebars-caffeine/pom.xml b/handlebars-caffeine/pom.xml
index e2400459f..67e0b57e4 100644
--- a/handlebars-caffeine/pom.xml
+++ b/handlebars-caffeine/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml
index f2e74817a..87f7adf13 100644
--- a/handlebars-guava-cache/pom.xml
+++ b/handlebars-guava-cache/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml
index 14c00ad85..d600b72e9 100644
--- a/handlebars-helpers/pom.xml
+++ b/handlebars-helpers/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml
index e84d7be9d..4d27a59c9 100644
--- a/handlebars-humanize/pom.xml
+++ b/handlebars-humanize/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml
index 55a84605f..9bf3785ed 100644
--- a/handlebars-jackson2/pom.xml
+++ b/handlebars-jackson2/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml
index 96d256d4d..3fa39701b 100644
--- a/handlebars-maven-plugin-tests/pom.xml
+++ b/handlebars-maven-plugin-tests/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index d85687f4d..ea50969f1 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index 1c9261a67..254b41ef0 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml
index ad8187ce7..15427baa2 100644
--- a/handlebars-springmvc/pom.xml
+++ b/handlebars-springmvc/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/handlebars/pom.xml b/handlebars/pom.xml
index f054d7816..cc7fe9766 100644
--- a/handlebars/pom.xml
+++ b/handlebars/pom.xml
@@ -6,7 +6,7 @@
com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.14.0.0
diff --git a/pom.xml b/pom.xml
index 3374c28e4..33c83f5c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0com.github.jknackhandlebars.java
- 4.3.1-SNAPSHOT
+ 4.3.1pomHandlebars.java
From 793260acf39368432654705aa3f5004c393b4c29 Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Tue, 18 Oct 2022 10:20:22 -0300
Subject: [PATCH 092/157] Add funding buttons
---
.github/FUNDING.yml | 2 ++
README.md | 3 ---
2 files changed, 2 insertions(+), 3 deletions(-)
create mode 100644 .github/FUNDING.yml
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 000000000..456ef9e56
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,2 @@
+github: [jknack]
+patreon: edgarespina
diff --git a/README.md b/README.md
index d0571a8d1..80c4069ce 100644
--- a/README.md
+++ b/README.md
@@ -1058,9 +1058,6 @@ Hello {{#child}}{{this.value}}{{/child}}
[Bugs, Issues and Features](https://github.com/jknack/handlebars.java/issues)
-## Donate
-
-Buy [Edgar](https://patreon.com/edgarespina) a beer!
## Related Projects
* [Handlebars.js](http://handlebarsjs.com/)
From c35870302c1bcc4b7b84f8f26661dfc48f8b35bd Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Tue, 18 Oct 2022 10:21:51 -0300
Subject: [PATCH 093/157] prepare for next development cycle
---
handlebars-caffeine/pom.xml | 2 +-
handlebars-guava-cache/pom.xml | 2 +-
handlebars-helpers/pom.xml | 2 +-
handlebars-humanize/pom.xml | 2 +-
handlebars-jackson2/pom.xml | 2 +-
handlebars-maven-plugin-tests/pom.xml | 2 +-
handlebars-maven-plugin/pom.xml | 2 +-
handlebars-proto/pom.xml | 2 +-
handlebars-springmvc/pom.xml | 2 +-
handlebars/pom.xml | 2 +-
pom.xml | 2 +-
11 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/handlebars-caffeine/pom.xml b/handlebars-caffeine/pom.xml
index 67e0b57e4..162f55944 100644
--- a/handlebars-caffeine/pom.xml
+++ b/handlebars-caffeine/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/handlebars-guava-cache/pom.xml b/handlebars-guava-cache/pom.xml
index 87f7adf13..3450e4db4 100644
--- a/handlebars-guava-cache/pom.xml
+++ b/handlebars-guava-cache/pom.xml
@@ -5,7 +5,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/handlebars-helpers/pom.xml b/handlebars-helpers/pom.xml
index d600b72e9..c45581145 100644
--- a/handlebars-helpers/pom.xml
+++ b/handlebars-helpers/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/handlebars-humanize/pom.xml b/handlebars-humanize/pom.xml
index 4d27a59c9..3aa1c9949 100644
--- a/handlebars-humanize/pom.xml
+++ b/handlebars-humanize/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/handlebars-jackson2/pom.xml b/handlebars-jackson2/pom.xml
index 9bf3785ed..842d97c6f 100644
--- a/handlebars-jackson2/pom.xml
+++ b/handlebars-jackson2/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/handlebars-maven-plugin-tests/pom.xml b/handlebars-maven-plugin-tests/pom.xml
index 3fa39701b..aab1f9386 100644
--- a/handlebars-maven-plugin-tests/pom.xml
+++ b/handlebars-maven-plugin-tests/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/handlebars-maven-plugin/pom.xml b/handlebars-maven-plugin/pom.xml
index ea50969f1..6f8693e08 100644
--- a/handlebars-maven-plugin/pom.xml
+++ b/handlebars-maven-plugin/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
index 254b41ef0..f16a9fd8f 100644
--- a/handlebars-proto/pom.xml
+++ b/handlebars-proto/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/handlebars-springmvc/pom.xml b/handlebars-springmvc/pom.xml
index 15427baa2..e0a6d3500 100644
--- a/handlebars-springmvc/pom.xml
+++ b/handlebars-springmvc/pom.xml
@@ -4,7 +4,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/handlebars/pom.xml b/handlebars/pom.xml
index cc7fe9766..066186a78 100644
--- a/handlebars/pom.xml
+++ b/handlebars/pom.xml
@@ -6,7 +6,7 @@
com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOT4.0.0
diff --git a/pom.xml b/pom.xml
index 33c83f5c4..7a44dffd7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0com.github.jknackhandlebars.java
- 4.3.1
+ 5.0.0-SNAPSHOTpomHandlebars.java
From 4d043ce39fbcf7485c56df6084536fa89368b3ec Mon Sep 17 00:00:00 2001
From: Edgar Espina
Date: Sat, 4 Mar 2023 19:21:48 -0300
Subject: [PATCH 094/157] remove handlebars-proto fix #1017
---
handlebars-proto/pom.xml | 200 ---------
.../jknack/handlebars/server/HbsServer.java | 261 -----------
.../jknack/handlebars/server/HbsServlet.java | 404 ------------------
.../src/main/resources/error-pages/error.hbs | 115 -----
.../src/main/resources/hbs.properties | 1 -
.../src/main/resources/logback.xml | 33 --
handlebars-proto/src/main/resources/try.html | 20 -
.../src/test/resources/logback-test.xml | 14 -
pom.xml | 1 -
9 files changed, 1049 deletions(-)
delete mode 100644 handlebars-proto/pom.xml
delete mode 100644 handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java
delete mode 100644 handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServlet.java
delete mode 100644 handlebars-proto/src/main/resources/error-pages/error.hbs
delete mode 100644 handlebars-proto/src/main/resources/hbs.properties
delete mode 100644 handlebars-proto/src/main/resources/logback.xml
delete mode 100644 handlebars-proto/src/main/resources/try.html
delete mode 100644 handlebars-proto/src/test/resources/logback-test.xml
diff --git a/handlebars-proto/pom.xml b/handlebars-proto/pom.xml
deleted file mode 100644
index f16a9fd8f..000000000
--- a/handlebars-proto/pom.xml
+++ /dev/null
@@ -1,200 +0,0 @@
-
-
-
-
- com.github.jknack
- handlebars.java
- 5.0.0-SNAPSHOT
-
-
- 4.0.0
- com.github.jknack
- handlebars-proto
-
- A standalone Handlebars Server
-
-
- 9.4.44.v20210927
-
-
-
-
-
- src/main/resources
- true
-
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.2.4
-
-
- package
-
- shade
-
-
-
-
-
- *:*
-
- META-INF/*.SF
- META-INF/*.RSA
- META-INF/*.INF
- META-INF/*.sf
- META-INF/*.inf
- META-INF/*.rsa
-
-
-
-
-
- com.github.jknack.handlebars.server.HbsServer
-
-
-
-
-
-
-
-
-
- com.akathist.maven.plugins.launch4j
- launch4j-maven-plugin
- 2.1.2
-
-
- l4j-clui
- none
-
- launch4j
-
-
- console
- target/handlebars.exe
- target/handlebars-proto-${project.version}.jar
- Handlebars.java
-
- com.github.jknack.handlebars.server.HbsServer
- false
-
-
- 1.6.0
-
-
- 0.5.4.0
- ${project.version}
- Handlebars.java Server
- Copyright (c) 2012 Edgar Espina
- 0.5.4.0
- Handlebars.java Server
- ${project.version}
- handlebars
- handlebars.exe
-
-
-
-
-
-
-
-
-
-
-
- org.eclipse.jetty.orbit
- javax.servlet
- 3.0.0.v201112011016
-
-
-
- com.github.jknack
- handlebars
- ${project.version}
-
-
-
- com.github.jknack
- handlebars-jackson2
- ${project.version}
-
-
-
-
-
-
-
-
-
- com.github.jknack
- handlebars-humanize
- ${project.version}
-
-
-
- commons-io
- commons-io
- 2.11.0
-
-
-
- org.apache.commons
- commons-lang3
-
-
-
- com.fasterxml.jackson.core
- jackson-databind
-
-
-
- org.yaml
- snakeyaml
- compile
-
-
-
- org.eclipse.jetty
- jetty-server
- ${jetty-version}
-
-
-
- org.eclipse.jetty
- jetty-webapp
- ${jetty-version}
-
-
-
- org.eclipse.jetty
- jetty-servlet
- ${jetty-version}
-
-
-
- ch.qos.logback
- logback-classic
- compile
-
-
-
- args4j
- args4j
- 2.33
-
-
-
-
- junit
- junit
- test
-
-
-
-
-
diff --git a/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java b/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java
deleted file mode 100644
index ffb7c8504..000000000
--- a/handlebars-proto/src/main/java/com/github/jknack/handlebars/server/HbsServer.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.github.jknack.handlebars.server;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
-import java.net.MalformedURLException;
-import java.util.Properties;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.io.IOUtils;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.ErrorHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener;
-import org.eclipse.jetty.util.component.LifeCycle;
-import org.eclipse.jetty.util.resource.Resource;
-import org.eclipse.jetty.webapp.Configuration;
-import org.eclipse.jetty.webapp.WebAppContext;
-import org.eclipse.jetty.webapp.WebXmlConfiguration;
-import org.kohsuke.args4j.CmdLineException;
-import org.kohsuke.args4j.CmdLineParser;
-import org.kohsuke.args4j.Option;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.github.jknack.handlebars.Handlebars;
-import com.github.jknack.handlebars.HelperRegistry;
-import com.github.jknack.handlebars.HumanizeHelper;
-import com.github.jknack.handlebars.Jackson2Helper;
-import com.github.jknack.handlebars.helper.StringHelpers;
-import com.github.jknack.handlebars.io.FileTemplateLoader;
-import com.github.jknack.handlebars.io.TemplateLoader;
-import com.github.jknack.handlebars.io.URLTemplateLoader;
-
-/**
- * A handlebars web server.
- *
- * @author edgar.espina
- */
-public class HbsServer {
-
- /**
- * The logging system.
- */
- public static final Logger logger = LoggerFactory.getLogger(HbsServer.class);
-
- public static final String CONTEXT = "/";
-
- public static final String CONTENT_TYPE = "text/html";
-
- public static final int PORT = 6780;
-
- public static String version;
-
- static {
- InputStream in = null;
- try {
- in = HbsServer.class.getResourceAsStream("/hbs.properties");
- Properties properties = new Properties();
- properties.load(in);
- version = properties.getProperty("version");
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- IOUtils.closeQuietly(in);
- }
-
- }
-
- public static class Options {
- @Option(name = "-dir", aliases = "-d", required = true,
- usage = "set the template directory", metaVar = " ")
- public File dir;
-
- @Option(name = "-suffix", aliases = "-sx",
- usage = "set the template's suffix, default is: "
- + TemplateLoader.DEFAULT_SUFFIX, metaVar = " ")
- public String suffix = TemplateLoader.DEFAULT_SUFFIX;
-
- @Option(name = "-prefix", aliases = "-px",
- usage = "set the template's prefix, default is: "
- + TemplateLoader.DEFAULT_PREFIX, metaVar = " ")
- public String prefix = TemplateLoader.DEFAULT_PREFIX;
-
- @Option(name = "-context", aliases = "-c",
- usage = "set the web context's path, default is: " + CONTEXT,
- metaVar = " ")
- public String contextPath = CONTEXT;
-
- @Option(name = "-port", aliases = "-p",
- usage = "set the port's number, default is: " + PORT, metaVar = " ")
- public int port = PORT;
-
- @Option(name = "-contentType", aliases = "-ct",
- usage = "set the content's type header, default is: " + CONTENT_TYPE,
- metaVar = " ")
- public String contentType = CONTENT_TYPE;
-
- @Option(name = "-encoding", aliases = "-e",
- usage = "set the charset used it while rendering, default is: UTF-8",
- metaVar = " ")
- public String encoding = "UTF-8";
- }
-
- public static void main(final String[] args) throws Exception {
- Options arguments = new Options();
- CmdLineParser parser = new CmdLineParser(arguments);
- try {
- parser.parseArgument(args);
- run(arguments);
- } catch (CmdLineException e) {
- System.err.println(e.getMessage());
- String os = System.getProperty("os.name").toLowerCase();
- System.err.println("Usage:");
- String program = "java -jar handlebars-proto-${version}.jar";
- if (os.contains("win")) {
- program = "handlebars";
- }
- System.err.println(" " + program + " [-option value]");
- System.err.println("Options:");
- parser.printUsage(System.err);
- }
- }
-
- /**
- * Start a Handlebars server.
- *
- * @param args The command line arguments.
- * @throws Exception If something goes wrong.
- */
- public static void run(final Options args) throws Exception {
- if (!args.dir.exists()) {
- System.out.println("File not found: " + args.dir);
- }
- logger.info("Welcome to the Handlebars.java server v" + version);
-
- URLTemplateLoader loader = new FileTemplateLoader(args.dir);
- loader.setPrefix(new File(args.dir, args.prefix).getAbsolutePath());
- loader.setSuffix(args.suffix);
- Handlebars handlebars = new Handlebars(loader);
-
- /**
- * Helper wont work in the stand-alone version, so we add a default helper
- * that render the plain text.
- */
- handlebars.registerHelper(
- HelperRegistry.HELPER_MISSING,
- (context, options) -> new Handlebars.SafeString(options.fn.text())
- );
- handlebars.registerHelper("json", Jackson2Helper.INSTANCE);
-// handlebars.registerHelper("md", new MarkdownHelper());
- // String helpers
- StringHelpers.register(handlebars);
- // Humanize helpers
- HumanizeHelper.register(handlebars);
-
- final Server server = new Server(args.port);
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- logger.info("Hope you enjoy it! bye!");
- try {
- server.stop();
- } catch (Exception ex) {
- logger.info("Can't stop the server", ex);
- }
- }));
-
- server.addLifeCycleListener(new AbstractLifeCycleListener() {
- @Override
- public void lifeCycleStarted(final LifeCycle event) {
- logger.info("Open a browser and type:");
- logger.info(" http://localhost:{}{}/[page]{}", new Object[]{
- args.port,
- args.contextPath.equals(CONTEXT) ? "" : args.contextPath,
- args.suffix });
- }
- });
-
- WebAppContext root = new WebAppContext();
- ErrorHandler errorHandler = new ErrorHandler() {
- @Override
- protected void writeErrorPageHead(final HttpServletRequest request, final Writer writer,
- final int code, final String message) throws IOException {
- writer
- .write("\n");
- writer.write("{{");
- writer.write(Integer.toString(code));
- writer.write("}}");
- writer.write("\n");
- writer.write("");
- }
-
- @Override
- protected void writeErrorPageMessage(final HttpServletRequest request, final Writer writer,
- final int code,
- final String message, final String uri) throws IOException {
- writer.write("
- *
- * @see Humanize#metricPrefix(Number, Locale)
- */
- metricPrefix {
- @Override
- public Object apply(final Object value, final Options options)
- throws IOException {
- return Humanize.metricPrefix((Number) value, resolveLocale(options));
- }
- },
-
- /**
- * For dates that are the current day or within one day, return 'today',
- * 'tomorrow' or 'yesterday', as appropriate. Otherwise, returns a string
- * formatted according to a locale sensitive DateFormat.
- *
- *
- * {{naturalDay date}}
- *
- *
- * @see Humanize#naturalDay(Date)
- */
- naturalDay {
- @Override
- public Object apply(final Object value, final Options options)
- throws IOException {
- return Humanize.naturalDay((Date) value);
- }
- },
-
- /**
- * Computes both past and future relative dates.
- *
- * E.g. 'one day ago', 'one day from now', '10 years ago', '3 minutes from
- * now', 'right now' and so on.
- *
- *
- *
- * {{naturalTime date [locale="default"]}}
- *
- *
- * @see Humanize#naturalTime(Date, Locale)
- */
- naturalTime {
- @Override
- public Object apply(final Object value, final Options options)
- throws IOException {
- return Humanize.naturalTime((Date) value, resolveLocale(options));
- }
- },
-
- /**
- * Converts a number to its ordinal as a string.
- *
- * E.g. 1 becomes '1st', 2 becomes '2nd', 3 becomes '3rd', etc.
- *
");
}
-
}
diff --git a/handlebars-guava-cache/src/test/java/com/github/jknack/handlebars/io/GuavaCachedTemplateLoaderTest.java b/handlebars-guava-cache/src/test/java/com/github/jknack/handlebars/io/GuavaCachedTemplateLoaderTest.java
index 67eee96fc..02240b636 100644
--- a/handlebars-guava-cache/src/test/java/com/github/jknack/handlebars/io/GuavaCachedTemplateLoaderTest.java
+++ b/handlebars-guava-cache/src/test/java/com/github/jknack/handlebars/io/GuavaCachedTemplateLoaderTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.io;
import static java.lang.System.out;
@@ -14,10 +19,9 @@ public class GuavaCachedTemplateLoaderTest {
@Test
public void testCacheWithExpiration() throws Exception {
- TemplateLoader loader = new FileTemplateLoader(new File(
- "src/test/resources"));
- TemplateLoader cachedLoader = GuavaCachedTemplateLoader
- .cacheWithExpiration(loader, 200, TimeUnit.MILLISECONDS);
+ TemplateLoader loader = new FileTemplateLoader(new File("src/test/resources"));
+ TemplateLoader cachedLoader =
+ GuavaCachedTemplateLoader.cacheWithExpiration(loader, 200, TimeUnit.MILLISECONDS);
assertNotNull(loader.sourceAt("template"));
assertNotNull(cachedLoader.sourceAt("template"));
@@ -35,7 +39,6 @@ public void testCacheWithExpiration() throws Exception {
cachedLoader.sourceAt("template");
}
out.println("Cached took: " + sw);
-
}
@Test
@@ -43,5 +46,4 @@ public void testCacheWithExpirationAgain() throws Exception {
// lazy mans JVM warming
testCacheWithExpiration();
}
-
}
diff --git a/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/AssignHelper.java b/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/AssignHelper.java
index 91ac8b4cb..d5156058e 100644
--- a/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/AssignHelper.java
+++ b/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/AssignHelper.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -34,19 +22,14 @@
*/
public class AssignHelper implements Helper {
- /**
- * A singleton instance of this helper.
- */
+ /** A singleton instance of this helper. */
public static final Helper INSTANCE = new AssignHelper();
- /**
- * The helper's name.
- */
+ /** The helper's name. */
public static final String NAME = "assign";
@Override
- public Object apply(final String variableName, final Options options)
- throws IOException {
+ public Object apply(final String variableName, final Options options) throws IOException {
CharSequence finalValue = options.apply(options.fn);
options.context.data(variableName, finalValue.toString().trim());
return null;
diff --git a/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/IncludeHelper.java b/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/IncludeHelper.java
index 98e531b67..5cf889989 100644
--- a/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/IncludeHelper.java
+++ b/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/IncludeHelper.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -25,20 +13,16 @@
import com.github.jknack.handlebars.Template;
/**
- * Allows to include partials with custom context.
- * This is a port of https://github.com/wycats/handlebars.js/pull/368
+ * Allows to include partials with custom context. This is a port of
+ * https://github.com/wycats/handlebars.js/pull/368
*
* @author https://github.com/c089
*/
public class IncludeHelper implements Helper {
- /**
- * A singleton instance of this helper.
- */
+ /** A singleton instance of this helper. */
public static final Helper INSTANCE = new IncludeHelper();
- /**
- * The helper's name.
- */
+ /** The helper's name. */
public static final String NAME = "include";
@Override
@@ -48,5 +32,4 @@ public Object apply(final String partial, final Options options) throws IOExcept
Template template = options.handlebars.compile(partial);
return new Handlebars.SafeString(template.apply(options.context));
}
-
}
diff --git a/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/JodaHelper.java b/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/JodaHelper.java
index ec6d2ca18..8b2503396 100644
--- a/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/JodaHelper.java
+++ b/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/JodaHelper.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -34,10 +22,9 @@
public enum JodaHelper implements Helper {
/**
- * A Helper for pattern-formatted ReadableInstance. Pattern usage
- * is as specified in {@link DateTimeFormat}. Defaults to
- * M d y, H:m:s z, for example
- * 11 15 1995, 14:32:10 CST.
+ * A Helper for pattern-formatted ReadableInstance. Pattern usage is as specified in
+ * {@link DateTimeFormat}. Defaults to M d y, H:m:s z, for example
+ * 11 15 1995, 14:32:10 CST.
*/
jodaPattern {
@@ -46,13 +33,11 @@ protected CharSequence safeApply(final ReadableInstant time, final Options optio
String pattern = options.param(0, "M d y, H:m:s z");
return DateTimeFormat.forPattern(pattern).print(time);
}
-
},
/**
- * A Helper for style-formatted ReadableInstant. Style usage is
- * as specified in {@link DateTimeFormat}. Defaults to MM,
- * for example
+ * A Helper for style-formatted ReadableInstant. Style usage is as specified in
+ * {@link DateTimeFormat}. Defaults to MM, for example
*/
jodaStyle {
@@ -61,12 +46,11 @@ protected CharSequence safeApply(final ReadableInstant time, final Options optio
String style = options.param(0, "MM");
return DateTimeFormat.forStyle(style).print(time);
}
-
},
/**
- * A Helper for ISO-formatted ReadableInstant.
- * Usages is detailed in {@link ISODateTimeFormat}.
+ * A Helper for ISO-formatted ReadableInstant. Usages is detailed in {@link
+ * ISODateTimeFormat}.
*/
jodaISO {
@@ -79,7 +63,6 @@ protected CharSequence safeApply(final ReadableInstant time, final Options optio
return ISODateTimeFormat.dateTimeNoMillis().print(time);
}
}
-
};
@Override
@@ -90,12 +73,9 @@ public Object apply(final ReadableInstant time, final Options options) throws IO
/**
* Apply the helper to the context.
*
- * @param time
- * The JodaTime ReadableInstant.
- * @param options
- * Any formatting options, such as the Pattern, Style, or ISO format.
+ * @param time The JodaTime ReadableInstant.
+ * @param options Any formatting options, such as the Pattern, Style, or ISO format.
* @return The String result.
*/
protected abstract CharSequence safeApply(ReadableInstant time, Options options);
-
}
diff --git a/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/NumberHelper.java b/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/NumberHelper.java
index 0a0f851ca..22f37a613 100644
--- a/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/NumberHelper.java
+++ b/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/NumberHelper.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -33,14 +21,14 @@
public enum NumberHelper implements Helper {
/**
- * You can use the isEven helper to return a value only if the first argument
- * is even. Otherwise return null.
+ * You can use the isEven helper to return a value only if the first argument is even. Otherwise
+ * return null.
*
*
{@code
*
* }
- * If value is 2, the output will be "leftBox".
*
+ * If value is 2, the output will be "leftBox".
*/
isEven {
@Override
@@ -50,14 +38,14 @@ public CharSequence safeApply(final Number value, final Options options) {
},
/**
- * You can use the isOdd helper to return a value only if the first argument
- * is odd. Otherwise return null.
+ * You can use the isOdd helper to return a value only if the first argument is odd. Otherwise
+ * return null.
*
*
{@code
*
* }
- * If value is 3, the output will be "rightBox".
*
+ * If value is 3, the output will be "rightBox".
*/
isOdd {
@Override
@@ -67,14 +55,13 @@ public CharSequence safeApply(final Number value, final Options options) {
},
/**
- * You can use the stripes helper to return different value if the passed
- * argument is odd or even.
+ * You can use the stripes helper to return different value if the passed argument is odd or even.
*
*
{@code
*
* }
- * If value is 2, the output will be "row-even".
*
+ * If value is 2, the output will be "row-even".
*/
stripes {
@Override
@@ -84,8 +71,7 @@ public CharSequence safeApply(final Number value, final Options options) {
};
@Override
- public Object apply(final Object context, final Options options)
- throws IOException {
+ public Object apply(final Object context, final Options options) throws IOException {
if (context instanceof Number) {
return safeApply((Number) context, options);
}
@@ -95,10 +81,8 @@ public Object apply(final Object context, final Options options)
/**
* Apply the helper to the context.
*
- * @param value
- * The context object (param=0).
- * @param options
- * The options object.
+ * @param value The context object (param=0).
+ * @param options The options object.
* @return A string result.
*/
protected abstract CharSequence safeApply(Number value, Options options);
@@ -106,8 +90,7 @@ public Object apply(final Object context, final Options options)
/**
* Apply the helper to the context.
*
- * @param value
- * The number value.
+ * @param value The number value.
* @return true is even, false is odd
*/
protected boolean isEven(final Number value) {
@@ -117,8 +100,7 @@ protected boolean isEven(final Number value) {
/**
* Register the helper in a handlebars instance.
*
- * @param handlebars
- * A handlebars object. Required.
+ * @param handlebars A handlebars object. Required.
*/
public void registerHelper(final Handlebars handlebars) {
notNull(handlebars, "The handlebars is required.");
@@ -128,8 +110,7 @@ public void registerHelper(final Handlebars handlebars) {
/**
* Register all the number helpers.
*
- * @param handlebars
- * The helper's owner. Required.
+ * @param handlebars The helper's owner. Required.
*/
public static void register(final Handlebars handlebars) {
notNull(handlebars, "A handlebars object is required.");
diff --git a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/AssignHelperTest.java b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/AssignHelperTest.java
index d7654d98b..ed52b7be8 100644
--- a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/AssignHelperTest.java
+++ b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/AssignHelperTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.helper;
import static org.junit.Assert.assertEquals;
@@ -21,17 +26,17 @@ protected void configure(final Handlebars handlebars) {
public void assignResult() throws IOException {
shouldCompileTo(
"{{#assign \"benefitsTitle\"}} benefits.{{type}}.title {{/assign}}",
- $("type", "discounts"), "");
+ $("type", "discounts"),
+ "");
}
@Test
public void assignContext() throws IOException {
Context context = Context.newContext($("type", "discounts"));
- shouldCompileTo("{{#assign \"benefitsTitle\"}} benefits.{{type}}.title {{/assign}}",
- context, "");
+ shouldCompileTo(
+ "{{#assign \"benefitsTitle\"}} benefits.{{type}}.title {{/assign}}", context, "");
assertEquals("benefits.discounts.title", context.data("benefitsTitle"));
}
-
}
diff --git a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/IncludeTest.java b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/IncludeTest.java
index dd4a64a6e..b4bc3e8e7 100644
--- a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/IncludeTest.java
+++ b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/IncludeTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.helper;
import java.io.IOException;
@@ -19,71 +24,112 @@ public void include() throws IOException {
String template = "{{#each dudes}}{{include \"dude\" greeting=\"Hi\"}} {{/each}}";
String partial = "{{greeting}}, {{name}}!";
String expected = "Hi, Yehuda! Hi, Alan! ";
- Hash dudes = $("dudes",
- new Object[]{
- $("name", "Yehuda", "url", "http://yehuda"),
- $("name", "Alan", "url", "http://alan")
- });
+ Hash dudes =
+ $(
+ "dudes",
+ new Object[] {
+ $("name", "Yehuda", "url", "http://yehuda"), $("name", "Alan", "url", "http://alan")
+ });
shouldCompileToWithPartials(template, dudes, $("dude", partial), expected);
}
@Test
public void accessToParentContext() throws IOException {
- String string = "{{#each hobbies}}{{../name}} has hobby {{hobbyname}} and lives in {{../town}} {{/each}}";
- Object hash = $("name", "Dennis", "town", "berlin", "hobbies",
- new Object[]{$("hobbyname", "swimming"), $("hobbyname", "dancing"),
- $("hobbyname", "movies") });
- shouldCompileTo(string, hash, "Dennis has hobby swimming and lives in berlin " +
- "Dennis has hobby dancing and lives in berlin " +
- "Dennis has hobby movies and lives in berlin ");
+ String string =
+ "{{#each hobbies}}{{../name}} has hobby {{hobbyname}} and lives in {{../town}} {{/each}}";
+ Object hash =
+ $(
+ "name",
+ "Dennis",
+ "town",
+ "berlin",
+ "hobbies",
+ new Object[] {
+ $("hobbyname", "swimming"), $("hobbyname", "dancing"), $("hobbyname", "movies")
+ });
+ shouldCompileTo(
+ string,
+ hash,
+ "Dennis has hobby swimming and lives in berlin "
+ + "Dennis has hobby dancing and lives in berlin "
+ + "Dennis has hobby movies and lives in berlin ");
}
@Test
public void accessToParentContextFromPartialUsingInclude() throws IOException {
- String string = "{{#each hobbies}}{{include \"hobby\" parentcontext=.. town=../town}} {{/each}}";
- Object hash = $("name", "Dennis", "town", "berlin", "hobbies",
- new Object[]{$("hobbyname", "swimming"), $("hobbyname", "dancing"),
- $("hobbyname", "movies") });
- Hash partials = $("hobby",
- "{{parentcontext.name}} has hobby {{hobbyname}} and lives in {{town}}");
-
- shouldCompileToWithPartials(string, hash, partials,
- "Dennis has hobby swimming and lives in berlin " +
- "Dennis has hobby dancing and lives in berlin " +
- "Dennis has hobby movies and lives in berlin ");
+ String string =
+ "{{#each hobbies}}{{include \"hobby\" parentcontext=.. town=../town}} {{/each}}";
+ Object hash =
+ $(
+ "name",
+ "Dennis",
+ "town",
+ "berlin",
+ "hobbies",
+ new Object[] {
+ $("hobbyname", "swimming"), $("hobbyname", "dancing"), $("hobbyname", "movies")
+ });
+ Hash partials =
+ $("hobby", "{{parentcontext.name}} has hobby {{hobbyname}} and lives in {{town}}");
+
+ shouldCompileToWithPartials(
+ string,
+ hash,
+ partials,
+ "Dennis has hobby swimming and lives in berlin "
+ + "Dennis has hobby dancing and lives in berlin "
+ + "Dennis has hobby movies and lives in berlin ");
}
@Test
public void accessToParentContextFromPartialMustacheSpec() throws IOException {
String string = "{{#each hobbies}}{{> hobby}} {{/each}}";
- Object hash = $("name", "Dennis", "town", "berlin", "hobbies",
- new Object[]{$("hobbyname", "swimming"), $("hobbyname", "dancing"),
- $("hobbyname", "movies") });
-
- Hash partials = $("hobby",
- "{{name}} has hobby {{hobbyname}} and lives in {{town}}");
-
- shouldCompileToWithPartials(string, hash, partials,
- "Dennis has hobby swimming and lives in berlin " +
- "Dennis has hobby dancing and lives in berlin " +
- "Dennis has hobby movies and lives in berlin ");
+ Object hash =
+ $(
+ "name",
+ "Dennis",
+ "town",
+ "berlin",
+ "hobbies",
+ new Object[] {
+ $("hobbyname", "swimming"), $("hobbyname", "dancing"), $("hobbyname", "movies")
+ });
+
+ Hash partials = $("hobby", "{{name}} has hobby {{hobbyname}} and lives in {{town}}");
+
+ shouldCompileToWithPartials(
+ string,
+ hash,
+ partials,
+ "Dennis has hobby swimming and lives in berlin "
+ + "Dennis has hobby dancing and lives in berlin "
+ + "Dennis has hobby movies and lives in berlin ");
}
@Test
public void explicitAccessToParentContextFromPartialMustacheSpec() throws IOException {
String string = "{{#each hobbies}}{{> hobby}} {{/each}}";
- Object hash = $("name", "Dennis", "town", "berlin", "hobbies",
- new Object[]{$("hobbyname", "swimming"), $("hobbyname", "dancing"),
- $("hobbyname", "movies") });
-
- Hash partials = $("hobby",
- "{{../name}} has hobby {{hobbyname}} and lives in {{../town}}");
-
- shouldCompileToWithPartials(string, hash, partials,
- "Dennis has hobby swimming and lives in berlin " +
- "Dennis has hobby dancing and lives in berlin " +
- "Dennis has hobby movies and lives in berlin ");
+ Object hash =
+ $(
+ "name",
+ "Dennis",
+ "town",
+ "berlin",
+ "hobbies",
+ new Object[] {
+ $("hobbyname", "swimming"), $("hobbyname", "dancing"), $("hobbyname", "movies")
+ });
+
+ Hash partials = $("hobby", "{{../name}} has hobby {{hobbyname}} and lives in {{../town}}");
+
+ shouldCompileToWithPartials(
+ string,
+ hash,
+ partials,
+ "Dennis has hobby swimming and lives in berlin "
+ + "Dennis has hobby dancing and lives in berlin "
+ + "Dennis has hobby movies and lives in berlin ");
}
}
diff --git a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/JodaHelperTest.java b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/JodaHelperTest.java
index 73fcfbb54..5022c13ed 100644
--- a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/JodaHelperTest.java
+++ b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/JodaHelperTest.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2013 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -32,7 +20,6 @@
* Tests for JodaHelper.
*
* @author @mrhanlon https://github.com/mrhanlon
- *
*/
public class JodaHelperTest extends AbstractTest {
@@ -48,8 +35,8 @@ protected Handlebars newHandlebars() {
@Test
public void testPattern() throws IOException {
DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0);
- shouldCompileTo("{{jodaPatternHelper this \"y-MMM-d H:m:s\"}}", dateTime,
- "1995-Jul-4 14:32:12");
+ shouldCompileTo(
+ "{{jodaPatternHelper this \"y-MMM-d H:m:s\"}}", dateTime, "1995-Jul-4 14:32:12");
}
@Test
@@ -67,9 +54,11 @@ public void testBadPattern() throws IOException {
@Test
public void testStyle() throws IOException {
DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0);
- withJava(version -> version <= 8,
+ withJava(
+ version -> version <= 8,
() -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95 2:32 PM"));
- withJava(version -> version >= 9,
+ withJava(
+ version -> version >= 9,
() -> shouldCompileTo("{{jodaStyleHelper this \"SS\"}}", dateTime, "7/4/95, 2:32 PM"));
}
@@ -86,8 +75,11 @@ public void testBadStyle() throws IOException {
@Test
public void testISO() throws IOException {
- DateTime dateTime = new DateTime().withDate(1995, 7, 4).withTime(14, 32, 12, 0)
- .withZoneRetainFields(DateTimeZone.UTC);
+ DateTime dateTime =
+ new DateTime()
+ .withDate(1995, 7, 4)
+ .withTime(14, 32, 12, 0)
+ .withZoneRetainFields(DateTimeZone.UTC);
shouldCompileTo("{{jodaISOHelper this}}", dateTime, "1995-07-04T14:32:12Z");
}
}
diff --git a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/NumberHelperTest.java b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/NumberHelperTest.java
index 818791c86..bc5128ddb 100644
--- a/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/NumberHelperTest.java
+++ b/handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/NumberHelperTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.helper;
import java.io.IOException;
diff --git a/handlebars-jackson2/src/main/java/com/github/jknack/handlebars/Jackson2Helper.java b/handlebars-jackson2/src/main/java/com/github/jknack/handlebars/Jackson2Helper.java
index 7e13950c6..6f82af07c 100644
--- a/handlebars-jackson2/src/main/java/com/github/jknack/handlebars/Jackson2Helper.java
+++ b/handlebars-jackson2/src/main/java/com/github/jknack/handlebars/Jackson2Helper.java
@@ -1,22 +1,12 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
+import static java.util.Objects.requireNonNull;
+
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -28,13 +18,11 @@
import com.fasterxml.jackson.core.io.SegmentedStringWriter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
-import static java.util.Objects.requireNonNull;
/**
* A Jackson 2.x helper.
- *
- * If model is null an empty string is returned.
- *
- *
- * You can change this using the default option:
- *
+ *
+ *
If model is null an empty string is returned.
+ *
+ *
You can change this using the default option:
*
*
* {{json model default="{}"}}
*
*
- *
- * Using a view class:
- *
+ *
Using a view class:
*
*
* {{json model view="foo.MyView"}}
*
- *
- * Using alias for views:
- *
+ *
+ *
Using alias for views:
*
*
* {{json model view="myView"}}
*
*
- *
- * Escape HTML chars:
- *
+ *
Escape HTML chars:
*
*
* {{json model escapeHtml=true}}
*
*
- *
- * Pretty printer:
- *
+ *
Pretty printer:
*
*
* {{json model pretty=true}}
@@ -93,8 +72,8 @@
public class Jackson2Helper implements Helper {
/**
- * Escape HTML chars from JSON content.
- * See http://www.cowtowncoder.com/blog/archives/2012/08/entry_476.html
+ * Escape HTML chars from JSON content. See
+ * http://www.cowtowncoder.com/blog/archives/2012/08/entry_476.html
*
* @author edgar.espina
* @since 1.0.0
@@ -102,12 +81,12 @@ public class Jackson2Helper implements Helper {
@SuppressWarnings("serial")
private static class HtmlEscapes extends CharacterEscapes {
- /**
- * The escape table.
- */
+ /** The escape table. */
private int[] escapeTable;
+
{
- // Start with set of characters known to require escaping (double-quote, backslash etc)
+ // Start with set of characters known to require escaping (double-quote,
+ // backslash etc)
escapeTable = CharacterEscapes.standardAsciiEscapesForJSON();
// and force escaping of a few others:
escapeTable['<'] = CharacterEscapes.ESCAPE_STANDARD;
@@ -125,22 +104,15 @@ public int[] getEscapeCodesForAscii() {
public SerializableString getEscapeSequence(final int ch) {
return null;
}
-
}
- /**
- * A singleton version of {@link Jackson2Helper}.
- */
+ /** A singleton version of {@link Jackson2Helper}. */
public static final Helper INSTANCE = new Jackson2Helper();
- /**
- * The JSON parser.
- */
+ /** The JSON parser. */
private final ObjectMapper mapper;
- /**
- * Class alias registry.
- */
+ /** Class alias registry. */
private final Map> alias = new HashMap>();
/**
@@ -152,16 +124,13 @@ public Jackson2Helper(final ObjectMapper objectMapper) {
mapper = requireNonNull(objectMapper, "The object mapper is required.");
}
- /**
- * Creates a new {@link Jackson2Helper}.
- */
+ /** Creates a new {@link Jackson2Helper}. */
private Jackson2Helper() {
this(new ObjectMapper());
}
@Override
- public Object apply(final Object context, final Options options)
- throws IOException {
+ public Object apply(final Object context, final Options options) throws IOException {
if (context == null) {
return options.hash("default", "");
}
@@ -220,9 +189,9 @@ public Object apply(final Object context, final Options options)
* @param viewClass The view class. Required.
* @return This helper.
*/
- public Jackson2Helper viewAlias(final String alias,
- final Class> viewClass) {
- this.alias.put(requireNonNull(alias, "A view alias is required."),
+ public Jackson2Helper viewAlias(final String alias, final Class> viewClass) {
+ this.alias.put(
+ requireNonNull(alias, "A view alias is required."),
requireNonNull(viewClass, "A view class is required."));
return this;
}
diff --git a/handlebars-jackson2/src/main/java/com/github/jknack/handlebars/JsonNodeValueResolver.java b/handlebars-jackson2/src/main/java/com/github/jknack/handlebars/JsonNodeValueResolver.java
index 255b98da5..47bf43c19 100644
--- a/handlebars-jackson2/src/main/java/com/github/jknack/handlebars/JsonNodeValueResolver.java
+++ b/handlebars-jackson2/src/main/java/com/github/jknack/handlebars/JsonNodeValueResolver.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -48,9 +36,7 @@
*/
public enum JsonNodeValueResolver implements ValueResolver {
- /**
- * The singleton instance.
- */
+ /** The singleton instance. */
INSTANCE;
@Override
@@ -63,7 +49,8 @@ public Object resolve(final Object context, final String name) {
}
value = resolve(((ArrayNode) context).get(Integer.parseInt(name)));
} catch (NumberFormatException ex) {
- // ignore undefined key and move on, see https://github.com/jknack/handlebars.java/pull/280
+ // ignore undefined key and move on, see
+ // https://github.com/jknack/handlebars.java/pull/280
value = null;
}
} else if (context instanceof JsonNode) {
@@ -147,7 +134,7 @@ public int size() {
return node.size();
}
- @SuppressWarnings({"unchecked", "rawtypes" })
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Override
public Set> entrySet() {
Iterator> it = node.fields();
@@ -174,5 +161,4 @@ public Set> propertySet(final Object context) {
}
return Collections.emptySet();
}
-
}
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Blog.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Blog.java
index 14e9ec768..31dfeacb9 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Blog.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Blog.java
@@ -1,19 +1,7 @@
-/**
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
* Copyright (c) 2012 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
*/
package com.github.jknack.handlebars;
@@ -25,8 +13,7 @@
public class Blog {
public static class Views {
- public static class Public {
- }
+ public static class Public {}
}
@JsonView(Views.Public.class)
@@ -41,8 +28,7 @@ public Blog(final String title, final String body) {
this.body = body;
}
- public Blog() {
- }
+ public Blog() {}
public String getTitle() {
return title;
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Comment.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Comment.java
index 8a0b182bd..d763a0c22 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Comment.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Comment.java
@@ -1,19 +1,7 @@
-/**
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
* Copyright (c) 2012 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
*/
package com.github.jknack.handlebars;
@@ -27,8 +15,7 @@ public Comment(final String author, final String comment) {
this.comment = comment;
}
- public Comment() {
- }
+ public Comment() {}
public String getAuthor() {
return author;
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue260.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue260.java
index 610a39086..0f8736716 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue260.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue260.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars;
import java.io.IOException;
@@ -13,7 +18,8 @@ public class Issue260 extends AbstractTest {
@Override
protected Object configureContext(final Object model) {
return Context.newBuilder(model)
- .resolver(MapValueResolver.INSTANCE, JsonNodeValueResolver.INSTANCE).build();
+ .resolver(MapValueResolver.INSTANCE, JsonNodeValueResolver.INSTANCE)
+ .build();
}
@Test
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue412.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue412.java
index 49cf2a96c..5732e3889 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue412.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue412.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars;
import java.io.IOException;
@@ -13,14 +18,14 @@ public class Issue412 extends AbstractTest {
@Override
protected Object configureContext(final Object model) {
return Context.newBuilder(model)
- .resolver(MapValueResolver.INSTANCE, JsonNodeValueResolver.INSTANCE).build();
+ .resolver(MapValueResolver.INSTANCE, JsonNodeValueResolver.INSTANCE)
+ .build();
}
@Test
public void keyShouldWork() throws IOException {
JsonNode tree = new ObjectMapper().readTree("{\"firstName\":\"John\", \"lastName\":\"Smith\"}");
- shouldCompileTo("{{#each this}}{{@key}}: {{this}} {{/each}}", tree,
- "firstName: John lastName: Smith ");
+ shouldCompileTo(
+ "{{#each this}}{{@key}}: {{this}} {{/each}}", tree, "firstName: John lastName: Smith ");
}
-
}
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue598.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue598.java
index 02afa274d..e47364a4a 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue598.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Issue598.java
@@ -1,18 +1,25 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars;
+import java.io.IOException;
+
+import org.junit.Test;
+
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.jknack.handlebars.context.MapValueResolver;
-import org.junit.Test;
-
-import java.io.IOException;
public class Issue598 extends AbstractTest {
@Override
protected Object configureContext(final Object model) {
return Context.newBuilder(model)
- .resolver(MapValueResolver.INSTANCE, JsonNodeValueResolver.INSTANCE).build();
+ .resolver(MapValueResolver.INSTANCE, JsonNodeValueResolver.INSTANCE)
+ .build();
}
@Test
@@ -20,5 +27,4 @@ public void shouldExtendJsonArrayWithLenghtProperty() throws IOException {
JsonNode tree = new ObjectMapper().readTree("[1, 2, 3]");
shouldCompileTo("{{this.length}}", tree, "3");
}
-
}
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java
index f6cbf5568..a5917001d 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/Jackson2HelperTest.java
@@ -1,15 +1,7 @@
-/**
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
* Copyright (c) 2012 Edgar Espina
- * This file is part of Handlebars.java.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
*/
package com.github.jknack.handlebars;
@@ -41,8 +33,10 @@ public void toJSON() throws IOException {
Template template = handlebars.compileInline("{{@json this}}");
- assertThat(template.apply(new Blog("First Post", "...")), equalsToStringIgnoringWindowsNewLine(
- "{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}"));
+ assertThat(
+ template.apply(new Blog("First Post", "...")),
+ equalsToStringIgnoringWindowsNewLine(
+ "{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}"));
}
@Test
@@ -52,12 +46,14 @@ public void toPrettyJSON() throws IOException {
Template template = handlebars.compileInline("{{@json this pretty=true}}");
- assertThat(template.apply(new Blog("First Post", "...")),
- equalsToStringIgnoringWindowsNewLine("{\n" +
- " \"title\" : \"First Post\",\n" +
- " \"body\" : \"...\",\n" +
- " \"comments\" : [ ]\n" +
- "}"));
+ assertThat(
+ template.apply(new Blog("First Post", "...")),
+ equalsToStringIgnoringWindowsNewLine(
+ "{\n"
+ + " \"title\" : \"First Post\",\n"
+ + " \"body\" : \"...\",\n"
+ + " \"comments\" : [ ]\n"
+ + "}"));
}
@Test
@@ -67,11 +63,11 @@ public void toJSONViewInclusive() throws IOException {
handlebars.registerHelper("@json", Jackson2Helper.INSTANCE);
Template template =
- handlebars
- .compileInline(
- "{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
+ handlebars.compileInline(
+ "{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
- assertThat(template.apply(new Blog("First Post", "...")),
+ assertThat(
+ template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine(
"{\"title\":\"First Post\",\"body\":\"...\",\"comments\":[]}"));
}
@@ -86,11 +82,11 @@ public void toJSONViewExclusive() throws IOException {
handlebars.registerHelper("@json", new Jackson2Helper(mapper));
Template template =
- handlebars
- .compileInline(
- "{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
+ handlebars.compileInline(
+ "{{@json this view=\"com.github.jknack.handlebars.Blog$Views$Public\"}}");
- assertThat(template.apply(new Blog("First Post", "...")),
+ assertThat(
+ template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}
@@ -101,14 +97,13 @@ public void toJSONAliasViewExclusive() throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
- handlebars.registerHelper("@json",
- new Jackson2Helper(mapper).viewAlias("myView", Public.class));
+ handlebars.registerHelper(
+ "@json", new Jackson2Helper(mapper).viewAlias("myView", Public.class));
- Template template =
- handlebars
- .compileInline("{{@json this view=\"myView\"}}");
+ Template template = handlebars.compileInline("{{@json this view=\"myView\"}}");
- assertThat(template.apply(new Blog("First Post", "...")),
+ assertThat(
+ template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}
@@ -121,11 +116,10 @@ public void jsonViewNotFound() throws IOException {
handlebars.registerHelper("@json", new Jackson2Helper(mapper));
- Template template =
- handlebars
- .compileInline("{{@json this view=\"missing.ViewClass\"}}");
+ Template template = handlebars.compileInline("{{@json this view=\"missing.ViewClass\"}}");
- assertThat(template.apply(new Blog("First Post", "...")),
+ assertThat(
+ template.apply(new Blog("First Post", "...")),
equalsToStringIgnoringWindowsNewLine("{\"title\":\"First Post\"}"));
}
@@ -137,12 +131,15 @@ public void escapeHtml() throws IOException {
Map model = new HashMap();
model.put("script", "");
- assertThat(handlebars
- .compileInline("{{@json this}}").apply(model), equalsToStringIgnoringWindowsNewLine(
- "{\"script\":\"\"}"));
+ assertThat(
+ handlebars.compileInline("{{@json this}}").apply(model),
+ equalsToStringIgnoringWindowsNewLine(
+ "{\"script\":\"\"}"));
- assertThat(handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model),
+ assertThat(
+ handlebars.compileInline("{{@json this escapeHTML=true}}").apply(model),
equalsToStringIgnoringWindowsNewLine(
- "{\"script\":\"\\u003Cscript text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}"));
+ "{\"script\":\"\\u003Cscript"
+ + " text=\\\"text/javascript\\\"\\u003E\\u003C/script\\u003E\"}"));
}
}
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/JsonNodeValueResolverTest.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/JsonNodeValueResolverTest.java
index f7f561ff9..fc78a3e4c 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/JsonNodeValueResolverTest.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/JsonNodeValueResolverTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars;
import static org.junit.Assert.assertEquals;
@@ -41,8 +46,10 @@ public void resolveValueNode() throws IOException {
root.put("double", 3.14d);
root.put("bool", true);
- assertEquals("abc 678 6789 7.13 3.14 true",
- handlebars.compileInline("{{string}} {{int}} {{long}} {{float}} {{double}} {{bool}}")
+ assertEquals(
+ "abc 678 6789 7.13 3.14 true",
+ handlebars
+ .compileInline("{{string}} {{int}} {{long}} {{float}} {{double}} {{bool}}")
.apply(context(root)));
}
@@ -54,7 +61,7 @@ public void nullMustBeResolvedToUnresolved() {
@Test
public void resolveBinaryNode() {
String name = "binary";
- byte[] result = new byte[]{1 };
+ byte[] result = new byte[] {1};
JsonNode node = mock(JsonNode.class);
BinaryNode value = BinaryNode.valueOf(result);
@@ -148,8 +155,8 @@ public void propertySet() throws IOException {
@Test
public void emptyPropertySet() throws IOException {
- Set> propertySet = JsonNodeValueResolver.INSTANCE
- .propertySet(new Object());
+ Set> propertySet =
+ JsonNodeValueResolver.INSTANCE.propertySet(new Object());
assertNotNull(propertySet);
assertEquals(0, propertySet.size());
}
@@ -157,12 +164,13 @@ public void emptyPropertySet() throws IOException {
@Test
public void resolveObjectNode() throws IOException {
Handlebars handlebars = new Handlebars();
- Object item = new Object() {
- @SuppressWarnings("unused")
- public String getKey() {
- return "pojo";
- }
- };
+ Object item =
+ new Object() {
+ @SuppressWarnings("unused")
+ public String getKey() {
+ return "pojo";
+ }
+ };
Map root = new HashMap();
root.put("pojo", item);
@@ -175,31 +183,33 @@ public void resolveSimpleArrayNode() throws IOException {
Handlebars handlebars = new Handlebars();
Map root = new HashMap();
- root.put("array", new Object[]{1, 2, 3 });
+ root.put("array", new Object[] {1, 2, 3});
- assertEquals("123",
+ assertEquals(
+ "123",
handlebars.compileInline("{{array.[0]}}{{array.[1]}}{{array.[2]}}").apply(context(root)));
- assertEquals("123",
- handlebars.compileInline("{{#array}}{{this}}{{/array}}").apply(context(root)));
+ assertEquals(
+ "123", handlebars.compileInline("{{#array}}{{this}}{{/array}}").apply(context(root)));
}
@Test
public void resolveArrayNode() throws IOException {
Handlebars handlebars = new Handlebars();
- Object item = new Object() {
- @SuppressWarnings("unused")
- public String getKey() {
- return "pojo";
- }
- };
+ Object item =
+ new Object() {
+ @SuppressWarnings("unused")
+ public String getKey() {
+ return "pojo";
+ }
+ };
Map root = new HashMap();
- root.put("array", new Object[]{item });
+ root.put("array", new Object[] {item});
assertEquals("pojo", handlebars.compileInline("{{array.[0].key}}").apply(context(root)));
- assertEquals("pojo",
- handlebars.compileInline("{{#array}}{{key}}{{/array}}").apply(context(root)));
+ assertEquals(
+ "pojo", handlebars.compileInline("{{#array}}{{key}}{{/array}}").apply(context(root)));
}
public static JsonNode node(final Object object) throws IOException {
@@ -210,6 +220,7 @@ public static JsonNode node(final Object object) throws IOException {
public static Context context(final Object object) throws IOException {
return Context.newBuilder(node(object))
- .resolver(MapValueResolver.INSTANCE, JsonNodeValueResolver.INSTANCE).build();
+ .resolver(MapValueResolver.INSTANCE, JsonNodeValueResolver.INSTANCE)
+ .build();
}
}
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/i280/Issue280.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/i280/Issue280.java
index c4ea02bfa..c28f581d7 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/i280/Issue280.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/i280/Issue280.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.i280;
import org.junit.Test;
@@ -20,5 +25,4 @@ public void errorWhileLookingParentContextUsingJsonNodeValueResolver() throws Ex
JsonNode node = new ObjectMapper().readTree("[{\"key\": \"value\"}]");
shouldCompileTo("{{#each this}}{{undefinedKey}}{{/each}}", node, "");
}
-
}
diff --git a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/i368/Issue368.java b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/i368/Issue368.java
index 774fbac11..000f1499d 100644
--- a/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/i368/Issue368.java
+++ b/handlebars-jackson2/src/test/java/com/github/jknack/handlebars/i368/Issue368.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.i368;
import java.io.IOException;
@@ -16,16 +21,22 @@ public class Issue368 extends AbstractTest {
@Override
protected Object configureContext(final Object context) {
return Context.newBuilder(context)
- .resolver(JsonNodeValueResolver.INSTANCE, MapValueResolver.INSTANCE).build();
+ .resolver(JsonNodeValueResolver.INSTANCE, MapValueResolver.INSTANCE)
+ .build();
}
@Test
public void jsonItShouldHaveIndexVar() throws IOException {
- String value = "{ \"names\": [ { \"id\": \"a\" }, { \"id\": \"b\" }, { \"id\": \"c\" }, { \"id\": \"d\" } ] }";
+ String value =
+ "{ \"names\": [ { \"id\": \"a\" }, { \"id\": \"b\" }, { \"id\": \"c\" }, { \"id\": \"d\" }"
+ + " ] }";
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(value);
- shouldCompileTo("{{#each names}}index={{@index}}, id={{id}}, {{/each}}", jsonNode, "index=0, id=a, index=1, id=b, index=2, id=c, index=3, id=d, ");
+ shouldCompileTo(
+ "{{#each names}}index={{@index}}, id={{id}}, {{/each}}",
+ jsonNode,
+ "index=0, id=a, index=1, id=b, index=2, id=c, index=3, id=d, ");
}
}
diff --git a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/HandlebarsPlugin.java b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/HandlebarsPlugin.java
index 5f007c7f7..5b2ff4e11 100644
--- a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/HandlebarsPlugin.java
+++ b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/HandlebarsPlugin.java
@@ -1,33 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * This copy of Woodstox XML processor is licensed under the
- * Apache (Software) License, version 2.0 ("the License").
- * See the License for details about distribution rights, and the
- * specific rights regarding derivate works.
- *
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/
- *
- * A copy is also included in the downloadable source code package
- * containing Woodstox, in file "ASL2.0", under the same directory
- * as this file.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.maven;
@@ -49,9 +23,7 @@
*/
public abstract class HandlebarsPlugin extends AbstractMojo {
- /**
- * The maven project.
- */
+ /** The maven project. */
@Parameter(defaultValue = "${project}", required = true, readonly = true)
protected MavenProject project;
diff --git a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/I18nJsPlugin.java b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/I18nJsPlugin.java
index c3a7a1c93..1bd99bd0e 100644
--- a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/I18nJsPlugin.java
+++ b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/I18nJsPlugin.java
@@ -1,33 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * This copy of Woodstox XML processor is licensed under the
- * Apache (Software) License, version 2.0 ("the License").
- * See the License for details about distribution rights, and the
- * specific rights regarding derivate works.
- *
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/
- *
- * A copy is also included in the downloadable source code package
- * containing Woodstox, in file "ASL2.0", under the same directory
- * as this file.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.maven;
@@ -57,7 +31,6 @@
import com.github.jknack.handlebars.TagType;
import com.github.jknack.handlebars.Template;
import com.github.jknack.handlebars.helper.I18nHelper;
-
import edu.emory.mathcs.backport.java.util.Collections;
/**
@@ -71,37 +44,28 @@ public class I18nJsPlugin extends HandlebarsPlugin {
/**
* The resource bundle name. Example:
+ *
*
- *
messages
- *
com.github.app.messages
+ *
messages
+ *
com.github.app.messages
*
+ *
* Default is: messages.
*/
- @Parameter
- private String bundle = "messages";
+ @Parameter private String bundle = "messages";
- /**
- * The output directory. JavaScript files will be save here.
- */
- @Parameter(
- defaultValue = "${project.build.directory}/${project.build.finalName}/js")
+ /** The output directory. JavaScript files will be save here. */
+ @Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}/js")
private String output;
- /**
- * True if all the messages bundle should be merge into a single file. Default: false.
- */
+ /** True if all the messages bundle should be merge into a single file. Default: false. */
@Parameter(defaultValue = "false")
private boolean merge;
- /**
- * True, if the output should be in the AMD format. Default is anonymous function.
- */
- @Parameter
- private boolean amd;
+ /** True, if the output should be in the AMD format. Default is anonymous function. */
+ @Parameter private boolean amd;
- /**
- * Character encoding. Default is: UTF-8.
- */
+ /** Character encoding. Default is: UTF-8. */
@Parameter(defaultValue = "UTF-8")
private String encoding = "UTF-8";
@@ -151,16 +115,17 @@ protected void doExecute() throws Exception {
// set bundle name
hash.put("bundle", this.bundle);
- Options options = new Options.Builder(handlebars, I18nHelper.i18nJs.name(), TagType.VAR,
- context, Template.EMPTY)
- .setHash(hash)
- .build();
+ Options options =
+ new Options.Builder(
+ handlebars, I18nHelper.i18nJs.name(), TagType.VAR, context, Template.EMPTY)
+ .setHash(hash)
+ .build();
// convert to JS
buffer.append(I18nHelper.i18nJs.apply(locale, options));
if (!merge) {
- FileUtils.fileWrite(new File(output, bundleName + ".js"), encoding,
- wrap(bundleName, buffer, amd));
+ FileUtils.fileWrite(
+ new File(output, bundleName + ".js"), encoding, wrap(bundleName, buffer, amd));
buffer.setLength(0);
getLog().debug(" => " + bundleName + ".js");
} else {
@@ -200,18 +165,20 @@ private List bundles(final String bundle, final URL[] classpath) throws Ex
Set bundles = new LinkedHashSet();
for (URL url : classpath) {
File dir = new File(url.toURI());
- bundles.addAll(FileUtils.getFiles(dir, bundle.replace(".", FileUtils.FS) + "*.properties",
- null));
+ bundles.addAll(
+ FileUtils.getFiles(dir, bundle.replace(".", FileUtils.FS) + "*.properties", null));
}
return new ArrayList(bundles);
}
/**
* Set the resource bundle name. Example:
+ *
*
- *
messages
- *
com.github.app.messages
+ *
messages
+ *
com.github.app.messages
*
+ *
* Default is: messages.
*
* @param bundle The bundle name.
diff --git a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java
index 42eac9287..b6f8697e5 100644
--- a/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java
+++ b/handlebars-maven-plugin/src/main/java/com/github/jknack/handlebars/maven/PrecompilePlugin.java
@@ -1,33 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * This copy of Woodstox XML processor is licensed under the
- * Apache (Software) License, version 2.0 ("the License").
- * See the License for details about distribution rights, and the
- * specific rights regarding derivate works.
- *
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/
- *
- * A copy is also included in the downloadable source code package
- * containing Woodstox, in file "ASL2.0", under the same directory
- * as this file.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.maven;
@@ -86,59 +60,38 @@
@Mojo(name = "precompile", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true)
public class PrecompilePlugin extends HandlebarsPlugin {
- /**
- * A prefix location, default is ${basedir}/src/main/webapp.
- */
+ /** A prefix location, default is ${basedir}/src/main/webapp. */
@Parameter(defaultValue = "${basedir}/src/main/webapp")
private String prefix;
- /**
- * The file extension, default is: .hbs.
- */
+ /** The file extension, default is: .hbs. */
@Parameter(defaultValue = ".hbs")
private String suffix = ".hbs";
- /**
- * The template files to precompile.
- */
- @Parameter
- private List templates;
+ /** The template files to precompile. */
+ @Parameter private List templates;
- /**
- * The output file.
- */
+ /** The output file. */
@Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}/js/helpers.js")
private String output;
- /**
- * The handlebars js file.
- */
+ /** The handlebars js file. */
@Parameter(defaultValue = "/handlebars-v4.7.7.js")
private String handlebarsJsFile;
/**
* True, if the handlebars.runtime.js file need to be included in the output. Default is: false.
*/
- @Parameter
- private String runtime;
+ @Parameter private String runtime;
- /**
- * Minimize the output. Default is: false.
- */
- @Parameter
- private boolean minimize;
+ /** Minimize the output. Default is: false. */
+ @Parameter private boolean minimize;
- /**
- * True, if the output should be in the AMD format. Default is false.
- */
- @Parameter
- private boolean amd;
+ /** True, if the output should be in the AMD format. Default is false. */
+ @Parameter private boolean amd;
- /**
- * The encoding char set. Default is: UTF-8.
- */
- @Parameter
- private String encoding = "UTF-8";
+ /** The encoding char set. Default is: UTF-8. */
+ @Parameter private String encoding = "UTF-8";
@Override
protected void doExecute() throws Exception {
@@ -171,9 +124,7 @@ protected void doExecute() throws Exception {
i18n(handlebars);
- /**
- * Silent any missing helper.
- */
+ /** Silent any missing helper. */
silentHelpers(handlebars);
File parent = output.getParentFile();
@@ -225,12 +176,14 @@ protected void doExecute() throws Exception {
Template template = handlebars.compileInline("{{precompile \"" + templateName + "\"}}");
Map hash = new HashMap();
hash.put("wrapper", amd ? "amd" : "none");
- Options opts = new Options
- .Builder(handlebars, PrecompileHelper.NAME, TagType.VAR, nullContext, template)
+ Options opts =
+ new Options.Builder(
+ handlebars, PrecompileHelper.NAME, TagType.VAR, nullContext, template)
.setHash(hash)
.build();
- writer.append(PrecompileHelper.INSTANCE.apply(templateName, opts).toString())
+ writer
+ .append(PrecompileHelper.INSTANCE.apply(templateName, opts).toString())
.append("\n\n");
}
// extras
@@ -275,17 +228,19 @@ private void silentHelpers(final Handlebars handlebars) {
* @param handlebars The handlebars object.
*/
private void i18n(final Handlebars handlebars) {
- handlebars.registerHelper(I18nHelper.i18n.name(), new Helper() {
- @Override
- public Object apply(final String context, final Options options) throws IOException {
- return null;
- }
+ handlebars.registerHelper(
+ I18nHelper.i18n.name(),
+ new Helper() {
+ @Override
+ public Object apply(final String context, final Options options) throws IOException {
+ return null;
+ }
- @Override
- public String toString() {
- return I18nHelper.i18n.name() + "-maven-plugin";
- }
- });
+ @Override
+ public String toString() {
+ return I18nHelper.i18n.name() + "-maven-plugin";
+ }
+ });
}
/**
@@ -295,36 +250,46 @@ public String toString() {
* @param extras Append output here.
* @param classpath The project classpath.
*/
- private void i18nJs(final Handlebars handlebars, final List extras,
- final URL[] classpath) {
- handlebars.registerHelper(I18nHelper.i18nJs.name(), new Helper() {
- @Override
- public Object apply(final String context, final Options options) throws IOException {
- StringBuilder output = new StringBuilder();
- output.append("// i18nJs output:\n");
- output.append("// register an empty i18nJs helper:\n");
- output.append(registerHelper(I18nHelper.i18nJs.name(),
- "I18n.locale = arguments[0] || \"" + Locale.getDefault() + "\";\n"
- + "return '';", "arguments"));
- output.append("// redirect i18n helper to i18n.js:\n");
- output.append(registerHelper(I18nHelper.i18n.name(), "var key = arguments[0],\n"
- + " i18nOpts = {},\n"
- + " len = arguments.length - 1,"
- + " options = arguments[len];\n"
- + "for(var i = 1; i < len; i++) {\n"
- + " i18nOpts['arg' + (i - 1)] = arguments[i];\n"
- + "}\n"
- + "i18nOpts.locale = options.hash.locale;\n"
- + "return I18n.t(key, i18nOpts);"));
- extras.add(output);
- return null;
- }
+ private void i18nJs(
+ final Handlebars handlebars, final List extras, final URL[] classpath) {
+ handlebars.registerHelper(
+ I18nHelper.i18nJs.name(),
+ new Helper() {
+ @Override
+ public Object apply(final String context, final Options options) throws IOException {
+ StringBuilder output = new StringBuilder();
+ output.append("// i18nJs output:\n");
+ output.append("// register an empty i18nJs helper:\n");
+ output.append(
+ registerHelper(
+ I18nHelper.i18nJs.name(),
+ "I18n.locale = arguments[0] || \""
+ + Locale.getDefault()
+ + "\";\n"
+ + "return '';",
+ "arguments"));
+ output.append("// redirect i18n helper to i18n.js:\n");
+ output.append(
+ registerHelper(
+ I18nHelper.i18n.name(),
+ "var key = arguments[0],\n"
+ + " i18nOpts = {},\n"
+ + " len = arguments.length - 1,"
+ + " options = arguments[len];\n"
+ + "for(var i = 1; i < len; i++) {\n"
+ + " i18nOpts['arg' + (i - 1)] = arguments[i];\n"
+ + "}\n"
+ + "i18nOpts.locale = options.hash.locale;\n"
+ + "return I18n.t(key, i18nOpts);"));
+ extras.add(output);
+ return null;
+ }
- @Override
- public String toString() {
- return I18nHelper.i18nJs.name() + "-maven-plugin";
- }
- });
+ @Override
+ public String toString() {
+ return I18nHelper.i18nJs.name() + "-maven-plugin";
+ }
+ });
}
/**
@@ -336,8 +301,9 @@ public String toString() {
* @return JS code.
*/
private CharSequence registerHelper(final String name, final String body, final String... args) {
- return String.format("Handlebars.registerHelper('%s', function (%s) {\n%s\n});\n\n", name,
- join(args, ", "), body);
+ return String.format(
+ "Handlebars.registerHelper('%s', function (%s) {\n%s\n});\n\n",
+ name, join(args, ", "), body);
}
/**
@@ -359,8 +325,11 @@ private void minimize(final File output) throws IOException, MojoFailureExceptio
compiler.disableThreads();
compiler.initOptions(options);
- Result result = compiler.compile(Collections. emptyList(),
- Arrays.asList(SourceFile.fromFile(output.getAbsolutePath())), options);
+ Result result =
+ compiler.compile(
+ Collections.emptyList(),
+ Arrays.asList(SourceFile.fromFile(output.getAbsolutePath())),
+ options);
if (result.success) {
FileUtils.fileWrite(output, compiler.toSource());
} else {
@@ -412,7 +381,6 @@ public void setSuffix(final String suffix) {
}
/**
- *
* @param template the template filename
*/
public void addTemplate(final String template) {
@@ -424,19 +392,17 @@ public void addTemplate(final String template) {
/**
* Set the handlebars.js location used it to compile/precompile template to JavaScript.
- *
- * Using handlebars.js 2.x:
- *
+ *
+ *
Using handlebars.js 2.x:
+ *
*
- * Handlebars handlebars = new Handlebars()
- * .handlebarsJsFile("handlebars-v2.0.0.js");
+ * Handlebars handlebars = new Handlebars().handlebarsJsFile("handlebars-v2.0.0.js");
*
- *
- * Using handlebars.js 1.x:
- *
+ *
+ *
Using handlebars.js 1.x:
+ *
*
- * Handlebars handlebars = new Handlebars()
- * .handlebarsJsFile("handlebars-v1.3.0.js");
+ * Handlebars handlebars = new Handlebars().handlebarsJsFile("handlebars-v1.3.0.js");
*
*
* Default handlebars.js is handlebars-v4.0.4.js.
@@ -446,5 +412,4 @@ public void addTemplate(final String template) {
public void setHandlebarsJsFile(final String handlebarsJsFile) {
this.handlebarsJsFile = handlebarsJsFile;
}
-
}
diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java
index 2aafbea4d..0dfc12420 100644
--- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java
+++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/I18nJsPluginTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.maven;
import static org.junit.Assert.assertEquals;
@@ -28,10 +33,10 @@ public void i18nJsNoMerge() throws Exception {
plugin.execute();
- assertEquals(tokens("src/test/resources/messages.expected.js"),
- tokens("target/messages.js"));
+ assertEquals(tokens("src/test/resources/messages.expected.js"), tokens("target/messages.js"));
- assertEquals(tokens("src/test/resources/messages_es_AR.expected.js"),
+ assertEquals(
+ tokens("src/test/resources/messages_es_AR.expected.js"),
tokens("target/messages_es_AR.js"));
FileUtils.copyFile(new File("target/messages.js"), new File("target/messages-tests.js"));
@@ -58,10 +63,11 @@ public void i18nJsNoMergeAmd() throws Exception {
plugin.execute();
- assertEquals(tokens("src/test/resources/messages-amd.expected.js"),
- tokens("target/messages.js"));
+ assertEquals(
+ tokens("src/test/resources/messages-amd.expected.js"), tokens("target/messages.js"));
- assertEquals(tokens("src/test/resources/messages_es_AR-amd.expected.js"),
+ assertEquals(
+ tokens("src/test/resources/messages_es_AR-amd.expected.js"),
tokens("target/messages_es_AR.js"));
}
@@ -74,8 +80,7 @@ public void i18nJsWithMerge() throws Exception {
plugin.execute();
- assertEquals(tokens("src/test/resources/messages-merged.js"),
- tokens("target/messages.js"));
+ assertEquals(tokens("src/test/resources/messages-merged.js"), tokens("target/messages.js"));
}
@Test
@@ -88,8 +93,7 @@ public void i18nJsWithMergeAmd() throws Exception {
plugin.execute();
- assertEquals(tokens("src/test/resources/messages-merged-amd.js"),
- tokens("target/messages.js"));
+ assertEquals(tokens("src/test/resources/messages-merged-amd.js"), tokens("target/messages.js"));
}
private MavenProject newProject(final String... classpath)
@@ -99,25 +103,19 @@ private MavenProject newProject(final String... classpath)
return project;
}
- /**
- * Matches on tokens and avoid errors between Java 6.x and Java 7.x.
- */
+ /** Matches on tokens and avoid errors between Java 6.x and Java 7.x. */
private Set tokens(final String filename) throws IOException {
- String content = FileUtils.fileRead(filename)
- .replace("\r", "")
- .replace("\t", " ");
+ String content = FileUtils.fileRead(filename).replace("\r", "").replace("\t", " ");
return Sets.newLinkedHashSet(Splitter.on(Pattern.compile("\\s|,")).split(content));
}
private void equalsToIgnoreBlanks(String expected, String found) throws IOException {
- assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
+ assertEquals(
+ replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
replaceWhiteCharsWithSpace(FileUtils.fileRead(found)));
}
private String replaceWhiteCharsWithSpace(String content) {
- return content
- .replace("\r", "")
- .replace("\t", " ")
- .trim();
+ return content.replace("\r", "").replace("\t", " ").trim();
}
}
diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java
index 59466b859..16a6e59aa 100644
--- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java
+++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue230.java
@@ -1,11 +1,14 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.maven;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.io.IOException;
-
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
@@ -24,13 +27,15 @@ public void issue230() throws Exception {
plugin.execute();
- assertEquals("(function() {\n" +
- " /* English (United States) */\n" +
- " I18n.translations = I18n.translations || {};\n" +
- " I18n.translations['en_US'] = {\n" +
- " \"pagination_top_of_page\": \"Inicio de la pagina\"\n" +
- " };\n" +
- "})();", replaceWhiteCharsWithSpace(FileUtils.fileRead("target/i230.js")));
+ assertEquals(
+ "(function() {\n"
+ + " /* English (United States) */\n"
+ + " I18n.translations = I18n.translations || {};\n"
+ + " I18n.translations['en_US'] = {\n"
+ + " \"pagination_top_of_page\": \"Inicio de la pagina\"\n"
+ + " };\n"
+ + "})();",
+ replaceWhiteCharsWithSpace(FileUtils.fileRead("target/i230.js")));
}
private MavenProject newProject(final String... classpath)
@@ -41,9 +46,6 @@ private MavenProject newProject(final String... classpath)
}
private String replaceWhiteCharsWithSpace(String content) {
- return content
- .replace("\r", "")
- .replace("\t", " ")
- .trim();
+ return content.replace("\r", "").replace("\t", " ").trim();
}
}
diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java
index 3c3bf5f5b..ce53ed967 100644
--- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java
+++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.maven;
import static org.junit.Assert.assertEquals;
@@ -33,15 +38,13 @@ public void withAmdOutput() throws Exception {
}
private void equalsToIgnoreBlanks(String expected, String found) throws IOException {
- assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
+ assertEquals(
+ replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
replaceWhiteCharsWithSpace(FileUtils.fileRead(found)));
}
private String replaceWhiteCharsWithSpace(String content) {
- return content.trim()
- .replace("\\r\\n", "\\n")
- .replace("\r", "")
- .replace("\t", " ");
+ return content.trim().replace("\\r\\n", "\\n").replace("\r", "").replace("\t", " ");
}
private MavenProject newProject(final String... classpath)
diff --git a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java
index f99091f37..ad83630a6 100644
--- a/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java
+++ b/handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.maven;
import static org.junit.Assert.assertEquals;
@@ -8,7 +13,6 @@
import java.io.File;
import java.io.IOException;
-import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -35,16 +39,13 @@ public void i18nJs() throws Exception {
}
private void equalsToIgnoreBlanks(String expected, String found) throws IOException {
- assertEquals(replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
+ assertEquals(
+ replaceWhiteCharsWithSpace(FileUtils.fileRead(expected)),
replaceWhiteCharsWithSpace(FileUtils.fileRead(found)));
}
private String replaceWhiteCharsWithSpace(String content) {
- return content
- .replace("\\r\\n", "\\n")
- .replace("\r", "")
- .replace("\t", " ")
- .trim();
+ return content.replace("\\r\\n", "\\n").replace("\r", "").replace("\t", " ").trim();
}
@Test
@@ -126,8 +127,8 @@ public void mustFailOnMissingFile() throws Exception {
@Test(expected = MojoFailureException.class)
public void mustFailOnUnExpectedException() throws Exception {
MavenProject project = mock(MavenProject.class);
- when(project.getRuntimeClasspathElements()).thenThrow(
- new DependencyResolutionRequiredException(null));
+ when(project.getRuntimeClasspathElements())
+ .thenThrow(new DependencyResolutionRequiredException(null));
PrecompilePlugin plugin = new PrecompilePlugin();
plugin.setPrefix("src/test/resources/no templates");
@@ -160,9 +161,10 @@ public void fileWithRuntimeMustBeLargerThanNormalFiles() throws Exception {
withRT.execute();
- assertTrue("File with runtime must be larger",
- FileUtils.fileRead("target/without-rt-helpers.js").length() <
- FileUtils.fileRead("target/with-rt-helpers.js").length());
+ assertTrue(
+ "File with runtime must be larger",
+ FileUtils.fileRead("target/without-rt-helpers.js").length()
+ < FileUtils.fileRead("target/with-rt-helpers.js").length());
}
@Test
@@ -185,9 +187,10 @@ public void normalFileShouleBeLargerThanMinimizedFiles() throws Exception {
withRT.setHandlebarsJsFile("/handlebars-v4.7.7.js");
withRT.execute();
- assertTrue("Normal file must be larger than minimized",
- FileUtils.fileRead("target/helpers-normal.js").length() >
- FileUtils.fileRead("target/helpers.min.js").length());
+ assertTrue(
+ "Normal file must be larger than minimized",
+ FileUtils.fileRead("target/helpers-normal.js").length()
+ > FileUtils.fileRead("target/helpers.min.js").length());
}
@Test
diff --git a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsView.java b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsView.java
index 0ff8c34d2..c23bed712 100644
--- a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsView.java
+++ b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsView.java
@@ -1,22 +1,12 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.springmvc;
+import static java.util.Objects.requireNonNull;
+
import java.io.IOException;
import java.util.Locale;
import java.util.Map;
@@ -24,7 +14,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import static java.util.Objects.requireNonNull;
import org.springframework.web.servlet.view.AbstractTemplateView;
import com.github.jknack.handlebars.Context;
@@ -39,26 +28,20 @@
*/
public class HandlebarsView extends AbstractTemplateView {
- /**
- * The compiled template.
- */
+ /** The compiled template. */
protected Template template;
- /**
- * The value's resolvers.
- */
+ /** The value's resolvers. */
protected ValueResolver[] valueResolvers;
- /**
- * Merge model into the view. {@inheritDoc}
- */
+ /** Merge model into the view. {@inheritDoc} */
@Override
- protected void renderMergedTemplateModel(final Map model,
- final HttpServletRequest request, final HttpServletResponse response)
+ protected void renderMergedTemplateModel(
+ final Map model,
+ final HttpServletRequest request,
+ final HttpServletResponse response)
throws IOException {
- Context context = Context.newBuilder(model)
- .resolver(valueResolvers)
- .build();
+ Context context = Context.newBuilder(model).resolver(valueResolvers).build();
try {
template.apply(context, response.getWriter());
} finally {
@@ -93,8 +76,8 @@ public void setTemplate(final Template template) {
* @param valueResolvers The value resolvers. Required.
*/
public void setValueResolver(final ValueResolver... valueResolvers) {
- this.valueResolvers = requireNonNull(valueResolvers,
- "At least one value-resolver must be present.");
+ this.valueResolvers =
+ requireNonNull(valueResolvers, "At least one value-resolver must be present.");
}
@Override
diff --git a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java
index 9a8998db1..90cb153f1 100644
--- a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java
+++ b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolver.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.springmvc;
@@ -69,55 +57,42 @@
public class HandlebarsViewResolver extends AbstractTemplateViewResolver
implements InitializingBean, HelperRegistry {
- /**
- * The default content type.
- */
+ /** The default content type. */
public static final String DEFAULT_CONTENT_TYPE = "text/html;charset=UTF-8";
- /**
- * The handlebars object.
- */
+ /** The handlebars object. */
private Handlebars handlebars;
- /**
- * The value's resolvers.
- */
+ /** The value's resolvers. */
private List valueResolvers = new ArrayList<>(defaultValueResolvers());
- /**
- * Fail on missing file. Default is: true.
- */
+ /** Fail on missing file. Default is: true. */
private boolean failOnMissingFile = true;
- /**
- * The helper registry.
- */
+ /** The helper registry. */
private HelperRegistry registry = new DefaultHelperRegistry();
/** True, if the message helper (based on {@link MessageSource}) should be registered. */
private boolean registerMessageHelper = true;
/**
- * If true, the i18n helpers will use a {@link MessageSource} instead of a plain
- * {@link ResourceBundle} .
+ * If true, the i18n helpers will use a {@link MessageSource} instead of a plain {@link
+ * ResourceBundle} .
*/
private boolean bindI18nToMessageSource;
/**
* If true, templates will be deleted once applied. Useful, in some advanced template inheritance
- * use cases. Used by {{#block}} helper. Default is: false.
- * At any time you can override the default setup with:
+ * use cases. Used by {{#block}} helper. Default is: false. At any time you can
+ * override the default setup with:
*
*
* {{#block "footer" delete-after-merge=true}}
*
- *
*/
private boolean deletePartialAfterMerge;
- /**
- * Set variable formatters.
- */
+ /** Set variable formatters. */
private Formatter[] formatters;
/** Location of the handlebars.js file. */
@@ -134,17 +109,14 @@ public class HandlebarsViewResolver extends AbstractTemplateViewResolver
*
* @param viewClass The view's class. Required.
*/
- public HandlebarsViewResolver(
- final Class extends HandlebarsView> viewClass) {
+ public HandlebarsViewResolver(final Class extends HandlebarsView> viewClass) {
setViewClass(viewClass);
setContentType(DEFAULT_CONTENT_TYPE);
setPrefix(TemplateLoader.DEFAULT_PREFIX);
setSuffix(TemplateLoader.DEFAULT_SUFFIX);
}
- /**
- * Creates a new {@link HandlebarsViewResolver}.
- */
+ /** Creates a new {@link HandlebarsViewResolver}. */
public HandlebarsViewResolver() {
this(HandlebarsView.class);
}
@@ -154,7 +126,7 @@ public HandlebarsViewResolver() {
* underlying template lifecycle management.
*
* @param handlebars The {@link Handlebars} instance used for template lifecycle management.
- * Required.
+ * Required.
*/
public HandlebarsViewResolver(final Handlebars handlebars) {
this(handlebars, HandlebarsView.class);
@@ -165,22 +137,19 @@ public HandlebarsViewResolver(final Handlebars handlebars) {
* underlying template lifecycle management.
*
* @param handlebars The {@link Handlebars} instance used for template lifecycle management.
- * Required.
+ * Required.
* @param viewClass The view's class. Required.
*/
- public HandlebarsViewResolver(final Handlebars handlebars,
- final Class extends HandlebarsView> viewClass) {
+ public HandlebarsViewResolver(
+ final Handlebars handlebars, final Class extends HandlebarsView> viewClass) {
this(viewClass);
this.handlebars = handlebars;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
- protected AbstractUrlBasedView buildView(final String viewName)
- throws Exception {
+ protected AbstractUrlBasedView buildView(final String viewName) throws Exception {
return configure((HandlebarsView) super.buildView(viewName));
}
@@ -191,12 +160,10 @@ protected AbstractUrlBasedView buildView(final String viewName)
* @return The configured view.
* @throws IOException If a resource cannot be loaded.
*/
- protected AbstractUrlBasedView configure(final HandlebarsView view)
- throws IOException {
+ protected AbstractUrlBasedView configure(final HandlebarsView view) throws IOException {
String url = view.getUrl();
// Remove prefix & suffix.
- url = url.substring(getPrefix().length(), url.length()
- - getSuffix().length());
+ url = url.substring(getPrefix().length(), url.length() - getSuffix().length());
// Compile the template.
try {
view.setTemplate(handlebars.compile(url));
@@ -228,8 +195,8 @@ public void afterPropertiesSet() {
TemplateLoader templateLoader = createTemplateLoader(getApplicationContext());
// Creates a new handlebars object.
- handlebars = requireNonNull(createHandlebars(templateLoader),
- "A handlebars object is required.");
+ handlebars =
+ requireNonNull(createHandlebars(templateLoader), "A handlebars object is required.");
}
handlebars.with(registry);
@@ -325,8 +292,7 @@ protected TemplateLoader createTemplateLoader(final ApplicationContext context)
*/
public Handlebars getHandlebars() {
if (handlebars == null) {
- throw new IllegalStateException(
- "afterPropertiesSet() method hasn't been call it.");
+ throw new IllegalStateException("afterPropertiesSet() method hasn't been call it.");
}
return handlebars;
}
@@ -344,10 +310,8 @@ protected List getValueResolvers() {
* @param valueResolvers The value resolvers. Required.
*/
public void setValueResolvers(final ValueResolver... valueResolvers) {
- requireNonNull(valueResolvers,
- "At least one value-resolver must be present.");
- this.valueResolvers = Stream.of(valueResolvers)
- .collect(Collectors.toList());
+ requireNonNull(valueResolvers, "At least one value-resolver must be present.");
+ this.valueResolvers = Stream.of(valueResolvers).collect(Collectors.toList());
}
/**
@@ -356,27 +320,22 @@ public void setValueResolvers(final ValueResolver... valueResolvers) {
* @param formatters Formatters to add.
*/
public void setFormatters(final Formatter... formatters) {
- this.formatters = requireNonNull(formatters,
- "At least one formatter must be present.");
+ this.formatters = requireNonNull(formatters, "At least one formatter must be present.");
}
/**
* Set the handlebars.js location used it to compile/precompile template to JavaScript.
- *
- * Using handlebars.js 2.x:
- *
+ *
+ *
Using handlebars.js 2.x:
*
*
- * Handlebars handlebars = new Handlebars()
- * .handlebarsJsFile("handlebars-v2.0.0.js");
+ * Handlebars handlebars = new Handlebars().handlebarsJsFile("handlebars-v2.0.0.js");
*
- *
- * Using handlebars.js 1.x:
- *
+ *
+ *
Using handlebars.js 1.x:
*
*
- * Handlebars handlebars = new Handlebars()
- * .handlebarsJsFile("handlebars-v4.7.7.js");
+ * Handlebars handlebars = new Handlebars().handlebarsJsFile("handlebars-v4.7.7.js");
*
*
* Default handlebars.js is handlebars-v4.7.7.js.
@@ -390,8 +349,8 @@ public void setHandlebarsJsFile(final String location) {
/**
* True, if the view resolver should fail on missing files. Default is: true.
*
- * @param failOnMissingFile True, if the view resolver should fail on
- * missing files. Default is: true.
+ * @param failOnMissingFile True, if the view resolver should fail on missing files. Default is:
+ * true.
*/
public void setFailOnMissingFile(final boolean failOnMissingFile) {
this.failOnMissingFile = failOnMissingFile;
@@ -425,12 +384,9 @@ public void setHelperSources(final List> helpers) {
}
/**
- *
* Register all the helper methods for the given helper source.
- *
- *
- * A helper method looks like:
- *
+ *
+ *
A helper method looks like:
*
*
* public static? CharSequence methodName(context?, parameter*, options?) {
@@ -438,12 +394,13 @@ public void setHelperSources(final List> helpers) {
*
*
* Where:
+ *
*
- *
A method can/can't be static
- *
The method's name became the helper's name
- *
Context, parameters and options are all optionals
- *
If context and options are present they must be the first and last arguments of the
- * method
+ *
A method can/can't be static
+ *
The method's name became the helper's name
+ *
Context, parameters and options are all optionals
+ *
If context and options are present they must be the first and last arguments of the
+ * method
*
*
* Instance and static methods will be registered as helpers.
@@ -458,12 +415,9 @@ public HandlebarsViewResolver registerHelpers(final Object helperSource) {
}
/**
- *
* Register all the helper methods for the given helper source.
- *
- *
- * A helper method looks like:
- *
+ *
+ *
A helper method looks like:
*
*
* public static? CharSequence methodName(context?, parameter*, options?) {
@@ -471,12 +425,13 @@ public HandlebarsViewResolver registerHelpers(final Object helperSource) {
*
*
* Where:
+ *
*
- *
A method can/can't be static
- *
The method's name became the helper's name
- *
Context, parameters and options are all optionals
- *
If context and options are present they must be the first and last arguments of the
- * method
+ *
A method can/can't be static
+ *
The method's name became the helper's name
+ *
Context, parameters and options are all optionals
+ *
If context and options are present they must be the first and last arguments of the
+ * method
*
*
* Only static methods will be registered as helpers.
@@ -561,7 +516,7 @@ public HandlebarsViewResolver withoutMessageHelper() {
* true.
*
* @param registerMessageHelper True, if the message helper (based on {@link MessageSource})
- * should be registered. Default is: true.
+ * should be registered. Default is: true.
*/
public void setRegisterMessageHelper(final boolean registerMessageHelper) {
this.registerMessageHelper = registerMessageHelper;
@@ -569,7 +524,7 @@ public void setRegisterMessageHelper(final boolean registerMessageHelper) {
/**
* @param bindI18nToMessageSource If true, the i18n helpers will use a {@link MessageSource}
- * instead of a plain {@link ResourceBundle}. Default is: false.
+ * instead of a plain {@link ResourceBundle}. Default is: false.
*/
public void setBindI18nToMessageSource(final boolean bindI18nToMessageSource) {
this.bindI18nToMessageSource = bindI18nToMessageSource;
@@ -577,15 +532,15 @@ public void setBindI18nToMessageSource(final boolean bindI18nToMessageSource) {
/**
* If true, templates will be deleted once applied. Useful, in some advanced template inheritance
- * use cases. Used by {{#block}} helper. Default is: false.
- * At any time you can override the default setup with:
+ * use cases. Used by {{#block}} helper. Default is: false. At any time you can
+ * override the default setup with:
*
*
* {{#block "footer" delete-after-merge=true}}
*
*
* @param deletePartialAfterMerge True for clearing up templates once they got applied. Used by
- * {{#block}} helper.
+ * {{#block}} helper.
*/
public void setDeletePartialAfterMerge(final boolean deletePartialAfterMerge) {
this.deletePartialAfterMerge = deletePartialAfterMerge;
@@ -617,7 +572,8 @@ public HandlebarsViewResolver registerDecorator(final String name, final Decorat
return this;
}
- @Override public HandlebarsViewResolver setCharset(final Charset charset) {
+ @Override
+ public HandlebarsViewResolver setCharset(final Charset charset) {
this.charset = requireNonNull(charset, "Charset required.");
return this;
}
diff --git a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/MessageSourceHelper.java b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/MessageSourceHelper.java
index 05eb29ac1..3a3e0df81 100644
--- a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/MessageSourceHelper.java
+++ b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/MessageSourceHelper.java
@@ -1,26 +1,15 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.springmvc;
+import static java.util.Objects.requireNonNull;
+
import java.io.IOException;
import java.util.Locale;
-import static java.util.Objects.requireNonNull;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
@@ -28,23 +17,22 @@
import com.github.jknack.handlebars.Options;
/**
- *
- * A helper that delegates to a {@link MessageSource} instance.
- *
- * Usage:
+ * A helper that delegates to a {@link MessageSource} instance. Usage:
*
*
- * This helper have a strong dependency to local-thread-bound variable for
- * accessing to the current user locale.
+ *
+ * This helper have a strong dependency to local-thread-bound variable for accessing to the current
+ * user locale.
*
* @author edgar.espina
* @since 0.5.5
@@ -52,9 +40,7 @@
*/
public class MessageSourceHelper implements Helper {
- /**
- * A message source. Required.
- */
+ /** A message source. Required. */
private MessageSource messageSource;
/**
@@ -67,8 +53,7 @@ public MessageSourceHelper(final MessageSource messageSource) {
}
@Override
- public Object apply(final String code, final Options options)
- throws IOException {
+ public Object apply(final String code, final Options options) throws IOException {
Object[] args = options.params;
String defaultMessage = options.hash("default");
return messageSource.getMessage(code, args, defaultMessage, currentLocale());
diff --git a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/SpringTemplateLoader.java b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/SpringTemplateLoader.java
index a6db5085c..c2d92b94b 100644
--- a/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/SpringTemplateLoader.java
+++ b/handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/SpringTemplateLoader.java
@@ -1,26 +1,15 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.springmvc;
+import static java.util.Objects.requireNonNull;
+
import java.io.IOException;
import java.net.URL;
-import static java.util.Objects.requireNonNull;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
@@ -30,10 +19,11 @@
/**
* A template loader for a Spring application.
+ *
*
- *
Must support fully qualified URLs, e.g. "file:C:/page.html".
- *
Must support classpath pseudo-URLs, e.g. "classpath:page.html".
- *
Should support relative file paths, e.g. "WEB-INF/page.html".
+ *
Must support fully qualified URLs, e.g. "file:C:/page.html".
+ *
Must support classpath pseudo-URLs, e.g. "classpath:page.html".
+ *
Should support relative file paths, e.g. "WEB-INF/page.html".
*
*
* @author edgar.espina
@@ -42,9 +32,7 @@
*/
public class SpringTemplateLoader extends URLTemplateLoader {
- /**
- * The Spring {@link ResourceLoader}.
- */
+ /** The Spring {@link ResourceLoader}. */
private ResourceLoader loader;
/**
@@ -87,5 +75,4 @@ public String resolve(final String location) {
}
return protocol + super.resolve(location.substring(protocol.length()));
}
-
}
diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsApp.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsApp.java
index f2e38b04c..9252c5fbf 100644
--- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsApp.java
+++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsApp.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.springmvc;
import java.io.IOException;
@@ -5,7 +10,6 @@
import java.util.HashMap;
import java.util.Map;
-import com.github.jknack.handlebars.Handlebars;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
@@ -13,25 +17,26 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
+import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
@Configuration
public class HandlebarsApp {
- @Autowired
- ApplicationContext applicationContext;
+ @Autowired ApplicationContext applicationContext;
@Bean
public HandlebarsViewResolver viewResolver() {
HandlebarsViewResolver viewResolver = new HandlebarsViewResolver();
- Helper helper = new Helper() {
- @Override
- public Object apply(final Object context, final Options options) throws IOException {
- return "Spring Helper";
- }
- };
+ Helper helper =
+ new Helper() {
+ @Override
+ public Object apply(final Object context, final Options options) throws IOException {
+ return "Spring Helper";
+ }
+ };
viewResolver.registerHelper("spring", helper);
viewResolver.setHelperSources(Arrays.asList(HandlebarsApp.class));
@@ -48,8 +53,8 @@ public Object apply(final Object context, final Options options) throws IOExcept
@Bean
public HandlebarsViewResolver parameterizedHandlebarsViewResolver() {
- HandlebarsViewResolver viewResolver = new HandlebarsViewResolver(new Handlebars(
- new SpringTemplateLoader(applicationContext)));
+ HandlebarsViewResolver viewResolver =
+ new HandlebarsViewResolver(new Handlebars(new SpringTemplateLoader(applicationContext)));
// no cache for testing
viewResolver.setCache(false);
diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolverIntegrationTest.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolverIntegrationTest.java
index 358e4f173..f038a47fc 100644
--- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolverIntegrationTest.java
+++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewResolverIntegrationTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.springmvc;
import static org.junit.Assert.assertEquals;
@@ -19,20 +24,17 @@
import com.github.jknack.handlebars.Handlebars;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {HandlebarsApp.class })
+@ContextConfiguration(classes = {HandlebarsApp.class})
public class HandlebarsViewResolverIntegrationTest {
@Autowired
- @Qualifier("viewResolver")
- HandlebarsViewResolver viewResolver;
+ @Qualifier("viewResolver") HandlebarsViewResolver viewResolver;
@Autowired
- @Qualifier("viewResolverWithoutMessageHelper")
- HandlebarsViewResolver viewResolverWithoutMessageHelper;
+ @Qualifier("viewResolverWithoutMessageHelper") HandlebarsViewResolver viewResolverWithoutMessageHelper;
@Autowired
- @Qualifier("parameterizedHandlebarsViewResolver")
- HandlebarsViewResolver parameterizedHandlebarsViewResolver;
+ @Qualifier("parameterizedHandlebarsViewResolver") HandlebarsViewResolver parameterizedHandlebarsViewResolver;
@Test
public void getHandlebars() throws Exception {
@@ -51,7 +53,8 @@ public void resolveView() throws Exception {
@Test
public void resolveViewWithParameterized() throws Exception {
assertNotNull(parameterizedHandlebarsViewResolver);
- View view = parameterizedHandlebarsViewResolver.resolveViewName("template", Locale.getDefault());
+ View view =
+ parameterizedHandlebarsViewResolver.resolveViewName("template", Locale.getDefault());
assertNotNull(view);
assertEquals(HandlebarsView.class, view.getClass());
}
@@ -73,7 +76,8 @@ public void resolveViewWithFallbackParameterized() throws Exception {
try {
assertNotNull(parameterizedHandlebarsViewResolver);
parameterizedHandlebarsViewResolver.setFailOnMissingFile(false);
- View view = parameterizedHandlebarsViewResolver.resolveViewName("invalidView", Locale.getDefault());
+ View view =
+ parameterizedHandlebarsViewResolver.resolveViewName("invalidView", Locale.getDefault());
assertNull(view);
} finally {
parameterizedHandlebarsViewResolver.setFailOnMissingFile(true);
@@ -111,9 +115,11 @@ public void getHandlebarsFail() throws Exception {
public void messageHelper() throws Exception {
assertNotNull(viewResolver);
Handlebars handlebars = viewResolver.getHandlebars();
- assertEquals("Handlebars Spring MVC!",
+ assertEquals(
+ "Handlebars Spring MVC!",
handlebars.compileInline("{{message \"hello\"}}").apply(new Object()));
- assertEquals("Handlebars Spring MVC!",
+ assertEquals(
+ "Handlebars Spring MVC!",
handlebars.compileInline("{{i18n \"hello\"}}").apply(new Object()));
}
@@ -121,28 +127,33 @@ public void messageHelper() throws Exception {
public void messageHelperWithParams() throws Exception {
assertNotNull(viewResolver);
Handlebars handlebars = viewResolver.getHandlebars();
- assertEquals("Hello Handlebars!",
+ assertEquals(
+ "Hello Handlebars!",
handlebars.compileInline("{{message \"hello.0\" \"Handlebars\"}}").apply(new Object()));
- assertEquals("Hello Handlebars!",
+ assertEquals(
+ "Hello Handlebars!",
handlebars.compileInline("{{i18n \"hello.0\" \"Handlebars\"}}").apply(new Object()));
- assertEquals("Hello Spring MVC!",
+ assertEquals(
+ "Hello Spring MVC!",
handlebars.compileInline("{{message \"hello.0\" \"Spring MVC\"}}").apply(new Object()));
- assertEquals("Hello Spring MVC!",
+ assertEquals(
+ "Hello Spring MVC!",
handlebars.compileInline("{{i18n \"hello.0\" \"Spring MVC\"}}").apply(new Object()));
}
@Test
public void i18nJs() throws Exception {
// maven classpath
- String expected = "\n";
+ String expected =
+ "\n";
assertNotNull(viewResolver);
Handlebars handlebars = viewResolver.getHandlebars();
@@ -153,24 +164,28 @@ public void i18nJs() throws Exception {
} catch (ComparisonFailure ex) {
try {
// eclipse classpath
- assertEquals("\n", output);
+ assertEquals(
+ "\n",
+ output);
} catch (ComparisonFailure java18) {
// java 1.8
- assertEquals("\n", output);
+ assertEquals(
+ "\n",
+ output);
}
}
}
@@ -179,8 +194,8 @@ public void i18nJs() throws Exception {
public void messageHelperWithDefaultValue() throws Exception {
assertNotNull(viewResolver);
Handlebars handlebars = viewResolver.getHandlebars();
- assertEquals("hey",
- handlebars.compileInline("{{message \"hi\" default='hey'}}").apply(new Object()));
+ assertEquals(
+ "hey", handlebars.compileInline("{{message \"hi\" default='hey'}}").apply(new Object()));
}
@Test
@@ -201,7 +216,8 @@ public void setCustomHelper() throws Exception {
public void helperSource() throws Exception {
assertNotNull(viewResolver);
Handlebars handlebars = viewResolver.getHandlebars();
- assertEquals("helper source!", handlebars.compileInline("{{helperSource}}").apply(new Object()));
+ assertEquals(
+ "helper source!", handlebars.compileInline("{{helperSource}}").apply(new Object()));
}
@Test
diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewTest.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewTest.java
index 0b2fcd686..6f576e409 100644
--- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewTest.java
+++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/HandlebarsViewTest.java
@@ -1,19 +1,7 @@
-/**
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
* Copyright (c) 2012 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
*/
package com.github.jknack.handlebars.springmvc;
@@ -30,11 +18,11 @@
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import com.github.jknack.handlebars.Context;
import com.github.jknack.handlebars.Template;
import com.github.jknack.handlebars.context.MapValueResolver;
-import org.mockito.ArgumentCaptor;
/**
* Unit test for {@link HandlebarsView}.
diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue257.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue257.java
index 7093f8f2b..94b19dec2 100644
--- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue257.java
+++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue257.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.springmvc;
import static org.junit.Assert.assertNotNull;
@@ -10,12 +15,11 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {HandlebarsApp.class })
+@ContextConfiguration(classes = {HandlebarsApp.class})
public class Issue257 {
@Autowired
- @Qualifier("viewResolver")
- HandlebarsViewResolver viewResolver;
+ @Qualifier("viewResolver") HandlebarsViewResolver viewResolver;
@Test
public void viewResolverShouldHaveBuiltInHelpers() {
diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue292.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue292.java
index 4f5167e32..eda9c2cf9 100644
--- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue292.java
+++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue292.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.springmvc;
import static org.junit.Assert.assertNotNull;
@@ -14,16 +19,14 @@
import org.springframework.web.servlet.View;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {HandlebarsApp.class })
+@ContextConfiguration(classes = {HandlebarsApp.class})
public class Issue292 {
@Autowired
- @Qualifier("viewResolver")
- HandlebarsViewResolver viewResolver;
+ @Qualifier("viewResolver") HandlebarsViewResolver viewResolver;
@Autowired
- @Qualifier("viewResolverWithoutMessageHelper")
- HandlebarsViewResolver viewResolverWithoutMessageHelper;
+ @Qualifier("viewResolverWithoutMessageHelper") HandlebarsViewResolver viewResolverWithoutMessageHelper;
@Test
public void getTemplate() throws Exception {
@@ -32,5 +35,4 @@ public void getTemplate() throws Exception {
assertTrue(view instanceof HandlebarsView);
assertNotNull(((HandlebarsView) view).getTemplate());
}
-
}
diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue304.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue304.java
index 0faaf4e8b..29ba082f5 100644
--- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue304.java
+++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/Issue304.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.springmvc;
import static org.junit.Assert.assertEquals;
@@ -16,16 +21,14 @@
import org.springframework.web.servlet.view.RedirectView;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {HandlebarsApp.class })
+@ContextConfiguration(classes = {HandlebarsApp.class})
public class Issue304 {
@Autowired
- @Qualifier("viewResolver")
- HandlebarsViewResolver viewResolver;
+ @Qualifier("viewResolver") HandlebarsViewResolver viewResolver;
@Autowired
- @Qualifier("viewResolverWithoutMessageHelper")
- HandlebarsViewResolver viewResolverWithoutMessageHelper;
+ @Qualifier("viewResolverWithoutMessageHelper") HandlebarsViewResolver viewResolverWithoutMessageHelper;
@Test
public void forward() throws Exception {
@@ -42,5 +45,4 @@ public void redirect() throws Exception {
assertNotNull(view);
assertEquals(RedirectView.class, view.getClass());
}
-
}
diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/MessageSourceHelperTest.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/MessageSourceHelperTest.java
index c33f8052a..3452a28c4 100644
--- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/MessageSourceHelperTest.java
+++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/MessageSourceHelperTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.springmvc;
import static org.junit.Assert.assertEquals;
@@ -42,22 +47,21 @@ public void messageSource() throws IOException {
Context ctx = mock(Context.class);
Template fn = mock(Template.class);
- Options options = new Options.Builder(hbs, "messageSource", TagType.VAR, ctx, fn)
- .setParams(params)
- .setHash(hash)
- .build();
+ Options options =
+ new Options.Builder(hbs, "messageSource", TagType.VAR, ctx, fn)
+ .setParams(params)
+ .setHash(hash)
+ .build();
MessageSource messageSource = mock(MessageSource.class);
- when(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage),
- any(Locale.class))).thenReturn(message);
+ when(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage), any(Locale.class)))
+ .thenReturn(message);
- Object result =
- new MessageSourceHelper(messageSource).apply(code, options);
+ Object result = new MessageSourceHelper(messageSource).apply(code, options);
assertEquals(message, result);
verify(hash).get("default");
- verify(messageSource).getMessage(eq(code), eq(params), eq(defaultMessage),
- any(Locale.class));
+ verify(messageSource).getMessage(eq(code), eq(params), eq(defaultMessage), any(Locale.class));
}
@Test
@@ -67,7 +71,7 @@ public void messageSourceWithParams() throws IOException {
String defaultMessage = null;
// Options
- Object[] params = {1, 2, 3 };
+ Object[] params = {1, 2, 3};
@SuppressWarnings("unchecked")
Map hash = mock(Map.class);
when(hash.get("default")).thenReturn(defaultMessage);
@@ -76,22 +80,21 @@ public void messageSourceWithParams() throws IOException {
Context ctx = mock(Context.class);
Template fn = mock(Template.class);
- Options options = new Options.Builder(hbs, "messageSource", TagType.VAR, ctx, fn)
- .setParams(params)
- .setHash(hash)
- .build();
+ Options options =
+ new Options.Builder(hbs, "messageSource", TagType.VAR, ctx, fn)
+ .setParams(params)
+ .setHash(hash)
+ .build();
MessageSource messageSource = mock(MessageSource.class);
- when(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage),
- any(Locale.class))).thenReturn(message);
+ when(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage), any(Locale.class)))
+ .thenReturn(message);
- Object result =
- new MessageSourceHelper(messageSource).apply(code, options);
+ Object result = new MessageSourceHelper(messageSource).apply(code, options);
assertEquals(message, result);
verify(hash).get("default");
- verify(messageSource).getMessage(eq(code), eq(params), eq(defaultMessage),
- any(Locale.class));
+ verify(messageSource).getMessage(eq(code), eq(params), eq(defaultMessage), any(Locale.class));
}
@Test
@@ -101,7 +104,7 @@ public void messageSourceWithDefaulMessage() throws IOException {
String defaultMessage = "Aca viene el 3";
// Options
- Object[] params = {1, 2, 3 };
+ Object[] params = {1, 2, 3};
@SuppressWarnings("unchecked")
Map hash = mock(Map.class);
when(hash.get("default")).thenReturn(defaultMessage);
@@ -110,21 +113,20 @@ public void messageSourceWithDefaulMessage() throws IOException {
Context ctx = mock(Context.class);
Template fn = mock(Template.class);
- Options options = new Options.Builder(hbs, "messageSource", TagType.VAR, ctx, fn)
- .setParams(params)
- .setHash(hash)
- .build();
+ Options options =
+ new Options.Builder(hbs, "messageSource", TagType.VAR, ctx, fn)
+ .setParams(params)
+ .setHash(hash)
+ .build();
MessageSource messageSource = mock(MessageSource.class);
- when(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage),
- any(Locale.class))).thenReturn(message);
+ when(messageSource.getMessage(eq(code), eq(params), eq(defaultMessage), any(Locale.class)))
+ .thenReturn(message);
- Object result =
- new MessageSourceHelper(messageSource).apply(code, options);
+ Object result = new MessageSourceHelper(messageSource).apply(code, options);
assertEquals(message, result);
verify(hash).get("default");
- verify(messageSource).getMessage(eq(code), eq(params), eq(defaultMessage),
- any(Locale.class));
+ verify(messageSource).getMessage(eq(code), eq(params), eq(defaultMessage), any(Locale.class));
}
}
diff --git a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/SpringTemplateLoaderTest.java b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/SpringTemplateLoaderTest.java
index 7d6ef851e..851ec1b81 100644
--- a/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/SpringTemplateLoaderTest.java
+++ b/handlebars-springmvc/src/test/java/com/github/jknack/handlebars/springmvc/SpringTemplateLoaderTest.java
@@ -1,3 +1,8 @@
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
+ */
package com.github.jknack.handlebars.springmvc;
import static org.junit.Assert.assertNotNull;
@@ -13,8 +18,7 @@ public class SpringTemplateLoaderTest {
@Test
public void sourceAt() throws IOException {
- SpringTemplateLoader loader =
- new SpringTemplateLoader(new DefaultResourceLoader());
+ SpringTemplateLoader loader = new SpringTemplateLoader(new DefaultResourceLoader());
TemplateSource source = loader.sourceAt("template");
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Context.java b/handlebars/src/main/java/com/github/jknack/handlebars/Context.java
index bfd16be3e..09736422e 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Context.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Context.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -37,17 +25,18 @@
import com.github.jknack.handlebars.io.TemplateSource;
/**
- * Mustache/Handlebars are contextual template engines. This class represent the
- * 'context stack' of a template.
+ * Mustache/Handlebars are contextual template engines. This class represent the 'context stack' of
+ * a template.
+ *
*
- *
Objects and hashes should be pushed onto the context stack.
- *
All elements on the context stack should be accessible.
- *
Multiple sections per template should be permitted.
- *
Failed context lookups should be considered falsy.
- *
Dotted names should be valid for Section tags.
- *
Dotted names that cannot be resolved should be considered falsy.
- *
Dotted Names - Context Precedence: Dotted names should be resolved against former
- * resolutions.
+ *
Objects and hashes should be pushed onto the context stack.
+ *
All elements on the context stack should be accessible.
+ *
Multiple sections per template should be permitted.
+ *
Failed context lookups should be considered falsy.
+ *
Dotted names should be valid for Section tags.
+ *
Dotted names that cannot be resolved should be considered falsy.
+ *
Dotted Names - Context Precedence: Dotted names should be resolved against former
+ * resolutions.
*
*
* @author edgar.espina
@@ -179,9 +168,7 @@ public Object get(final List path) {
*/
private static class CompositeValueResolver implements ValueResolver {
- /**
- * The internal value resolvers.
- */
+ /** The internal value resolvers. */
private List resolvers;
/**
@@ -237,9 +224,7 @@ public Set> propertySet(final Object context) {
*/
public static final class Builder {
- /**
- * The context product.
- */
+ /** The context product. */
private Context context;
/**
@@ -295,10 +280,10 @@ public Builder resolver(final ValueResolver... resolvers) {
notEmpty(resolvers, "At least one value-resolver must be present.");
boolean mapResolver = Stream.of(resolvers).anyMatch(MapValueResolver.class::isInstance);
if (!mapResolver) {
- context.setResolver(new CompositeValueResolver(
- Stream.concat(Stream.of(resolvers), Stream.of(MapValueResolver.INSTANCE))
- .collect(Collectors.toList())
- ));
+ context.setResolver(
+ new CompositeValueResolver(
+ Stream.concat(Stream.of(resolvers), Stream.of(MapValueResolver.INSTANCE))
+ .collect(Collectors.toList())));
} else {
context.setResolver(new CompositeValueResolver(Arrays.asList(resolvers)));
}
@@ -306,8 +291,8 @@ public Builder resolver(final ValueResolver... resolvers) {
}
/**
- * Add one or more value resolver to the defaults defined by
- * {@link ValueResolver#defaultValueResolvers()}.
+ * Add one or more value resolver to the defaults defined by {@link
+ * ValueResolver#defaultValueResolvers()}.
*
* @param resolvers The value resolvers. Required.
* @return This builder.
@@ -384,62 +369,39 @@ public Object eval(final ValueResolver resolver, final Context context, final Ob
}
return value;
}
-
}
- /**
- * Mark for fail context lookup.
- */
+ /** Mark for fail context lookup. */
private static final Object NULL = new Object();
- /**
- * The qualified name for partials. Internal use.
- */
+ /** The qualified name for partials. Internal use. */
public static final String PARTIALS = Context.class.getName() + "#partials";
- /**
- * Inline partials.
- */
+ /** Inline partials. */
public static final String INLINE_PARTIALS = "__inline_partials_";
- /**
- * The qualified name for partials. Internal use.
- */
+ /** The qualified name for partials. Internal use. */
public static final String INVOCATION_STACK = Context.class.getName() + "#invocationStack";
- /**
- * Number of parameters of a helper. Internal use.
- */
+ /** Number of parameters of a helper. Internal use. */
public static final String PARAM_SIZE = Context.class.getName() + "#paramSize";
- /**
- * Last callee of a partial block. Internal use.
- */
+ /** Last callee of a partial block. Internal use. */
public static final String CALLEE = Context.class.getName() + "#callee";
- /**
- * The parent context. Optional.
- */
+ /** The parent context. Optional. */
protected Context parent;
- /**
- * The target value. Resolved as '.' or 'this' inside templates. Required.
- */
+ /** The target value. Resolved as '.' or 'this' inside templates. Required. */
Object model;
- /**
- * A thread safe storage.
- */
+ /** A thread safe storage. */
protected Map data;
- /**
- * Additional, data can be stored here.
- */
+ /** Additional, data can be stored here. */
protected Context extendedContext;
- /**
- * The value resolver.
- */
+ /** The value resolver. */
protected ValueResolver resolver;
/**
@@ -456,8 +418,7 @@ protected Context(final Object model) {
/**
* Creates a root context.
*
- * @param model The target value. Resolved as '.' or 'this' inside
- * templates. Required.
+ * @param model The target value. Resolved as '.' or 'this' inside templates. Required.
* @return A root context.
*/
private static Context root(final Object model) {
@@ -480,7 +441,7 @@ private static Context root(final Object model) {
* @param model The model data.
* @return This context.
*/
- @SuppressWarnings({"unchecked" })
+ @SuppressWarnings({"unchecked"})
public Context combine(final String name, final Object model) {
Map map = (Map) extendedContext.model;
map.put(name, model);
@@ -493,7 +454,7 @@ public Context combine(final String name, final Object model) {
* @param model The model attributes.
* @return This context.
*/
- @SuppressWarnings({"unchecked" })
+ @SuppressWarnings({"unchecked"})
public Context combine(final Map model) {
Map map = (Map) extendedContext.model;
map.putAll(model);
@@ -587,15 +548,16 @@ public boolean isBlockParams() {
/**
* Lookup the given key inside the context stack.
+ *
*
- *
Objects and hashes should be pushed onto the context stack.
- *
All elements on the context stack should be accessible.
- *
Multiple sections per template should be permitted.
- *
Failed context lookups should be considered falsey.
- *
Dotted names should be valid for Section tags.
- *
Dotted names that cannot be resolved should be considered falsey.
- *
Dotted Names - Context Precedence: Dotted names should be resolved against former
- * resolutions.
+ *
Objects and hashes should be pushed onto the context stack.
+ *
All elements on the context stack should be accessible.
+ *
Multiple sections per template should be permitted.
+ *
Failed context lookups should be considered falsey.
+ *
Dotted names should be valid for Section tags.
+ *
Dotted names that cannot be resolved should be considered falsey.
+ *
Dotted Names - Context Precedence: Dotted names should be resolved against former
+ * resolutions.
*
*
* @param path The object path.
@@ -633,15 +595,16 @@ public Object get(final List path) {
/**
* Lookup the given key inside the context stack.
+ *
*
- *
Objects and hashes should be pushed onto the context stack.
- *
All elements on the context stack should be accessible.
- *
Multiple sections per template should be permitted.
- *
Failed context lookups should be considered falsey.
- *
Dotted names should be valid for Section tags.
- *
Dotted names that cannot be resolved should be considered falsey.
- *
Dotted Names - Context Precedence: Dotted names should be resolved against former
- * resolutions.
+ *
Objects and hashes should be pushed onto the context stack.
+ *
All elements on the context stack should be accessible.
+ *
Multiple sections per template should be permitted.
+ *
Failed context lookups should be considered falsey.
+ *
Dotted names should be valid for Section tags.
+ *
Dotted names that cannot be resolved should be considered falsey.
+ *
Dotted Names - Context Precedence: Dotted names should be resolved against former
+ * resolutions.
*
*
* @param key The object key.
@@ -653,15 +616,16 @@ public Object get(final String key) {
/**
* Lookup the given key inside the context stack.
+ *
*
- *
Objects and hashes should be pushed onto the context stack.
- *
All elements on the context stack should be accessible.
- *
Multiple sections per template should be permitted.
- *
Failed context lookups should be considered falsey.
- *
Dotted names should be valid for Section tags.
- *
Dotted names that cannot be resolved should be considered falsey.
- *
Dotted Names - Context Precedence: Dotted names should be resolved against former
- * resolutions.
+ *
Objects and hashes should be pushed onto the context stack.
+ *
All elements on the context stack should be accessible.
+ *
Multiple sections per template should be permitted.
+ *
Failed context lookups should be considered falsey.
+ *
Dotted names should be valid for Section tags.
+ *
Dotted names that cannot be resolved should be considered falsey.
+ *
Dotted Names - Context Precedence: Dotted names should be resolved against former
+ * resolutions.
*
*
* @param key The object key.
@@ -682,9 +646,7 @@ private void setResolver(final ValueResolver resolver) {
extendedContext.resolver = resolver;
}
- /**
- * Destroy this context by cleaning up instance attributes.
- */
+ /** Destroy this context by cleaning up instance attributes. */
public void destroy() {
model = null;
if (parent == null) {
@@ -746,8 +708,8 @@ public static Context newContext(final Context parent, final Object model) {
* @param values A list of values to set in the block param context.
* @return A new block param context.
*/
- public static Context newBlockParamContext(final Context parent, final List names,
- final List values) {
+ public static Context newBlockParamContext(
+ final Context parent, final List names, final List values) {
Map hash = new HashMap<>();
for (int i = 0; i < Math.min(values.size(), names.size()); i++) {
hash.put(names.get(i), values.get(i));
@@ -763,8 +725,8 @@ public static Context newBlockParamContext(final Context parent, final List hash) {
+ public static Context newPartialContext(
+ final Context ctx, final String scope, final Map hash) {
return new PartialCtx(ctx, ctx.get(scope), hash);
}
@@ -816,5 +778,4 @@ public static Context copy(final Context context, final Object model) {
ctx.resolver = context.resolver;
return ctx;
}
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Decorator.java b/handlebars/src/main/java/com/github/jknack/handlebars/Decorator.java
index b3ab7e934..e30d92d60 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Decorator.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Decorator.java
@@ -1,27 +1,15 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
import java.io.IOException;
/**
- * A decorator allows a declarative means to both annotate particular blocks with metadata as
- * well as to wrap in behaviors when desired, prior to execution.
+ * A decorator allows a declarative means to both annotate particular blocks with metadata as well
+ * as to wrap in behaviors when desired, prior to execution.
*
* @author edgar
* @since 4.0.0
@@ -36,5 +24,4 @@ public interface Decorator {
* @throws IOException If something goes wrong.
*/
void apply(Template fn, Options options) throws IOException;
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/EscapingStrategy.java b/handlebars/src/main/java/com/github/jknack/handlebars/EscapingStrategy.java
index 03ab9ccfc..3a0406f42 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/EscapingStrategy.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/EscapingStrategy.java
@@ -1,43 +1,28 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
-import org.apache.commons.text.StringEscapeUtils;
-import org.apache.commons.text.translate.LookupTranslator;
-
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.text.StringEscapeUtils;
+import org.apache.commons.text.translate.LookupTranslator;
+
/**
- *
* A strategy for determining how to escape a variable ({{variable}})..
- *
- *
- * Usage:
- *
+ *
+ *
Usage:
*
*
- * EscapingStrategy escapingStrategy = new EscapingStrategy() {
- * public String escape(final CharSequence value) {
- * // return the character sequence escaped however you want
- * }
- * };
- * Handlebars handlebars = new Handlebars().with(escapingStrategy);
+ * EscapingStrategy escapingStrategy = new EscapingStrategy() {
+ * public String escape(final CharSequence value) {
+ * // return the character sequence escaped however you want
+ * }
+ * };
+ * Handlebars handlebars = new Handlebars().with(escapingStrategy);
*
*
* @author Tristan Burch
@@ -46,8 +31,8 @@
public interface EscapingStrategy {
/**
- * Handlebars escaping strategy. Escape is done via a string map. See
- * {@link EscapingStrategy#HTML_ENTITY}.
+ * Handlebars escaping strategy. Escape is done via a string map. See {@link
+ * EscapingStrategy#HTML_ENTITY}.
*
* @author edgar
* @since 4.0.4
@@ -101,45 +86,45 @@ private static Map escapeMap(final String[][] table)
}
}
- /**
- * The default HTML Entity escaping strategy.
- */
- EscapingStrategy HTML_ENTITY = new Hbs(new String[][]{
- {"<", "<" },
- {">", ">" },
- {"\"", """ },
- {"'", "'" },
- {"`", "`" },
- {"&", "&" },
- {"=", "=" }
- });
-
- /**
- * Like {@link #HTML_ENTITY} but ignores =.
- */
- EscapingStrategy HBS3 = new Hbs(new String[][]{
- {"<", "<" },
- {">", ">" },
- {"\"", """ },
- {"'", "'" },
- {"`", "`" },
- {"&", "&" }
- });
+ /** The default HTML Entity escaping strategy. */
+ EscapingStrategy HTML_ENTITY =
+ new Hbs(
+ new String[][] {
+ {"<", "<"},
+ {">", ">"},
+ {"\"", """},
+ {"'", "'"},
+ {"`", "`"},
+ {"&", "&"},
+ {"=", "="}
+ });
+
+ /** Like {@link #HTML_ENTITY} but ignores =. */
+ EscapingStrategy HBS3 =
+ new Hbs(
+ new String[][] {
+ {"<", "<"},
+ {">", ">"},
+ {"\"", """},
+ {"'", "'"},
+ {"`", "`"},
+ {"&", "&"}
+ });
/** Default escaping strategy for Handlebars 4.x . */
EscapingStrategy HBS4 = HTML_ENTITY;
/** Escape variable for CSV. */
- EscapingStrategy CSV = value ->
- value == null ? null : StringEscapeUtils.escapeCsv(value.toString());
+ EscapingStrategy CSV =
+ value -> value == null ? null : StringEscapeUtils.escapeCsv(value.toString());
/** Escape variable for XML. */
- EscapingStrategy XML = value ->
- value == null ? null : StringEscapeUtils.escapeXml11(value.toString());
+ EscapingStrategy XML =
+ value -> value == null ? null : StringEscapeUtils.escapeXml11(value.toString());
/** Escape variable for JavaScript. */
- EscapingStrategy JS = value ->
- value == null ? null : StringEscapeUtils.escapeEcmaScript(value.toString());
+ EscapingStrategy JS =
+ value -> value == null ? null : StringEscapeUtils.escapeEcmaScript(value.toString());
/** NOOP escaping. */
EscapingStrategy NOOP = value -> value;
@@ -154,5 +139,4 @@ private static Map escapeMap(final String[][] table)
* @return the escaped character sequence.
*/
CharSequence escape(CharSequence value);
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Formatter.java b/handlebars/src/main/java/com/github/jknack/handlebars/Formatter.java
index a2af7fc54..e72e223ce 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Formatter.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Formatter.java
@@ -1,47 +1,31 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
/**
- *
* Format a variable to something else. Useful for date/long conversion. etc.. A formatter is
* applied on simple mustache/handlebars expression, like: {{var}}, but not in block expression.
- *
*
- *
* @author edgar
* @since 2.1.0
*/
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
index a63f1d1e4..cea90591a 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -58,12 +46,10 @@
import com.github.jknack.handlebars.io.TemplateSource;
/**
- *
* Handlebars provides the power necessary to let you build semantic templates effectively with no
* frustration.
- *
- * You can specify a different ```TemplateLoader``` by:
- *
+ *
You can specify a different ```TemplateLoader``` by:
*
*
* TemplateLoader loader = ...;
@@ -106,17 +91,14 @@
public class Handlebars implements HelperRegistry {
/**
- * A {@link SafeString} tell {@link Handlebars} that the content should not be
- * escaped as HTML.
+ * A {@link SafeString} tell {@link Handlebars} that the content should not be escaped as HTML.
*
* @author edgar.espina
* @since 0.1.0
*/
public static class SafeString implements CharSequence {
- /**
- * The content.
- */
+ /** The content. */
public final CharSequence content;
/**
@@ -152,8 +134,7 @@ public String toString() {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + (content == null ? 0
- : content.hashCode());
+ result = prime * result + (content == null ? 0 : content.hashCode());
return result;
}
@@ -168,8 +149,8 @@ public boolean equals(final Object obj) {
}
/**
- * Utilities function like: {@link Utils#escapeExpression(CharSequence)} and
- * {@link Utils#isEmpty(Object)}.
+ * Utilities function like: {@link Utils#escapeExpression(CharSequence)} and {@link
+ * Utils#isEmpty(Object)}.
*
* @author edgar.espina
* @since 0.1.0
@@ -189,12 +170,12 @@ public static class Utils {
private static final String VERSION_PREFIX = "1.";
/**
- * Evaluate the given object and return true is the object is considered
- * empty. Nulls, empty list or array and false values are considered empty.
+ * Evaluate the given object and return true is the object is considered empty. Nulls, empty
+ * list or array and false values are considered empty.
*
* @param value The object value.
- * @return Return true is the object is considered empty. Nulls, empty list
- * or array and false values are considered empty.
+ * @return Return true is the object is considered empty. Nulls, empty list or array and false
+ * values are considered empty.
*/
@SuppressWarnings("rawtypes")
public static boolean isEmpty(final Object value) {
@@ -223,24 +204,18 @@ public static boolean isEmpty(final Object value) {
}
/**
- *
* Escapes the characters in a {@code String} using HTML entities.
- *
- *
- * For example:
- *
- *
- * "bread" {@literal &} "butter"
- *
- * becomes:
+ *
+ *
For example:
+ *
+ *
"bread" {@literal &} "butter" becomes:
*
*
* "bread" & "butter"
*
*
* @param input the {@code String} to escape, may be null.
- * @return The escaped version of the input or the same input if it's a
- * SafeString.
+ * @return The escaped version of the input or the same input if it's a SafeString.
*/
public static CharSequence escapeExpression(final CharSequence input) {
return EscapingStrategy.DEF.escape(input);
@@ -253,27 +228,28 @@ static int javaVersion() {
/**
* Throws any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it
- * onwards.
- * The exception is still thrown - javac will just stop whining about it.
- *
- * Example usage:
- *
public void run() {
- * throw sneakyThrow(new IOException("You don't need to catch me!"));
- * }
- *
- * NB: The exception is not wrapped, ignored, swallowed, or redefined. The JVM actually does
- * not know or care about the concept of a 'checked exception'. All this method does is hide
- * the act of throwing a checked exception from the java compiler.
- *
- * Note that this method has a return type of {@code RuntimeException}; it is advised you
- * always call this method as argument to the {@code throw} statement to avoid compiler
- * errors regarding no return statement and similar problems. This method won't of course
- * return an actual {@code RuntimeException} - it never returns, it always throws the provided
- * exception.
+ * onwards. The exception is still thrown - javac will just stop whining about it.
+ *
+ *
Example usage:
+ *
+ *
+ * public void run() {
+ * throw sneakyThrow(new IOException("You don't need to catch me!"));
+ * }
+ *
+ *
+ *
NB: The exception is not wrapped, ignored, swallowed, or redefined. The JVM actually does
+ * not know or care about the concept of a 'checked exception'. All this method does is hide the
+ * act of throwing a checked exception from the java compiler.
+ *
+ *
Note that this method has a return type of {@code RuntimeException}; it is advised you
+ * always call this method as argument to the {@code throw} statement to avoid compiler errors
+ * regarding no return statement and similar problems. This method won't of course return an
+ * actual {@code RuntimeException} - it never returns, it always throws the provided exception.
*
* @param x The throwable to throw without requiring you to catch its type.
* @return A dummy RuntimeException; this method never returns normally, it always
- * throws an exception!
+ * throws an exception!
*/
public static RuntimeException propagate(final Throwable x) {
if (x == null) {
@@ -297,44 +273,28 @@ private static void sneakyThrow0(final Throwable x) throws
}
}
- /**
- * The default start delimiter.
- */
+ /** The default start delimiter. */
public static final String DELIM_START = "{{";
- /**
- * The default end delimiter.
- */
+ /** The default end delimiter. */
public static final String DELIM_END = "}}";
- /**
- * The logging system.
- */
+ /** The logging system. */
private static final Logger logger = getLogger(Handlebars.class);
- /**
- * The template loader. Required.
- */
+ /** The template loader. Required. */
private TemplateLoader loader;
- /**
- * The template cache. Required.
- */
+ /** The template cache. Required. */
private TemplateCache cache = NullTemplateCache.INSTANCE;
- /**
- * If true, missing helper parameters will be resolve to their names.
- */
+ /** If true, missing helper parameters will be resolve to their names. */
private boolean stringParams;
- /**
- * If true, unnecessary whitespace and new lines will be removed.
- */
+ /** If true, unnecessary whitespace and new lines will be removed. */
private boolean prettyPrint;
- /**
- * The helper registry.
- */
+ /** The helper registry. */
private HelperRegistry registry = new DefaultHelperRegistry();
/**
@@ -345,8 +305,7 @@ private static void sneakyThrow0(final Throwable x) throws
/**
* If true, templates will be deleted once applied. Useful, in some advanced template inheritance
- * use cases. Default is: false.
- * At any time you can override the default setup with:
+ * use cases. Default is: false. At any time you can override the default setup with:
*
*
* {{#block "footer" delete-after-merge=true}}
@@ -354,24 +313,16 @@ private static void sneakyThrow0(final Throwable x) throws
*/
private boolean deletePartialAfterMerge;
- /**
- * The escaping strategy.
- */
+ /** The escaping strategy. */
private EscapingStrategy escapingStrategy = EscapingStrategy.HTML_ENTITY;
- /**
- * The parser factory. Required.
- */
+ /** The parser factory. Required. */
private ParserFactory parserFactory = new HbsParserFactory();
- /**
- * The start delimiter.
- */
+ /** The start delimiter. */
private String startDelimiter = DELIM_START;
- /**
- * The end delimiter.
- */
+ /** The end delimiter. */
private String endDelimiter = DELIM_END;
/** Location of the handlebars.js file. */
@@ -387,24 +338,28 @@ private static void sneakyThrow0(final Throwable x) throws
private boolean parentScopeResolution = true;
/**
- * If true partial blocks will be evaluated to allow side effects by defining inline
- * blocks within the partials blocks.
- * Attention: This feature slows down the performance severly if your templates use
- * deeply nested partial blocks.
- * Handlebars works *much* faster if this feature is set to false.
+ * If true partial blocks will be evaluated to allow side effects by defining inline blocks within
+ * the partials blocks. Attention: This feature slows down the performance severly if your
+ * templates use deeply nested partial blocks. Handlebars works *much* faster if this feature is
+ * set to false.
+ *
+ *
Example of a feature that is usable when this is set to true:
*
- * Example of a feature that is usable when this is set to true:
*
+ *
* With a myPartial.hbs template like this:
+ *
*
* {{> myInline}}
*
+ *
* The text "Wow!!!" will actually be rendered.
*
- * If this flag is set to false, you need to explicitly evaluate the partial block.
- * The template myPartial.hbs will have to look like this:
+ *
If this flag is set to false, you need to explicitly evaluate the partial block. The
+ * template myPartial.hbs will have to look like this:
+ *
*
* {{> @partial-block}}{{> myInline}}
*
@@ -428,10 +383,7 @@ public Handlebars(final TemplateLoader loader) {
with(loader);
}
- /**
- * Creates a new {@link Handlebars} with a {@link ClassPathTemplateLoader} and no
- * cache.
- */
+ /** Creates a new {@link Handlebars} with a {@link ClassPathTemplateLoader} and no cache. */
public Handlebars() {
this(new ClassPathTemplateLoader());
}
@@ -443,9 +395,7 @@ public Handlebars() {
* @return JavaScript.
*/
public String precompile(final String path) {
- return Throwing.get(() ->
- precompileInline(loader.sourceAt(path).content(charset))
- );
+ return Throwing.get(() -> precompileInline(loader.sourceAt(path).content(charset)));
}
/**
@@ -455,23 +405,23 @@ public String precompile(final String path) {
* @return JavaScript.
*/
public String precompileInline(final String template) {
- return Throwing.get(() -> {
- ScriptEngine engine = engine();
- Object handlebars = engine.getContext().getAttribute("Handlebars");
- Bindings bindings = engine.createBindings();
- bindings.put("Handlebars", handlebars);
- bindings.put("template", template);
- return (String) engine.eval("Handlebars.precompile(template);", bindings);
- });
+ return Throwing.get(
+ () -> {
+ ScriptEngine engine = engine();
+ Object handlebars = engine.getContext().getAttribute("Handlebars");
+ Bindings bindings = engine.createBindings();
+ bindings.put("Handlebars", handlebars);
+ bindings.put("template", template);
+ return (String) engine.eval("Handlebars.precompile(template);", bindings);
+ });
}
/**
- * Compile the resource located at the given uri.
- * The implementation uses a cache for previously compiled Templates. By default,
- * if the resource has been compiled previously, and no changes have occurred
- * since in the resource, compilation will be skipped and the previously created
- * Template will be returned. You can set an alternate cache implementation
- * using {@link #with(TemplateCache cache) with}.
+ * Compile the resource located at the given uri. The implementation uses a cache for previously
+ * compiled Templates. By default, if the resource has been compiled previously, and no changes
+ * have occurred since in the resource, compilation will be skipped and the previously created
+ * Template will be returned. You can set an alternate cache implementation using {@link
+ * #with(TemplateCache cache) with}.
*
* @param location The resource's location. Required.
* @return A compiled template.
@@ -482,12 +432,11 @@ public Template compile(final String location) throws IOException {
}
/**
- * Compile the resource located at the given uri.
- * The implementation uses a cache for previously compiled Templates. By default,
- * if the resource has been compiled previously, and no changes have occurred
- * since in the resource, compilation will be skipped and the previously created
- * Template will be returned. You can set an alternate cache implementation
- * using {@link #with(TemplateCache cache) with}.
+ * Compile the resource located at the given uri. The implementation uses a cache for previously
+ * compiled Templates. By default, if the resource has been compiled previously, and no changes
+ * have occurred since in the resource, compilation will be skipped and the previously created
+ * Template will be returned. You can set an alternate cache implementation using {@link
+ * #with(TemplateCache cache) with}.
*
* @param location The resource's location. Required.
* @param startDelimiter The start delimiter. Required.
@@ -495,17 +444,17 @@ public Template compile(final String location) throws IOException {
* @return A compiled template.
* @throws IOException If the resource cannot be loaded.
*/
- public Template compile(final String location, final String startDelimiter,
- final String endDelimiter) throws IOException {
+ public Template compile(
+ final String location, final String startDelimiter, final String endDelimiter)
+ throws IOException {
return compile(loader.sourceAt(location), startDelimiter, endDelimiter);
}
/**
- * Compile a handlebars template.
- * The implementation uses a cache for previously compiled Templates. By default,
- * if same input string has been compiled previously, compilation will be skipped
- * and the previously created Template will be returned. You can set an alternate
- * cache implementation using {@link #with(TemplateCache cache) with}.
+ * Compile a handlebars template. The implementation uses a cache for previously compiled
+ * Templates. By default, if same input string has been compiled previously, compilation will be
+ * skipped and the previously created Template will be returned. You can set an alternate cache
+ * implementation using {@link #with(TemplateCache cache) with}.
*
* @param input The handlebars input. Required.
* @return A compiled template.
@@ -516,11 +465,10 @@ public Template compileInline(final String input) throws IOException {
}
/**
- * Compile a handlebars template.
- * The implementation uses a cache for previously compiled Templates. By default,
- * if same input string has been compiled previously, compilation will be skipped
- * and the previously created Template will be returned. You can set an alternate
- * cache implementation using {@link #with(TemplateCache cache) with}.
+ * Compile a handlebars template. The implementation uses a cache for previously compiled
+ * Templates. By default, if same input string has been compiled previously, compilation will be
+ * skipped and the previously created Template will be returned. You can set an alternate cache
+ * implementation using {@link #with(TemplateCache cache) with}.
*
* @param input The input text. Required.
* @param startDelimiter The start delimiter. Required.
@@ -528,21 +476,20 @@ public Template compileInline(final String input) throws IOException {
* @return A compiled template.
* @throws IOException If the resource cannot be loaded.
*/
- public Template compileInline(final String input, final String startDelimiter,
- final String endDelimiter) throws IOException {
+ public Template compileInline(
+ final String input, final String startDelimiter, final String endDelimiter)
+ throws IOException {
notNull(input, "The input is required.");
String filename = "inline@" + Integer.toHexString(Math.abs(input.hashCode()));
- return compile(new StringTemplateSource(filename, input),
- startDelimiter, endDelimiter);
+ return compile(new StringTemplateSource(filename, input), startDelimiter, endDelimiter);
}
/**
- * Compile a handlebars template.
- * The implementation uses a cache for previously compiled Templates. By default,
- * if the resource has been compiled previously, and no changes have occurred
- * since in the resource, compilation will be skipped and the previously created
- * Template will be returned. You can set an alternate cache implementation
- * using {@link #with(TemplateCache cache) with}.
+ * Compile a handlebars template. The implementation uses a cache for previously compiled
+ * Templates. By default, if the resource has been compiled previously, and no changes have
+ * occurred since in the resource, compilation will be skipped and the previously created Template
+ * will be returned. You can set an alternate cache implementation using {@link
+ * #with(TemplateCache cache) with}.
*
* @param source The template source. Required.
* @return A handlebars template.
@@ -553,12 +500,11 @@ public Template compile(final TemplateSource source) throws IOException {
}
/**
- * Compile a handlebars template.
- * The implementation uses a cache for previously compiled Templates. By default,
- * if the resource has been compiled previously, and no changes have occurred
- * since in the resource, compilation will be skipped and the previously created
- * Template will be returned. You can set an alternate cache implementation
- * using {@link #with(TemplateCache cache) with}.
+ * Compile a handlebars template. The implementation uses a cache for previously compiled
+ * Templates. By default, if the resource has been compiled previously, and no changes have
+ * occurred since in the resource, compilation will be skipped and the previously created Template
+ * will be returned. You can set an alternate cache implementation using {@link
+ * #with(TemplateCache cache) with}.
*
* @param source The template source. Required.
* @param startDelimiter The start delimiter. Required.
@@ -566,8 +512,9 @@ public Template compile(final TemplateSource source) throws IOException {
* @return A handlebars template.
* @throws IOException If the resource cannot be loaded.
*/
- public Template compile(final TemplateSource source, final String startDelimiter,
- final String endDelimiter) throws IOException {
+ public Template compile(
+ final TemplateSource source, final String startDelimiter, final String endDelimiter)
+ throws IOException {
notNull(source, "The template source is required.");
notEmpty(startDelimiter, "The start delimiter is required.");
notEmpty(endDelimiter, "The end delimiter is required.");
@@ -615,12 +562,9 @@ public Handlebars registerHelperMissing(final Helper helper) {
}
/**
- *
* Register all the helper methods for the given helper source.
- *
- *
- * A helper method looks like:
- *
+ *
+ *
A helper method looks like:
*
*
* public static? CharSequence methodName(context?, parameter*, options?) {
@@ -628,11 +572,12 @@ public Handlebars registerHelperMissing(final Helper helper) {
*
*
* Where:
+ *
*
- *
A method can/can't be static
- *
The method's name became the helper's name
- *
Context, parameters and options are all optional
- *
If context and options are present they must be the first and last method arguments.
+ *
A method can/can't be static
+ *
The method's name became the helper's name
+ *
Context, parameters and options are all optional
+ *
If context and options are present they must be the first and last method arguments.
*
*
* Instance and static methods will be registered as helpers.
@@ -647,12 +592,9 @@ public Handlebars registerHelpers(final Object helperSource) {
}
/**
- *
* Register all the helper methods for the given helper source.
- *
- *
- * A helper method looks like:
- *
+ *
+ *
A helper method looks like:
*
*
* public static? CharSequence methodName(context?, parameter*, options?) {
@@ -660,17 +602,17 @@ public Handlebars registerHelpers(final Object helperSource) {
*
*
* Where:
+ *
*
- *
A method can/can't be static
- *
The method's name became the helper's name
- *
Context, parameters and options are all optional
- *
If context and options are present they must be the first and last method arguments.
+ *
A method can/can't be static
+ *
The method's name became the helper's name
+ *
Context, parameters and options are all optional
+ *
If context and options are present they must be the first and last method arguments.
*
*
* Only static methods will be registered as helpers.
- *
- * Enums are supported too
- *
+ *
+ *
Enums are supported too
*
* @param helperSource The helper source. Enums are supported. Required.
* @return This handlebars object.
@@ -682,12 +624,9 @@ public Handlebars registerHelpers(final Class> helperSource) {
}
/**
- *
* Register helpers from a JavaScript source.
- *
- *
- * A JavaScript source file looks like:
- *
+ *
+ *
A JavaScript source file looks like:
*
*
* Handlebars.registerHelper('hey', function (context) {
@@ -717,12 +656,9 @@ public Handlebars registerHelpers(final URI location) throws Exception {
}
/**
- *
* Handlebars.registerHelper('hey', function (context) {
@@ -788,12 +721,9 @@ public Handlebars registerHelpers(final String filename, final Reader source) th
}
/**
- *
* Register helpers from a JavaScript source.
- *
- *
- * A JavaScript source file looks like:
- *
+ *
+ *
A JavaScript source file looks like:
*
*
* Handlebars.registerHelper('hey', function (context) {
@@ -825,12 +755,9 @@ public Handlebars registerHelpers(final String filename, final InputStream sourc
}
/**
- *
* Register helpers from a JavaScript source.
- *
- *
- * A JavaScript source file looks like:
- *
+ *
+ *
A JavaScript source file looks like:
*
*
* Handlebars.registerHelper('hey', function (context) {
@@ -905,7 +832,7 @@ public boolean stringParams() {
* If true, unnecessary spaces and new lines will be removed from output. Default is: false.
*
* @return If true, unnecessary spaces and new lines will be removed from output. Default is:
- * false.
+ * false.
*/
public boolean prettyPrint() {
return prettyPrint;
@@ -915,7 +842,7 @@ public boolean prettyPrint() {
* If true, unnecessary spaces and new lines will be removed from output. Default is: false.
*
* @param prettyPrint If true, unnecessary spaces and new lines will be removed from output.
- * Default is: false.
+ * Default is: false.
*/
public void setPrettyPrint(final boolean prettyPrint) {
this.prettyPrint = prettyPrint;
@@ -925,7 +852,7 @@ public void setPrettyPrint(final boolean prettyPrint) {
* If true, unnecessary spaces and new lines will be removed from output. Default is: false.
*
* @param prettyPrint If true, unnecessary spaces and new lines will be removed from output.
- * Default is: false.
+ * Default is: false.
* @return This handlebars object.
*/
public Handlebars prettyPrint(final boolean prettyPrint) {
@@ -936,8 +863,7 @@ public Handlebars prettyPrint(final boolean prettyPrint) {
/**
* If true, missing helper parameters will be resolve to their names.
*
- * @param stringParams If true, missing helper parameters will be resolve to
- * their names.
+ * @param stringParams If true, missing helper parameters will be resolve to their names.
*/
public void setStringParams(final boolean stringParams) {
this.stringParams = stringParams;
@@ -946,8 +872,7 @@ public void setStringParams(final boolean stringParams) {
/**
* If true, missing helper parameters will be resolve to their names.
*
- * @param stringParams If true, missing helper parameters will be resolve to
- * their names.
+ * @param stringParams If true, missing helper parameters will be resolve to their names.
* @return The handlebars object.
*/
public Handlebars stringParams(final boolean stringParams) {
@@ -960,7 +885,7 @@ public Handlebars stringParams(final boolean stringParams) {
* Default is: false.
*
* @return If true, templates will be able to call him self directly or indirectly. Use with
- * caution. Default is: false.
+ * caution. Default is: false.
*/
public boolean infiniteLoops() {
return infiniteLoops;
@@ -970,8 +895,7 @@ public boolean infiniteLoops() {
* If true, templates will be able to call him self directly or indirectly. Use with caution.
* Default is: false.
*
- * @param infiniteLoops If true, templates will be able to call him self directly or
- * indirectly.
+ * @param infiniteLoops If true, templates will be able to call him self directly or indirectly.
*/
public void setInfiniteLoops(final boolean infiniteLoops) {
this.infiniteLoops = infiniteLoops;
@@ -981,8 +905,7 @@ public void setInfiniteLoops(final boolean infiniteLoops) {
* If true, templates will be able to call him self directly or indirectly. Use with caution.
* Default is: false.
*
- * @param infiniteLoops If true, templates will be able to call him self directly or
- * indirectly.
+ * @param infiniteLoops If true, templates will be able to call him self directly or indirectly.
* @return The handlebars object.
*/
public Handlebars infiniteLoops(final boolean infiniteLoops) {
@@ -992,15 +915,15 @@ public Handlebars infiniteLoops(final boolean infiniteLoops) {
/**
* If true, templates will be deleted once applied. Useful, in some advanced template inheritance
- * use cases. Used by {{#block}} helper. Default is: false.
- * At any time you can override the default setup with:
+ * use cases. Used by {{#block}} helper. Default is: false. At any time you can
+ * override the default setup with:
*
*
* {{#block "footer" delete-after-merge=true}}
*
*
- * @return True for clearing up templates once they got applied. Used by
- * {{#block}} helper.
+ * @return True for clearing up templates once they got applied. Used by {{#block}} helper
+ * .
*/
public boolean deletePartialAfterMerge() {
return deletePartialAfterMerge;
@@ -1008,16 +931,15 @@ public boolean deletePartialAfterMerge() {
/**
* If true, templates will be deleted once applied. Useful, in some advanced template inheritance
- * use cases. Used by {{#block}} helper. Default is: false.
- * At any time you can override the default setup with:
+ * use cases. Used by {{#block}} helper. Default is: false. At any time you can
+ * override the default setup with:
*
*
* {{#block "footer" delete-after-merge=true}}
*
*
* @param deletePartialAfterMerge True for clearing up templates once they got applied. Used by
- * {{#block}} helper.
- *
+ * {{#block}} helper.
* @return This handlebars object.
*/
public Handlebars deletePartialAfterMerge(final boolean deletePartialAfterMerge) {
@@ -1027,15 +949,15 @@ public Handlebars deletePartialAfterMerge(final boolean deletePartialAfterMerge)
/**
* If true, templates will be deleted once applied. Useful, in some advanced template inheritance
- * use cases. Used by {{#block}} helper. Default is: false.
- * At any time you can override the default setup with:
+ * use cases. Used by {{#block}} helper. Default is: false. At any time you can
+ * override the default setup with:
*
*
* {{#block "footer" delete-after-merge=true}}
*
*
* @param deletePartialAfterMerge True for clearing up templates once they got applied. Used by
- * {{#block}} helper.
+ * {{#block}} helper.
*/
public void setDeletePartialAfterMerge(final boolean deletePartialAfterMerge) {
this.deletePartialAfterMerge = deletePartialAfterMerge;
@@ -1155,8 +1077,7 @@ public Handlebars with(final HelperRegistry registry) {
* @return This handlebars object.
*/
public Handlebars with(final EscapingStrategy escapingStrategy) {
- this.escapingStrategy = notNull(escapingStrategy,
- "The escaping strategy is required.");
+ this.escapingStrategy = notNull(escapingStrategy, "The escaping strategy is required.");
return this;
}
@@ -1185,12 +1106,12 @@ public Formatter.Chain getFormatter() {
* Handlebars hbs = new Handlebars();
*
* hbs.with(new Formatter() {
- * public Object format(Object value, Chain next) {
- * if (value instanceof Date) {
- * return ((Date) value).getTime();
- * }
- * return next.format(value);
- * }
+ * public Object format(Object value, Chain next) {
+ * if (value instanceof Date) {
+ * return ((Date) value).getTime();
+ * }
+ * return next.format(value);
+ * }
* });
*
*
@@ -1210,21 +1131,17 @@ public Handlebars with(final Formatter formatter) {
/**
* Set the handlebars.js location used it to compile/precompile template to JavaScript.
- *
- * Using handlebars.js 4.x:
- *
+ *
+ *
Using handlebars.js 4.x:
*
*
- * Handlebars handlebars = new Handlebars()
- * .handlebarsJsFile("handlebars-v4.0.4.js");
+ * Handlebars handlebars = new Handlebars().handlebarsJsFile("handlebars-v4.0.4.js");
*
- *
- * Using handlebars.js 1.x:
- *
+ *
+ *
Using handlebars.js 1.x:
*
*
- * Handlebars handlebars = new Handlebars()
- * .handlebarsJsFile("handlebars-v1.3.0.js");
+ * Handlebars handlebars = new Handlebars().handlebarsJsFile("handlebars-v1.3.0.js");
*
*
* Default handlebars.js is handlebars-v4.0.4.js.
@@ -1245,8 +1162,8 @@ public Handlebars handlebarsJsFile(final String location) {
}
/**
- * @return Classpath location of the handlebars.js file. Default is:
- * handlebars-v4.0.4.js
+ * @return Classpath location of the handlebars.js file. Default is: handlebars-v4.0.4.js
+ *
*/
public String handlebarsJsFile() {
return handlebarsJsFile;
@@ -1254,7 +1171,7 @@ public String handlebarsJsFile() {
/**
* @return True, if we want to extend lookup to parent scope, like Mustache Spec. Or false, if
- * lookup is restricted to current scope, like handlebars.js.
+ * lookup is restricted to current scope, like handlebars.js.
*/
public boolean parentScopeResolution() {
return parentScopeResolution;
@@ -1262,6 +1179,7 @@ public boolean parentScopeResolution() {
/**
* Given:
+ *
*
*
- * Handlebars.java will output: Hello Favre Brett while handlebars.js:
- * Hello Favre.
+ * Handlebars.java will output: Hello Favre Brett while handlebars.js:
+ * Hello Favre.
*
- * Why? Handlebars.java is a 100% Mustache implementation while handlebars.js isn't.
+ *
Why? Handlebars.java is a 100% Mustache implementation while handlebars.js isn't.
*
- * This option forces Handlebars.java mimics handlebars.js behavior:
+ *
This option forces Handlebars.java mimics handlebars.js behavior:
*
*
- * Handlebars hbs = new Handlebars()
- * .parentScopeResolution(true);
+ * Handlebars hbs = new Handlebars().parentScopeResolution(true);
*
*
* Outputs: Hello Favre.
*
- *
* @param parentScopeResolution False, if we want to restrict lookup to current scope (like in
- * handlebars.js). Default is true
+ * handlebars.js). Default is true
* @return This handlebars.
*/
public Handlebars parentScopeResolution(final boolean parentScopeResolution) {
@@ -1329,57 +1244,57 @@ public Handlebars parentScopeResolution(final boolean parentScopeResolution) {
}
/**
- * If true, partial blocks will implicitly be evaluated before the partials will actually
- * be executed. If false, you need to explicitly evaluate and render partial blocks with
+ * If true, partial blocks will implicitly be evaluated before the partials will actually be
+ * executed. If false, you need to explicitly evaluate and render partial blocks with
+ *
*
- * Attention: If this is set to true, Handlebars works *much* slower! while rendering
- * partial blocks. Default is: true for compatibility reasons.
*
- * @return If true partial blocks will be evaluated before the partial will be rendered
- * to allow inline block side effects.
- * If false, you will have to evaluate and render partial blocks explitly (this
- * option is *much* faster).
+ * Attention: If this is set to true, Handlebars works *much* slower! while rendering partial
+ * blocks. Default is: true for compatibility reasons.
+ *
+ * @return If true partial blocks will be evaluated before the partial will be rendered to allow
+ * inline block side effects. If false, you will have to evaluate and render partial blocks
+ * explitly (this option is *much* faster).
*/
public boolean preEvaluatePartialBlocks() {
return preEvaluatePartialBlocks;
}
/**
- * If true, partial blocks will implicitly be evaluated before the partials will actually
- * be executed. If false, you need to explicitly evaluate and render partial blocks with
+ * If true, partial blocks will implicitly be evaluated before the partials will actually be
+ * executed. If false, you need to explicitly evaluate and render partial blocks with
+ *
*
- * Attention: If this is set to true, Handlebars works *much* slower! while rendering
- * partial blocks. Default is: true for compatibility reasons.
*
- * @param preEvaluatePartialBlocks If true partial blocks will be evaluated before the
- * partial will be rendered to allow inline block side
- * effects.
- * If false, you will have to evaluate and render partial
- * blocks explitly (this option is *much* faster).
+ * Attention: If this is set to true, Handlebars works *much* slower! while rendering partial
+ * blocks. Default is: true for compatibility reasons.
+ *
+ * @param preEvaluatePartialBlocks If true partial blocks will be evaluated before the partial
+ * will be rendered to allow inline block side effects. If false, you will have to evaluate
+ * and render partial blocks explitly (this option is *much* faster).
*/
public void setPreEvaluatePartialBlocks(final boolean preEvaluatePartialBlocks) {
this.preEvaluatePartialBlocks = preEvaluatePartialBlocks;
}
/**
- * If true, partial blocks will implicitly be evaluated before the partials will actually
- * be executed. If false, you need to explicitly evaluate and render partial blocks with
+ * If true, partial blocks will implicitly be evaluated before the partials will actually be
+ * executed. If false, you need to explicitly evaluate and render partial blocks with
*
*
- * Attention: If this is set to true, Handlebars works *much* slower! while rendering
- * partial blocks. Default is: true for compatibility reasons.
- *
- * @param preEvaluatePartialBlocks If true partial blocks will be evaluated before the
- * partial will be rendered to allow inline block side
- * effects.
- * If false, you will have to evaluate and render partial
- * blocks explitly (this option is *much* faster).
+ *
+ * Attention: If this is set to true, Handlebars works *much* slower! while rendering partial
+ * blocks. Default is: true for compatibility reasons.
+ *
+ * @param preEvaluatePartialBlocks If true partial blocks will be evaluated before the partial
+ * will be rendered to allow inline block side effects. If false, you will have to evaluate
+ * and render partial blocks explitly (this option is *much* faster).
* @return The Handlebars object
*/
public Handlebars preEvaluatePartialBlocks(final boolean preEvaluatePartialBlocks) {
@@ -1470,7 +1385,6 @@ public static void debug(final String message) {
* @param args The optional args.
* @see String#format(String, Object...)
*/
-
public static void error(final String message, final Object... args) {
logger.error(String.format(message, args));
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/HandlebarsError.java b/handlebars/src/main/java/com/github/jknack/handlebars/HandlebarsError.java
index 0c6e33efe..bd2faf752 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/HandlebarsError.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/HandlebarsError.java
@@ -1,27 +1,15 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
-import java.io.Serializable;
-
import static org.apache.commons.lang3.Validate.isTrue;
import static org.apache.commons.lang3.Validate.notEmpty;
+import java.io.Serializable;
+
/**
* Useful information about a handlebar error.
*
@@ -30,34 +18,22 @@
*/
public class HandlebarsError implements Serializable {
- /**
- * The error's line number.
- */
+ /** The error's line number. */
public final int line;
- /**
- * The error's column number.
- */
+ /** The error's column number. */
public final int column;
- /**
- * The error's problem.
- */
+ /** The error's problem. */
public final String reason;
- /**
- * The error's evidence.
- */
+ /** The error's evidence. */
public final String evidence;
- /**
- * The file's name.
- */
+ /** The file's name. */
public final String filename;
- /**
- * The full error's message.
- */
+ /** The full error's message. */
public final String message;
/**
@@ -70,8 +46,12 @@ public class HandlebarsError implements Serializable {
* @param evidence The error's evidence. Required.
* @param message The error's message. Required.
*/
- public HandlebarsError(final String filename, final int line,
- final int column, final String reason, final String evidence,
+ public HandlebarsError(
+ final String filename,
+ final int line,
+ final int column,
+ final String reason,
+ final String evidence,
final String message) {
this.filename = notEmpty(filename, "The file's name is required");
isTrue(line > 0, "The error's line number must be greater than zero");
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/HandlebarsException.java b/handlebars/src/main/java/com/github/jknack/handlebars/HandlebarsException.java
index efa582ffe..6e329a5d3 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/HandlebarsException.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/HandlebarsException.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -25,14 +13,10 @@
*/
public class HandlebarsException extends RuntimeException {
- /**
- * The serial UUID.
- */
+ /** The serial UUID. */
private static final long serialVersionUID = -294368972176956335L;
- /**
- * A handlebars error. Optional.
- */
+ /** A handlebars error. Optional. */
private HandlebarsError error;
/**
@@ -60,8 +44,7 @@ public HandlebarsException(final Throwable cause) {
* @param error The error's message.
* @param cause The error's cause.
*/
- public HandlebarsException(final HandlebarsError error,
- final Throwable cause) {
+ public HandlebarsException(final HandlebarsError error, final Throwable cause) {
super(error.message, cause);
this.error = error;
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Helper.java b/handlebars/src/main/java/com/github/jknack/handlebars/Helper.java
index a8b53d34a..d2a7e89e7 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Helper.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Helper.java
@@ -1,28 +1,15 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
import java.io.IOException;
/**
- * Handlebars helpers can be accessed from any context in a template. You can
- * register a helper with the {@link Handlebars#registerHelper(String, Helper)}
- * method.
+ * Handlebars helpers can be accessed from any context in a template. You can register a helper with
+ * the {@link Handlebars#registerHelper(String, Helper)} method.
*
* @author edgar.espina
* @param The context object.
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/HelperRegistry.java b/handlebars/src/main/java/com/github/jknack/handlebars/HelperRegistry.java
index b7d266080..5f80617fa 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/HelperRegistry.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/HelperRegistry.java
@@ -1,33 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * This copy of Woodstox XML processor is licensed under the
- * Apache (Software) License, version 2.0 ("the License").
- * See the License for details about distribution rights, and the
- * specific rights regarding derivate works.
- *
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/
- *
- * A copy is also included in the downloadable source code package
- * containing Woodstox, in file "ASL2.0", under the same directory
- * as this file.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -48,9 +22,7 @@
*/
public interface HelperRegistry {
- /**
- * The missing helper's name.
- */
+ /** The missing helper's name. */
String HELPER_MISSING = "helperMissing";
/**
@@ -89,12 +61,9 @@ public interface HelperRegistry {
HelperRegistry registerHelperMissing(Helper helper);
/**
- *
* Register all the helper methods for the given helper source.
- *
- *
- * A helper method looks like:
- *
+ *
+ *
A helper method looks like:
*
*
* public static? CharSequence methodName(context?, parameter*, options?) {
@@ -102,11 +71,12 @@ public interface HelperRegistry {
*
*
* Where:
+ *
*
- *
A method can/can't be static
- *
The method's name became the helper's name
- *
Context, parameters and options are all optional
- *
If context and options are present they must be the first and last method arguments.
+ *
A method can/can't be static
+ *
The method's name became the helper's name
+ *
Context, parameters and options are all optional
+ *
If context and options are present they must be the first and last method arguments.
*
*
* Instance and static methods will be registered as helpers.
@@ -117,12 +87,9 @@ public interface HelperRegistry {
HelperRegistry registerHelpers(Object helperSource);
/**
- *
* Register all the helper methods for the given helper source.
- *
- *
- * A helper method looks like:
- *
+ *
+ *
A helper method looks like:
*
*
* public static? CharSequence methodName(context?, parameter*, options?) {
@@ -130,17 +97,17 @@ public interface HelperRegistry {
*
*
* Where:
+ *
*
- *
A method can/can't be static
- *
The method's name became the helper's name
- *
Context, parameters and options are all optional
- *
If context and options are present they must be the first and last method arguments.
+ *
A method can/can't be static
+ *
The method's name became the helper's name
+ *
Context, parameters and options are all optional
+ *
If context and options are present they must be the first and last method arguments.
*
*
* Only static methods will be registered as helpers.
- *
- * Enums are supported too
- *
+ *
+ *
Enums are supported too
*
* @param helperSource The helper source. Enums are supported. Required.
* @return This handlebars object.
@@ -148,12 +115,9 @@ public interface HelperRegistry {
HelperRegistry registerHelpers(Class> helperSource);
/**
- *
* Handlebars.registerHelper('hey', function (context) {
@@ -271,16 +226,12 @@ public interface HelperRegistry {
* @return This handlebars object.
* @throws Exception If the JavaScript helpers can't be registered.
*/
- HelperRegistry registerHelpers(String filename, InputStream source)
- throws Exception;
+ HelperRegistry registerHelpers(String filename, InputStream source) throws Exception;
/**
- *
* Register helpers from a JavaScript source.
- *
- *
- * A JavaScript source file looks like:
- *
+ *
+ *
A JavaScript source file looks like:
*
*
* Handlebars.registerHelper('hey', function (context) {
@@ -333,5 +284,4 @@ HelperRegistry registerHelpers(String filename, InputStream source)
* @since 4.0.6
*/
HelperRegistry setCharset(Charset charset);
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Lambda.java b/handlebars/src/main/java/com/github/jknack/handlebars/Lambda.java
index 89b029705..49e20b8a2 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Lambda.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Lambda.java
@@ -1,34 +1,19 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
import java.io.IOException;
/**
- *
- * When the value is a callable object, such as a lambda, the object will be
- * invoked and passed the block of text. The text passed is the literal block,
- * unrendered. {{tags}} will not have been expanded - the lambda should do that
- * on its own. In this way you can implement filters or caching.
- *
- *
- * Template:
- *
+ * When the value is a callable object, such as a lambda, the object will be invoked and passed the
+ * block of text. The text passed is the literal block, unrendered. {{tags}} will not have been
+ * expanded - the lambda should do that on its own. In this way you can implement filters or
+ * caching.
+ *
+ *
Template:
*
*
* {{#wrapped}}
@@ -47,9 +32,8 @@
* }
* });
*
- *
- * Output:
- *
+ *
+ *
Output:
*
*
* Willy is awesome.
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Options.java b/handlebars/src/main/java/com/github/jknack/handlebars/Options.java
index 5635d9127..ffa5d1b42 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Options.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Options.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -27,21 +15,16 @@
import java.util.Set;
/**
- * Options available for {@link Helper#apply(Object, Options)}.
- * Usage:
+ * Options available for {@link Helper#apply(Object, Options)}. Usage:
*
*
*
* @author edgar.espina
@@ -55,12 +38,11 @@ public class Options {
* @author edgar
* @since 2.3.2
*/
- public interface Buffer extends Appendable, CharSequence {
- }
+ public interface Buffer extends Appendable, CharSequence {}
/**
- * This buffer will write into the underlying writer. It won't be any visible output and
- * {@link #toString()} returns an empty string.
+ * This buffer will write into the underlying writer. It won't be any visible output and {@link
+ * #toString()} returns an empty string.
*
* @author edgar
* @since 2.3.2
@@ -165,7 +147,6 @@ public char charAt(final int index) {
public CharSequence subSequence(final int start, final int end) {
return buffer.subSequence(start, end);
}
-
}
/**
@@ -175,42 +156,28 @@ public CharSequence subSequence(final int start, final int end) {
* @since 0.9.0
*/
public static class Builder {
- /**
- * The {@link Handlebars} object. Not null.
- */
+ /** The {@link Handlebars} object. Not null. */
private Handlebars handlebars;
- /**
- * The current context. Not null.
- */
+ /** The current context. Not null. */
private Context context;
- /**
- * The current template. Not null.
- */
+ /** The current template. Not null. */
private Template fn;
- /**
- * The current inverse template. Not null.
- */
+ /** The current inverse template. Not null. */
private Template inverse = Template.EMPTY;
/** Empty params. */
private static Object[] EMPTY_PARAMS = {};
- /**
- * The parameters. Not null.
- */
+ /** The parameters. Not null. */
private Object[] params = EMPTY_PARAMS;
- /**
- * The hash options. Not null.
- */
+ /** The hash options. Not null. */
private Map hash = Collections.emptyMap();
- /**
- * The {@link TagType} from where the helper was called.
- */
+ /** The {@link TagType} from where the helper was called. */
private TagType tagType;
/** The name of the helper. */
@@ -231,8 +198,12 @@ public static class Builder {
* @param context A context object. Required.
* @param fn A template object. Required.
*/
- public Builder(final Handlebars handlebars, final String helperName, final TagType tagType,
- final Context context, final Template fn) {
+ public Builder(
+ final Handlebars handlebars,
+ final String helperName,
+ final TagType tagType,
+ final Context context,
+ final Template fn) {
this.handlebars = handlebars;
this.helperName = helperName;
this.tagType = tagType;
@@ -246,8 +217,9 @@ public Builder(final Handlebars handlebars, final String helperName, final TagTy
* @return A new {@link Options} object.
*/
public Options build() {
- Options options = new Options(handlebars, helperName, tagType, context, fn, inverse, params,
- hash, blockParams);
+ Options options =
+ new Options(
+ handlebars, helperName, tagType, context, fn, inverse, params, hash, blockParams);
options.writer = writer;
// clear out references
handlebars = null;
@@ -315,42 +287,27 @@ public Builder setWriter(final Writer writer) {
this.writer = writer;
return this;
}
-
}
- /**
- * The {@link Handlebars} object. Not null.
- */
+ /** The {@link Handlebars} object. Not null. */
public final Handlebars handlebars;
- /**
- * The current context. Not null.
- */
+ /** The current context. Not null. */
public final Context context;
- /**
- * The current template. Not null.
- */
+ /** The current template. Not null. */
public final Template fn;
- /**
- * The current inverse template. Not null.
- */
+ /** The current inverse template. Not null. */
public final Template inverse;
- /**
- * The parameters. Not null.
- */
+ /** The parameters. Not null. */
public final Object[] params;
- /**
- * The hash options. Not null.
- */
+ /** The hash options. Not null. */
public final Map hash;
- /**
- * The {@link TagType} from where the helper was called.
- */
+ /** The {@link TagType} from where the helper was called. */
public final TagType tagType;
/** The name of the helper. */
@@ -378,9 +335,16 @@ public Builder setWriter(final Writer writer) {
* @param hash The optional hash. Required.
* @param blockParams The block param names. Required.
*/
- public Options(final Handlebars handlebars, final String helperName, final TagType tagType,
- final Context context, final Template fn, final Template inverse, final Object[] params,
- final Map hash, final List blockParams) {
+ public Options(
+ final Handlebars handlebars,
+ final String helperName,
+ final TagType tagType,
+ final Context context,
+ final Template fn,
+ final Template inverse,
+ final Object[] params,
+ final Map hash,
+ final List blockParams) {
this.handlebars = handlebars;
this.helperName = helperName;
this.tagType = tagType;
@@ -407,9 +371,17 @@ public Options(final Handlebars handlebars, final String helperName, final TagTy
* @param blockParams The block param names. Required.
* @param writer A writer. Optional.
*/
- public Options(final Handlebars handlebars, final String helperName, final TagType tagType,
- final Context context, final Template fn, final Template inverse, final Object[] params,
- final Map hash, final List blockParams, final Writer writer) {
+ public Options(
+ final Handlebars handlebars,
+ final String helperName,
+ final TagType tagType,
+ final Context context,
+ final Template fn,
+ final Template inverse,
+ final Object[] params,
+ final Map hash,
+ final List blockParams,
+ final Writer writer) {
this.handlebars = handlebars;
this.helperName = helperName;
this.tagType = tagType;
@@ -492,8 +464,8 @@ public CharSequence inverse(final Context context) throws IOException {
}
/**
- * Apply the given template to the provided context. The context stack is
- * propagated allowing the access to the whole stack.
+ * Apply the given template to the provided context. The context stack is propagated allowing the
+ * access to the whole stack.
*
* @param template The template.
* @param context The context object.
@@ -506,8 +478,8 @@ public CharSequence apply(final Template template, final Object context) throws
}
/**
- * Apply the given template to the provided context. The context stack is
- * propagated allowing the access to the whole stack.
+ * Apply the given template to the provided context. The context stack is propagated allowing the
+ * access to the whole stack.
*
* @param template The template.
* @param context The context object.
@@ -520,8 +492,8 @@ public CharSequence apply(final Template template, final Context context) throws
}
/**
- * Apply the given template to the provided context. The context stack is
- * propagated allowing the access to the whole stack.
+ * Apply the given template to the provided context. The context stack is propagated allowing the
+ * access to the whole stack.
*
* @param template The template.
* @param context The context object.
@@ -529,8 +501,9 @@ public CharSequence apply(final Template template, final Context context) throws
* @return The resulting text.
* @throws IOException If a resource cannot be loaded.
*/
- public CharSequence apply(final Template template, final Context context,
- final List blockParams) throws IOException {
+ public CharSequence apply(
+ final Template template, final Context context, final List blockParams)
+ throws IOException {
Context ctx = context;
if (hasBlockParams) {
ctx = Context.newBlockParamContext(context, this.blockParams, blockParams);
@@ -539,8 +512,8 @@ public CharSequence apply(final Template template, final Context context,
}
/**
- * Apply the given template to the provided context. The context stack is
- * propagated allowing the access to the whole stack.
+ * Apply the given template to the provided context. The context stack is propagated allowing the
+ * access to the whole stack.
*
* @param template The template.
* @param context The context object.
@@ -548,14 +521,15 @@ public CharSequence apply(final Template template, final Context context,
* @return The resulting text.
* @throws IOException If a resource cannot be loaded.
*/
- public CharSequence apply(final Template template, final Object context,
- final List blockParams) throws IOException {
+ public CharSequence apply(
+ final Template template, final Object context, final List blockParams)
+ throws IOException {
return apply(template, wrap(context), blockParams);
}
/**
- * Apply the given template to the default context. The context stack is
- * propagated allowing the access to the whole stack.
+ * Apply the given template to the default context. The context stack is propagated allowing the
+ * access to the whole stack.
*
* @param template The template.
* @return The resulting text.
@@ -566,16 +540,11 @@ public CharSequence apply(final Template template) throws IOException {
}
/**
- *
- * Return a parameter at given index. This is analogous to:
- *
- *
+ * Return a parameter at given index. This is analogous to:
* Object param = options.params[index]
*
- *
- * The only difference is the type safe feature:
- *
- *
+ *
+ *
The only difference is the type safe feature:
* MyType param = options.param(index)
*
*
@@ -589,23 +558,17 @@ public T param(final int index) {
}
/**
- *
- * Return a parameter at given index. This is analogous to:
- *
- *
+ * Return a parameter at given index. This is analogous to:
* Object param = options.params[index]
*
- *
- * The only difference is the type safe feature:
- *
- *
+ *
+ *
The only difference is the type safe feature:
* MyType param = options.param(index)
*
*
* @param The runtime type.
* @param index The parameter position.
- * @param defaultValue The default value to return if the parameter is not
- * present or if null.
+ * @param defaultValue The default value to return if the parameter is not present or if null.
* @return The parameter's value.
*/
@SuppressWarnings("unchecked")
@@ -622,8 +585,7 @@ public T param(final int index, final T defaultValue) {
*
* @param The runtime type.
* @param name The property's name.
- * @param defaultValue The default value to return if the attribute is not
- * present or if null.
+ * @param defaultValue The default value to return if the attribute is not present or if null.
* @return The associated value or null if it's not found.
*/
public T get(final String name, final T defaultValue) {
@@ -647,8 +609,8 @@ public T get(final String name) {
* Return a previously registered partial in the current execution context.
*
* @param path The partial's path. Required.
- * @return A previously registered partial in the current execution context.
- * Or null if not found.
+ * @return A previously registered partial in the current execution context. Or null
+ * if not found.
*/
public Template partial(final String path) {
return partials().get(path);
@@ -665,16 +627,11 @@ public void partial(final String path, final Template partial) {
}
/**
- *
- * Find a value inside the {@link #hash} attributes. This is analogous to:
- *
- *
+ * Find a value inside the {@link #hash} attributes. This is analogous to:
* Object myClass = options.hash.get("class");
*
- *
- * This method works as a shorthand and type safe call:
- *
- *
+ *
+ *
This method works as a shorthand and type safe call:
* String myClass = options.hash("class");
*
*
@@ -687,16 +644,11 @@ public T hash(final String name) {
}
/**
- *
- * Find a value inside the {@link #hash} attributes. This is analogous to:
- *
- *
+ * Find a value inside the {@link #hash} attributes. This is analogous to:
* Object myClass = options.hash.get("class");
*
- *
- * This method works as a shorthand and type safe call:
- *
- *
+ *
+ *
This method works as a shorthand and type safe call:
* String myClass = options.hash("class");
*
*
@@ -712,24 +664,21 @@ public T hash(final String name, final Object defaultValue) {
}
/**
- * Returns false if its argument is false, null or empty list/array (a "falsy"
- * value).
+ * Returns false if its argument is false, null or empty list/array (a "falsy" value).
*
* @param value A value.
- * @return False if its argument is false, null or empty list/array (a "falsy"
- * value).
+ * @return False if its argument is false, null or empty list/array (a "falsy" value).
*/
public boolean isFalsy(final Object value) {
return Handlebars.Utils.isEmpty(value);
}
/**
- * Creates a {@link Context} from the given model. If the object is a context
- * already the same object will be returned.
+ * Creates a {@link Context} from the given model. If the object is a context already the same
+ * object will be returned.
*
* @param model The model object.
- * @return A context representing the model or the same model if it's a
- * context already.
+ * @return A context representing the model or the same model if it's a context already.
*/
public Context wrap(final Object model) {
if (model == context.model || model == context) {
@@ -742,12 +691,11 @@ public Context wrap(final Object model) {
}
/**
- * Creates a {@link Context} from the given model. If the object is a context
- * already the same object will be returned.
+ * Creates a {@link Context} from the given model. If the object is a context already the same
+ * object will be returned.
*
* @param context The model object.
- * @return A context representing the model or the same model if it's a
- * context already.
+ * @return A context representing the model or the same model if it's a context already.
*/
private Context wrap(final Context context) {
if (context != null) {
@@ -784,9 +732,8 @@ public void data(final String name, final Object value) {
* @return All the properties and their values for the given object.
*/
public Set> propertySet(final Object context) {
- return this.context.propertySet(context instanceof Context
- ? ((Context) context).model()
- : context);
+ return this.context.propertySet(
+ context instanceof Context ? ((Context) context).model() : context);
}
/**
@@ -830,7 +777,7 @@ public Buffer buffer() {
*/
private List blockParams(final Object context) {
if (this.blockParams.size() == 1) {
- return Arrays. asList(context);
+ return Arrays.asList(context);
}
return Collections.emptyList();
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Parser.java b/handlebars/src/main/java/com/github/jknack/handlebars/Parser.java
index 0663a67b5..7d0e1a0ee 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Parser.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Parser.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/ParserFactory.java b/handlebars/src/main/java/com/github/jknack/handlebars/ParserFactory.java
index 498865eaf..933aec15c 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/ParserFactory.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/ParserFactory.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/PathCompiler.java b/handlebars/src/main/java/com/github/jknack/handlebars/PathCompiler.java
index 9041b1ba9..e879e02b3 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/PathCompiler.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/PathCompiler.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -68,19 +56,21 @@ public final class PathCompiler {
private static Map> cache = new ConcurrentHashMap<>();
/** Split pattern. */
- private static Pattern pattern = Pattern
- .compile("((\\[[^\\[\\]]+])|"
- + "(" + Pattern.quote(PARENT_PATH) + ")|([^" + Pattern.quote(DOT_PATH) + "]+))");
+ private static Pattern pattern =
+ Pattern.compile(
+ "((\\[[^\\[\\]]+])|"
+ + "("
+ + Pattern.quote(PARENT_PATH)
+ + ")|([^"
+ + Pattern.quote(DOT_PATH)
+ + "]+))");
+
+ /** Not allowed. */
+ private PathCompiler() {}
/**
- * Not allowed.
- */
- private PathCompiler() {
- }
-
- /**
- * Split the property name by separator (except within a [] escaped blocked)
- * and create an array of it. The compiled expression will extend lookup to parent.
+ * Split the property name by separator (except within a [] escaped blocked) and create an array
+ * of it. The compiled expression will extend lookup to parent.
*
* @param key The property's name.
* @return A path representation of the property (array based).
@@ -90,15 +80,15 @@ public static List compile(final String key) {
}
/**
- * Split the property name by separator (except within a [] escaped blocked)
- * and create an array of it.
+ * Split the property name by separator (except within a [] escaped blocked) and create an array
+ * of it.
*
* @param key The property's name.
* @param parentScopeResolution False, if we want to restrict lookup to current scope.
* @return A path representation of the property (array based).
*/
- public static List compile(final String key,
- final boolean parentScopeResolution) {
+ public static List compile(
+ final String key, final boolean parentScopeResolution) {
boolean local = !parentScopeResolution;
String ukey = key + local;
List path = cache.get(ukey);
@@ -110,8 +100,8 @@ public static List compile(final String key,
}
/**
- * Split the property name by separator (except within a [] escaped blocked)
- * and create an array of it.
+ * Split the property name by separator (except within a [] escaped blocked) and create an array
+ * of it.
*
* @param path The property's path.
* @param local True, if we want to restrict lookup to current scope.
@@ -169,5 +159,4 @@ private static List parse(final String path, final boolean local
}
return resolvers;
}
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/PathExpression.java b/handlebars/src/main/java/com/github/jknack/handlebars/PathExpression.java
index efb562885..1420b1cf0 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/PathExpression.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/PathExpression.java
@@ -1,27 +1,15 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
import java.util.List;
/**
- * Compiled version of path expression, like: this, foo,
- * foo.bar.
+ * Compiled version of path expression, like: this, foo, foo.bar
+ * .
*
* @author edgar
* @since 4.0.1
@@ -66,8 +54,7 @@ interface Chain {
/**
* @return True if this expression is local. That's lookup won't be propagate to parent (or any
- * other). Example of these expressions are: this.namethis,
- * etc...
+ * other). Example of these expressions are: this.namethis, etc...
*/
boolean local();
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/TagType.java b/handlebars/src/main/java/com/github/jknack/handlebars/TagType.java
index 0ae19f627..2ba6eb0df 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/TagType.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/TagType.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -31,39 +19,33 @@ public enum TagType {
*/
VAR,
- /**
- * A var decorator tag, like: {{*name}}.
- */
+ /** A var decorator tag, like: {{*name}}. */
STAR_VAR,
/**
- * All variables are HTML escaped by default. If you want to return unescaped HTML, use the
- * triple mustache: {{{@literal &}name}}.
+ * All variables are HTML escaped by default. If you want to return unescaped HTML, use the triple
+ * mustache: {{{@literal &}name}}.
*/
AMP_VAR,
/**
- * All variables are HTML escaped by default. If you want to return unescaped HTML, use the
- * triple mustache: {{{name}}}.
+ * All variables are HTML escaped by default. If you want to return unescaped HTML, use the triple
+ * mustache: {{{name}}}.
*/
TRIPLE_VAR,
/**
- * Same as {@link #VAR} but can be invoked from inside a helper:
- * {{helper (subexpression)}}.
+ * Same as {@link #VAR} but can be invoked from inside a helper: {{helper (subexpression)}}
+ * .
*/
SUB_EXPRESSION,
/**
- *
* Sections render blocks of text one or more times, depending on the value of the key in the
* current context.
- *
*
- *
- * A section begins with a pound and ends with a slash. That is, {{#person}} begins a "person"
+ *
A section begins with a pound and ends with a slash. That is, {{#person}} begins a "person"
* section while {{/person}} ends it.
- *
*/
SECTION {
@Override
@@ -72,9 +54,7 @@ public boolean inline() {
}
},
- /**
- * Like {{#* decorator}}success{{/decorator}}.
- */
+ /** Like {{#* decorator}}success{{/decorator}}. */
START_SECTION {
@Override
public boolean inline() {
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Template.java b/handlebars/src/main/java/com/github/jknack/handlebars/Template.java
index 20ad53593..dd87aa1eb 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/Template.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/Template.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -30,83 +18,78 @@
*/
public interface Template {
- /**
- * An empty template implementation.
- */
- Template EMPTY = new Template() {
- @Override
- public String text() {
- return "";
- }
-
- @Override
- public String apply(final Object context) throws IOException {
- return "";
- }
-
- @Override
- public String apply(final Context context) throws IOException {
- return "";
- }
-
- @Override
- public void apply(final Context context, final Writer writer)
- throws IOException {
- }
-
- @Override
- public void apply(final Object context, final Writer writer)
- throws IOException {
- }
-
- @Override
- public String toJavaScript() {
- return "";
- }
-
- @Override
- public String filename() {
- return "";
- }
-
- @Override
- public int[] position() {
- return new int[]{0, 0 };
- }
-
- @SuppressWarnings({"rawtypes", "unchecked" })
- @Override
- public TypeSafeTemplate as() {
- TypeSafeTemplate template = as(TypeSafeTemplate.class);
- return template;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public > S as(final Class rootType) {
- TypeSafeTemplate template = new TypeSafeTemplate() {
+ /** An empty template implementation. */
+ Template EMPTY =
+ new Template() {
@Override
- public String apply(final T context) throws IOException {
+ public String text() {
return "";
}
@Override
- public void apply(final T context, final Writer writer) throws IOException {
+ public String apply(final Object context) throws IOException {
+ return "";
+ }
+
+ @Override
+ public String apply(final Context context) throws IOException {
+ return "";
+ }
+
+ @Override
+ public void apply(final Context context, final Writer writer) throws IOException {}
+
+ @Override
+ public void apply(final Object context, final Writer writer) throws IOException {}
+
+ @Override
+ public String toJavaScript() {
+ return "";
+ }
+
+ @Override
+ public String filename() {
+ return "";
+ }
+
+ @Override
+ public int[] position() {
+ return new int[] {0, 0};
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ @Override
+ public TypeSafeTemplate as() {
+ TypeSafeTemplate template = as(TypeSafeTemplate.class);
+ return template;
}
- };
- return (S) template;
- }
- @Override
- public List collect(final TagType... tagType) {
- return Collections.emptyList();
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public > S as(final Class rootType) {
+ TypeSafeTemplate template =
+ new TypeSafeTemplate() {
+ @Override
+ public String apply(final T context) throws IOException {
+ return "";
+ }
+
+ @Override
+ public void apply(final T context, final Writer writer) throws IOException {}
+ };
+ return (S) template;
+ }
- @Override
- public List collectReferenceParameters() {
- return Collections.emptyList();
- }
- };
+ @Override
+ public List collect(final TagType... tagType) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List collectReferenceParameters() {
+ return Collections.emptyList();
+ }
+ };
/**
* Merge the template tree using the given context.
@@ -179,25 +162,21 @@ public List collectReferenceParameters() {
/**
* Collect all the tag names under the given tagType.
- *
collect(TagType.VAR, TagType.TRIPLE_VAR) returns [hello, var, tripleVar]
+ *
*
* @param tagType The tag type. Required.
* @return A list with tag names.
@@ -206,17 +185,15 @@ public List collectReferenceParameters() {
/**
* Collects all the parameters which are also variables.
- *
collectReferenceParameters() returns [v1, v2]
*
* @return A list with reference parameter names.
*/
@@ -231,5 +208,4 @@ public List collectReferenceParameters() {
* @return The line and column where the template was found.
*/
int[] position();
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/TypeSafeTemplate.java b/handlebars/src/main/java/com/github/jknack/handlebars/TypeSafeTemplate.java
index fdb8a4be1..5707ff26b 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/TypeSafeTemplate.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/TypeSafeTemplate.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -23,9 +11,8 @@
/**
* Make handlebars templates type-safe. Users can extend the {@link TypeSafeTemplate} and add new
* methods.
- *
- * Usage:
- *
+ *
+ *
Usage:
*
*
* public interface UserTemplate extends TypeSafeTemplate<User> {
@@ -69,5 +56,4 @@ public interface TypeSafeTemplate {
* @throws IOException If a resource cannot be loaded.
*/
String apply(T context) throws IOException;
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java b/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java
index 156d98f12..40fb9ff2c 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/ValueResolver.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars;
@@ -36,33 +24,28 @@
*/
public interface ValueResolver {
- /**
- * A mark object.
- */
+ /** A mark object. */
Object UNRESOLVED = new Object();
/**
* Resolve the attribute's name in the context object. If a {@link #UNRESOLVED} is returned, the
- * {@link Context context stack} will
- * continue with the next value resolver in the chain.
+ * {@link Context context stack} will continue with the next value resolver in the chain.
*
* @param context The context object. Not null.
* @param name The attribute's name. Not null.
- * @return A {@link #UNRESOLVED} is returned, the {@link Context context
- * stack} will continue with the next value resolver in the chain.
- * Otherwise, it returns the associated value.
+ * @return A {@link #UNRESOLVED} is returned, the {@link Context context stack} will continue with
+ * the next value resolver in the chain. Otherwise, it returns the associated value.
*/
Object resolve(Object context, String name);
/**
- * Resolve the the context object by optionally converting the value if necessary.
- * If a {@link #UNRESOLVED} is returned, the {@link Context context stack} will continue with
- * the next value resolver in the chain.
+ * Resolve the the context object by optionally converting the value if necessary. If a {@link
+ * #UNRESOLVED} is returned, the {@link Context context stack} will continue with the next value
+ * resolver in the chain.
*
* @param context The context object. Not null.
- * @return A {@link #UNRESOLVED} is returned, the {@link Context context
- * stack} will continue with the next value resolver in the chain.
- * Otherwise, it returns the associated value.
+ * @return A {@link #UNRESOLVED} is returned, the {@link Context context stack} will continue with
+ * the next value resolver in the chain. Otherwise, it returns the associated value.
*/
Object resolve(Object context);
@@ -77,16 +60,18 @@ public interface ValueResolver {
/**
* Default value resolvers. Including:
*
- * - {@link MapValueResolver}
- * - {@link JavaBeanValueResolver}
- * - {@link MethodValueResolver}. On Java 14 or higher.
+ *
- {@link MapValueResolver} - {@link JavaBeanValueResolver} - {@link MethodValueResolver}. On
+ * Java 14 or higher.
*
* @return Immutable list of value resolvers.
*/
static List defaultValueResolvers() {
if (Handlebars.Utils.javaVersion14) {
- return unmodifiableList(asList(MapValueResolver.INSTANCE,
- JavaBeanValueResolver.INSTANCE, MethodValueResolver.INSTANCE));
+ return unmodifiableList(
+ asList(
+ MapValueResolver.INSTANCE,
+ JavaBeanValueResolver.INSTANCE,
+ MethodValueResolver.INSTANCE));
}
return unmodifiableList(asList(MapValueResolver.INSTANCE, JavaBeanValueResolver.INSTANCE));
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/cache/ConcurrentMapTemplateCache.java b/handlebars/src/main/java/com/github/jknack/handlebars/cache/ConcurrentMapTemplateCache.java
index 4425f61c3..3b0df0aa1 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/cache/ConcurrentMapTemplateCache.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/cache/ConcurrentMapTemplateCache.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.cache;
@@ -39,14 +27,10 @@
*/
public class ConcurrentMapTemplateCache implements TemplateCache {
- /**
- * The logging system.
- */
+ /** The logging system. */
private final Logger logger = LoggerFactory.getLogger(getClass());
- /**
- * The map cache.
- */
+ /** The map cache. */
private final ConcurrentMap> cache;
/** Turn on/off auto reloading of templates. */
@@ -62,9 +46,7 @@ protected ConcurrentMapTemplateCache(
this.cache = notNull(cache, "The cache is required.");
}
- /**
- * Creates a new ConcurrentMapTemplateCache.
- */
+ /** Creates a new ConcurrentMapTemplateCache. */
public ConcurrentMapTemplateCache() {
this(new ConcurrentHashMap>());
}
@@ -84,9 +66,7 @@ public Template get(final TemplateSource source, final Parser parser) throws IOE
notNull(source, "The source is required.");
notNull(parser, "The parser is required.");
- /**
- * Don't keep duplicated entries, remove old one if a change is detected.
- */
+ /** Don't keep duplicated entries, remove old one if a change is detected. */
return cacheGet(source, parser);
}
@@ -121,5 +101,4 @@ private Template cacheGet(final TemplateSource source, final Parser parser) thro
}
return entry.getValue();
}
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/cache/HighConcurrencyTemplateCache.java b/handlebars/src/main/java/com/github/jknack/handlebars/cache/HighConcurrencyTemplateCache.java
index 21c057031..b9febf6b6 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/cache/HighConcurrencyTemplateCache.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/cache/HighConcurrencyTemplateCache.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.cache;
@@ -44,14 +32,10 @@
*/
public class HighConcurrencyTemplateCache implements TemplateCache {
- /**
- * The logging system.
- */
+ /** The logging system. */
private final Logger logger = LoggerFactory.getLogger(getClass());
- /**
- * The map cache.
- */
+ /** The map cache. */
private final ConcurrentMap>> cache;
/** Turn on/off auto reloading of templates. */
@@ -67,9 +51,7 @@ protected HighConcurrencyTemplateCache(
this.cache = notNull(cache, "The cache is required.");
}
- /**
- * Creates a new HighConcurrencyTemplateCache.
- */
+ /** Creates a new HighConcurrencyTemplateCache. */
public HighConcurrencyTemplateCache() {
this(new ConcurrentHashMap>>());
}
@@ -89,9 +71,7 @@ public Template get(final TemplateSource source, final Parser parser) throws IOE
notNull(source, "The source is required.");
notNull(parser, "The parser is required.");
- /**
- * Don't keep duplicated entries, remove old templates if a change is detected.
- */
+ /** Don't keep duplicated entries, remove old templates if a change is detected. */
return cacheGet(source, parser);
}
@@ -158,10 +138,9 @@ private Template cacheGet(final TemplateSource source, final Parser parser) thro
* @param parser The handlebars parser.
* @return A new future task.
*/
- private FutureTask> newTask(final TemplateSource source,
- final Parser parser) {
- return new FutureTask<>(
- () -> Pair.of(source, parser.parse(source)));
+ private FutureTask> newTask(
+ final TemplateSource source, final Parser parser) {
+ return new FutureTask<>(() -> Pair.of(source, parser.parse(source)));
}
/**
@@ -171,8 +150,8 @@ private FutureTask> newTask(final TemplateSource
* @param futureTask The future task.
* @return The resulting value.
*/
- private Future> putIfAbsent(final TemplateSource source,
- final FutureTask> futureTask) {
+ private Future> putIfAbsent(
+ final TemplateSource source, final FutureTask> futureTask) {
Future> future = cache.putIfAbsent(source, futureTask);
if (future == null) {
future = futureTask;
@@ -197,5 +176,4 @@ private RuntimeException launderThrowable(final TemplateSource source, final Thr
return new HandlebarsException("Can't parse: " + source, cause);
}
}
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/cache/NullTemplateCache.java b/handlebars/src/main/java/com/github/jknack/handlebars/cache/NullTemplateCache.java
index 4d8d7cb0e..c2162c8df 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/cache/NullTemplateCache.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/cache/NullTemplateCache.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.cache;
@@ -31,18 +19,14 @@
*/
public enum NullTemplateCache implements TemplateCache {
- /**
- * Shared instance of null cache.
- */
+ /** Shared instance of null cache. */
INSTANCE;
@Override
- public void clear() {
- }
+ public void clear() {}
@Override
- public void evict(final TemplateSource source) {
- }
+ public void evict(final TemplateSource source) {}
@Override
public NullTemplateCache setReload(final boolean reload) {
@@ -53,5 +37,4 @@ public NullTemplateCache setReload(final boolean reload) {
public Template get(final TemplateSource source, final Parser parser) throws IOException {
return parser.parse(source);
}
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/cache/TemplateCache.java b/handlebars/src/main/java/com/github/jknack/handlebars/cache/TemplateCache.java
index 2bf61df22..e3a3e993e 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/cache/TemplateCache.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/cache/TemplateCache.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.cache;
@@ -31,9 +19,7 @@
*/
public interface TemplateCache {
- /**
- * Remove all mappings from the cache.
- */
+ /** Remove all mappings from the cache. */
void clear();
/**
@@ -54,8 +40,8 @@ public interface TemplateCache {
Template get(TemplateSource source, Parser parser) throws IOException;
/**
- * Turn on/off auto reloading of templates. Auto reload is done using
- * {@link TemplateSource#lastModified()}.
+ * Turn on/off auto reloading of templates. Auto reload is done using {@link
+ * TemplateSource#lastModified()}.
*
* @param reload True, for turning off template reload. Default is: false.
* @return This template loader.
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/context/FieldValueResolver.java b/handlebars/src/main/java/com/github/jknack/handlebars/context/FieldValueResolver.java
index 1b7786727..533681035 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/context/FieldValueResolver.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/context/FieldValueResolver.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.context;
@@ -29,9 +17,8 @@
import com.github.jknack.handlebars.context.FieldValueResolver.FieldWrapper;
/**
- * A specialization of {@link MemberValueResolver} with lookup and invocation
- * support for {@link Field}.
- * It matches private, protected, package, public and no-static field.
+ * A specialization of {@link MemberValueResolver} with lookup and invocation support for {@link
+ * Field}. It matches private, protected, package, public and no-static field.
*
* @author edgar.espina
* @since 0.1.1
@@ -46,46 +33,35 @@ public class FieldValueResolver extends MemberValueResolver {
*/
public interface FieldWrapper extends Member {
/**
- * Returns the value of the field represented by this {@code Field}, on
- * the specified object. The value is automatically wrapped in an
- * object if it has a primitive type.
+ * Returns the value of the field represented by this {@code Field}, on the specified object.
+ * The value is automatically wrapped in an object if it has a primitive type.
*
- *
- * The underlying field's value is obtained as follows:
+ *
The underlying field's value is obtained as follows:
*
- *
- * If the underlying field is a static field, the {@code obj} argument is ignored; it may be
+ *
If the underlying field is a static field, the {@code obj} argument is ignored; it may be
* null.
*
- *
- * Otherwise, the underlying field is an instance field. If the specified {@code obj} argument
- * is null, the method throws a {@code NullPointerException}. If the specified object is not an
- * instance of the class or interface declaring the underlying field, the method throws an
- * {@code IllegalArgumentException}.
+ *
Otherwise, the underlying field is an instance field. If the specified {@code obj}
+ * argument is null, the method throws a {@code NullPointerException}. If the specified object
+ * is not an instance of the class or interface declaring the underlying field, the method
+ * throws an {@code IllegalArgumentException}.
*
- *
- * If this {@code Field} object enforces Java language access control, and the underlying field
- * is inaccessible, the method throws an {@code IllegalAccessException}. If the underlying field
- * is static, the class that declared the field is initialized if it has not already been
+ *
If this {@code Field} object enforces Java language access control, and the underlying
+ * field is inaccessible, the method throws an {@code IllegalAccessException}. If the underlying
+ * field is static, the class that declared the field is initialized if it has not already been
* initialized.
*
- *
- * Otherwise, the value is retrieved from the underlying instance or static field. If the field
- * has a primitive type, the value is wrapped in an object before being returned, otherwise it
- * is returned as is.
+ *
Otherwise, the value is retrieved from the underlying instance or static field. If the
+ * field has a primitive type, the value is wrapped in an object before being returned,
+ * otherwise it is returned as is.
*
- *
- * If the field is hidden in the type of {@code obj}, the field's value is obtained according to
- * the preceding rules.
+ *
If the field is hidden in the type of {@code obj}, the field's value is obtained according
+ * to the preceding rules.
*
- * @param obj object from which the represented field's value is
- * to be extracted
+ * @param obj object from which the represented field's value is to be extracted
* @return the value of the represented field in object {@code obj}; primitive values are
- * wrapped in an appropriate
- * object before being returned
- *
- * @exception IllegalAccessException if the underlying field
- * is inaccessible.
+ * wrapped in an appropriate object before being returned
+ * @exception IllegalAccessException if the underlying field is inaccessible.
*/
Object get(Object obj) throws IllegalAccessException;
}
@@ -98,9 +74,7 @@ public interface FieldWrapper extends Member {
*/
private static class FieldMember extends AccessibleObject implements FieldWrapper {
- /**
- * The field object.
- */
+ /** The field object. */
private Field field;
/**
@@ -160,16 +134,11 @@ public void setAccessible(final boolean flag) {
*/
private static final class ArrayLengthMember implements FieldWrapper {
- /**
- * One instance is enough.
- */
+ /** One instance is enough. */
public static final FieldWrapper LENGTH = new ArrayLengthMember();
- /**
- * Not allowed.
- */
- private ArrayLengthMember() {
- }
+ /** Not allowed. */
+ private ArrayLengthMember() {}
@Override
public Class> getDeclaringClass() {
@@ -195,12 +164,9 @@ public boolean isSynthetic() {
public Object get(final Object obj) throws IllegalAccessException {
return Array.getLength(obj);
}
-
}
- /**
- * The default value resolver.
- */
+ /** The default value resolver. */
public static final ValueResolver INSTANCE = new FieldValueResolver();
@Override
@@ -214,8 +180,7 @@ protected Object invokeMember(final FieldWrapper field, final Object context) {
return field.get(context);
} catch (Exception ex) {
throw new IllegalStateException(
- "Shouldn't be illegal to access field '" + field.getName()
- + "'", ex);
+ "Shouldn't be illegal to access field '" + field.getName() + "'", ex);
}
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/context/JavaBeanValueResolver.java b/handlebars/src/main/java/com/github/jknack/handlebars/context/JavaBeanValueResolver.java
index 1b0284d26..64029543c 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/context/JavaBeanValueResolver.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/context/JavaBeanValueResolver.java
@@ -1,27 +1,15 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.context;
-import com.github.jknack.handlebars.ValueResolver;
-
import java.lang.reflect.Method;
import java.util.Collection;
+import com.github.jknack.handlebars.ValueResolver;
+
/**
* A JavaBean method value resolver.
*
@@ -30,19 +18,13 @@
*/
public class JavaBeanValueResolver extends MethodValueResolver {
- /**
- * The 'is' prefix.
- */
+ /** The 'is' prefix. */
private static final String IS_PREFIX = "is";
- /**
- * The 'get' prefix.
- */
+ /** The 'get' prefix. */
private static final String GET_PREFIX = "get";
- /**
- * The default value resolver.
- */
+ /** The default value resolver. */
public static final ValueResolver INSTANCE = new JavaBeanValueResolver();
@Override
@@ -67,11 +49,10 @@ public boolean matches(final Method method, final String name) {
* Convert the property's name to a JavaBean read method name.
*
* @param prefix The prefix: 'get' or 'is'.
- * @param name The unqualified property name.
+ * @param name The unqualified property name.
* @return The javaBean method name.
*/
- private static String javaBeanMethod(final String prefix,
- final String name) {
+ private static String javaBeanMethod(final String prefix, final String name) {
StringBuilder buffer = new StringBuilder(prefix);
buffer.append(name);
buffer.setCharAt(prefix.length(), Character.toUpperCase(name.charAt(0)));
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/context/MapValueResolver.java b/handlebars/src/main/java/com/github/jknack/handlebars/context/MapValueResolver.java
index 0f4498981..492b39e60 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/context/MapValueResolver.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/context/MapValueResolver.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.context;
@@ -33,12 +21,10 @@
*/
public enum MapValueResolver implements ValueResolver {
- /**
- * A singleton instance.
- */
+ /** A singleton instance. */
INSTANCE;
- @SuppressWarnings({"rawtypes", "unchecked" })
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Override
public Object resolve(final Object context, final String name) {
Object value = null;
@@ -65,7 +51,7 @@ public Object resolve(final Object context) {
return UNRESOLVED;
}
- @SuppressWarnings({"unchecked", "rawtypes" })
+ @SuppressWarnings({"unchecked", "rawtypes"})
@Override
public Set> propertySet(final Object context) {
if (context instanceof Map) {
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/context/MemberValueResolver.java b/handlebars/src/main/java/com/github/jknack/handlebars/context/MemberValueResolver.java
index 1ec5c2dd0..a5a04f680 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/context/MemberValueResolver.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/context/MemberValueResolver.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.context;
@@ -34,8 +22,8 @@
import com.github.jknack.handlebars.ValueResolver;
/**
- * A specialization of {@link ValueResolver} that is built on top of reflections
- * API. It use an internal cache for saving {@link Member members}.
+ * A specialization of {@link ValueResolver} that is built on top of reflections API. It use an
+ * internal cache for saving {@link Member members}.
*
* @author edgar.espina
* @param The member type.
@@ -43,9 +31,7 @@
*/
public abstract class MemberValueResolver implements ValueResolver {
- /**
- * A concurrent and thread-safe cache for {@link Member}.
- */
+ /** A concurrent and thread-safe cache for {@link Member}. */
private final Map, Map> cache = new ConcurrentHashMap<>();
@Override
@@ -89,17 +75,15 @@ private Map cache(final Class> clazz) {
}
/**
- * Determines whether or not to call
- * {@link AccessibleObject#setAccessible(boolean)} on members before they are
- * cached.
+ * Determines whether or not to call {@link AccessibleObject#setAccessible(boolean)} on members
+ * before they are cached.
*
- * Calling setAccessible on JDK 9 or later on private or protected declaring
- * classes in modules will result in errors so the default implementation checks
- * to see if the declared class cannonical name starts with "java." or "sun." to
- * prevent most of these errors.
+ *
Calling setAccessible on JDK 9 or later on private or protected declaring classes in modules
+ * will result in errors so the default implementation checks to see if the declared class
+ * cannonical name starts with "java." or "sun." to prevent most of these errors.
*
- * Modular applications should create their own resolvers and override this
- * method to prevent encapsulation violation errors.
+ *
Modular applications should create their own resolvers and override this method to prevent
+ * encapsulation violation errors.
*
* @param member Not null.
* @return true will cause setAccessible(true) to be called.
@@ -203,5 +187,4 @@ public Set> propertySet(final Object context) {
* @return The member's name.
*/
protected abstract String memberName(M member);
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/context/MethodValueResolver.java b/handlebars/src/main/java/com/github/jknack/handlebars/context/MethodValueResolver.java
index 5e1d3ccc8..682a6354c 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/context/MethodValueResolver.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/context/MethodValueResolver.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.context;
@@ -25,23 +13,18 @@
import com.github.jknack.handlebars.ValueResolver;
/**
- * A specialization of {@link MemberValueResolver} with lookup and invocation
- * support for {@link Method}.
- * It matches a public method.
+ * A specialization of {@link MemberValueResolver} with lookup and invocation support for {@link
+ * Method}. It matches a public method.
*
* @author edgar.espina
* @since 0.1.1
*/
public class MethodValueResolver extends MemberValueResolver {
- /**
- * The default instance.
- */
+ /** The default instance. */
public static final ValueResolver INSTANCE = new MethodValueResolver();
- /**
- * Args for getters.
- */
+ /** Args for getters. */
private static final Object[] EMPTY_ARGS = new Object[0];
@Override
@@ -61,8 +44,7 @@ protected Object invokeMember(final Method member, final Object context) {
}
throw new IllegalStateException("Execution of '" + member.getName() + "' failed", cause);
} catch (IllegalAccessException ex) {
- throw new IllegalStateException(
- "Could not access method: '" + member.getName() + "'", ex);
+ throw new IllegalStateException("Could not access method: '" + member.getName() + "'", ex);
}
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/BlockHelper.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/BlockHelper.java
index 98dc47ed5..623406cc2 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/BlockHelper.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/BlockHelper.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -31,13 +19,10 @@
import com.github.jknack.handlebars.Template;
/**
- *
* The block helper will replace its section with the partial of the same name if it exists.
- *
- *
- * If delete-after-merge is set to true, the partial will be delete once
- * applied it.
- *
+ *
+ *
If delete-after-merge is set to true, the partial will be delete
+ * once applied it.
*
*
* {{block "title" [delete-after-merge=false]}}
@@ -48,21 +33,15 @@
*/
public class BlockHelper implements Helper {
- /**
- * A singleton instance of this helper.
- */
+ /** A singleton instance of this helper. */
public static final Helper INSTANCE = new BlockHelper();
- /**
- * The helper's name.
- */
+ /** The helper's name. */
public static final String NAME = "block";
@Override
- public Object apply(final Object context, final Options options)
- throws IOException {
- isTrue(context instanceof String, "found '%s', expected 'partial's name'",
- context);
+ public Object apply(final Object context, final Options options) throws IOException {
+ isTrue(context instanceof String, "found '%s', expected 'partial's name'", context);
String path = (String) context;
Template template = options.partial(path);
@@ -88,8 +67,8 @@ public Object apply(final Object context, final Options options)
}
CharSequence result = options.apply(template, options.context.data(hash));
- Boolean deletePartials = options.hash("delete-after-merge",
- options.handlebars.deletePartialAfterMerge());
+ Boolean deletePartials =
+ options.hash("delete-after-merge", options.handlebars.deletePartialAfterMerge());
if (deletePartials) {
// once applied, remove the template from current execution.
options.partial(path, null);
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/ConditionalHelpers.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/ConditionalHelpers.java
index 55846b2c3..0633b9dcb 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/ConditionalHelpers.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/ConditionalHelpers.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -38,7 +26,8 @@ public enum ConditionalHelpers implements Helper {
/**
* Test if two elements are equals. Usage:
*
- * Render 'yes' or 'no':
+ *
Render 'yes' or 'no':
+ *
*
* {{#eq a b}}
* yes
@@ -48,32 +37,34 @@ public enum ConditionalHelpers implements Helper {
*
*
* Render 'true' or 'false':
+ *
*
* {{eq a b}}
*
*
* Render 'y' or 'n':
+ *
*
* {{eq a b yes='y' no='n'}}
*
*/
eq {
- @Override public Object apply(final Object a, final Options options) throws IOException {
+ @Override
+ public Object apply(final Object a, final Options options) throws IOException {
Object b = options.param(0, null);
boolean result = eq(a, b);
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
- return result
- ? options.hash("yes", true)
- : options.hash("no", false);
+ return result ? options.hash("yes", true) : options.hash("no", false);
}
},
/**
* Test if two elements are NOT equals. Usage:
*
- * Render 'yes' or 'no':
+ *
Render 'yes' or 'no':
+ *
*
* {{#neq a b}}
* yes
@@ -83,32 +74,34 @@ public enum ConditionalHelpers implements Helper {
*
*
* Render 'true' or 'false':
+ *
*
* {{neq a b}}
*
*
* Render 'y' or 'n':
+ *
*
* {{neq a b yes='y' no='n'}}
*
*/
neq {
- @Override public Object apply(final Object a, final Options options) throws IOException {
+ @Override
+ public Object apply(final Object a, final Options options) throws IOException {
Object b = options.param(0, null);
boolean result = !eq(a, b);
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
- return result
- ? options.hash("yes", true)
- : options.hash("no", false);
+ return result ? options.hash("yes", true) : options.hash("no", false);
}
},
/**
* Greater operator (arguments must be {@link Comparable} elements. Usage:
*
- * Render 'yes' or 'no':
+ *
Render 'yes' or 'no':
+ *
*
* {{#gt a b}}
* yes
@@ -118,31 +111,33 @@ public enum ConditionalHelpers implements Helper {
*
*
* Render 'true' or 'false':
+ *
*
* {{gt a b}}
*
*
* Render 'y' or 'n':
+ *
*
* {{neq a b yes='y' no='n'}}
*
*/
gt {
- @Override public Object apply(final Object a, final Options options) throws IOException {
+ @Override
+ public Object apply(final Object a, final Options options) throws IOException {
boolean result = cmp(a, options.param(0, null)) > 0;
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
- return result
- ? options.hash("yes", true)
- : options.hash("no", false);
+ return result ? options.hash("yes", true) : options.hash("no", false);
}
},
/**
* Greater or equal operator (arguments must be {@link Comparable} elements. Usage:
*
- * Render 'yes' or 'no':
+ *
Render 'yes' or 'no':
+ *
*
* {{#gte a b}}
* yes
@@ -152,31 +147,33 @@ public enum ConditionalHelpers implements Helper {
*
*
* Render 'true' or 'false':
+ *
*
* {{gte a b}}
*
*
* Render 'y' or 'n':
+ *
*
* {{gte a b yes='y' no='n'}}
*
*/
gte {
- @Override public Object apply(final Object a, final Options options) throws IOException {
+ @Override
+ public Object apply(final Object a, final Options options) throws IOException {
boolean result = cmp(a, options.param(0, null)) >= 0;
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
- return result
- ? options.hash("yes", true)
- : options.hash("no", false);
+ return result ? options.hash("yes", true) : options.hash("no", false);
}
},
/**
* Less than operator (arguments must be {@link Comparable} elements. Usage:
*
- * Render 'yes' or 'no':
+ *
Render 'yes' or 'no':
+ *
*
* {{#lt a b}}
* yes
@@ -186,31 +183,33 @@ public enum ConditionalHelpers implements Helper {
*
*
* Render 'true' or 'false':
+ *
*
* {{lt a b}}
*
*
* Render 'y' or 'n':
+ *
*
* {{lt a b yes='y' no='n'}}
*
*/
lt {
- @Override public Object apply(final Object a, final Options options) throws IOException {
+ @Override
+ public Object apply(final Object a, final Options options) throws IOException {
boolean result = cmp(a, options.param(0, null)) < 0;
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
- return result
- ? options.hash("yes", true)
- : options.hash("no", false);
+ return result ? options.hash("yes", true) : options.hash("no", false);
}
},
/**
* Less or equal operator (arguments must be {@link Comparable} elements. Usage:
*
- * Render 'yes' or 'no':
+ *
Render 'yes' or 'no':
+ *
*
* {{#lte a b}}
* yes
@@ -220,36 +219,38 @@ public enum ConditionalHelpers implements Helper {
*
*
* Render 'true' or 'false':
+ *
*
* {{lte a b}}
*
*
* Render 'y' or 'n':
+ *
*
* {{lte a b yes='y' no='n'}}
*
*/
lte {
- @Override public Object apply(final Object a, final Options options) throws IOException {
+ @Override
+ public Object apply(final Object a, final Options options) throws IOException {
boolean result = cmp(a, options.param(0, null)) <= 0;
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
- return result
- ? options.hash("yes", true)
- : options.hash("no", false);
+ return result ? options.hash("yes", true) : options.hash("no", false);
}
},
/**
* And operator.
*
- * Truthiness of arguments is determined by {@link Handlebars.Utils#isEmpty(Object)}, so this
+ *
Truthiness of arguments is determined by {@link Handlebars.Utils#isEmpty(Object)}, so this
* helper can be used with non-boolean values.
*
- * Usage:
+ *
Usage:
+ *
+ *
Render 'yes' or 'no':
*
- * Render 'yes' or 'no':
*
* {{#and a b}}
* yes
@@ -259,6 +260,7 @@ public enum ConditionalHelpers implements Helper {
*
*
* Multiple arguments are supported too:
+ *
*
* {{#and a b c d}}
* yes
@@ -268,17 +270,20 @@ public enum ConditionalHelpers implements Helper {
*
*
* Render 'true' or 'false':
+ *
*
* {{and a b}}
*
*
* Render 'y' or 'n':
+ *
*
* {{and a b yes='y' no='n'}}
*
*/
and {
- @Override public Object apply(final Object context, final Options options) throws IOException {
+ @Override
+ public Object apply(final Object context, final Options options) throws IOException {
boolean result = !Handlebars.Utils.isEmpty(context);
if (result) {
for (int i = 0; i < options.params.length && result; i++) {
@@ -288,21 +293,20 @@ public enum ConditionalHelpers implements Helper {
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
- return result
- ? options.hash("yes", true)
- : options.hash("no", false);
+ return result ? options.hash("yes", true) : options.hash("no", false);
}
},
/**
* Or operator.
*
- * Truthiness of arguments is determined by {@link Handlebars.Utils#isEmpty(Object)}, so this
+ *
Truthiness of arguments is determined by {@link Handlebars.Utils#isEmpty(Object)}, so this
* helper can be used with non-boolean values.
*
- * Usage:
+ *
Usage:
+ *
+ *
Render 'yes' or 'no':
*
- * Render 'yes' or 'no':
*
* {{#or a b}}
* yes
@@ -312,6 +316,7 @@ public enum ConditionalHelpers implements Helper {
*
*
* Multiple arguments are supported too:
+ *
*
* {{#or a b c d}}
* yes
@@ -321,17 +326,20 @@ public enum ConditionalHelpers implements Helper {
*
*
* Render 'true' or 'false':
+ *
*
* {{or a b}}
*
*
* Render 'y' or 'n':
+ *
*
* {{or a b yes='y' no='n'}}
*
*/
or {
- @Override public Object apply(final Object context, final Options options) throws IOException {
+ @Override
+ public Object apply(final Object context, final Options options) throws IOException {
boolean result = !Handlebars.Utils.isEmpty(context);
if (!result) {
int i = 0;
@@ -342,21 +350,20 @@ public enum ConditionalHelpers implements Helper {
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
- return result
- ? options.hash("yes", true)
- : options.hash("no", false);
+ return result ? options.hash("yes", true) : options.hash("no", false);
}
},
/**
* Not operator.
*
- * Truthiness of arguments is determined by {@link Handlebars.Utils#isEmpty(Object)}, so this
+ *
Truthiness of arguments is determined by {@link Handlebars.Utils#isEmpty(Object)}, so this
* helper can be used with non-boolean values.
*
- * Usage:
+ *
Usage:
+ *
+ *
Render 'yes' or 'no':
*
- * Render 'yes' or 'no':
*
*/
not {
- @Override public Object apply(final Object context, final Options options) throws IOException {
+ @Override
+ public Object apply(final Object context, final Options options) throws IOException {
boolean result = Handlebars.Utils.isEmpty(context);
if (options.tagType == TagType.SECTION) {
return result ? options.fn() : options.inverse();
}
- return result
- ? options.hash("yes", true)
- : options.hash("no", false);
+ return result ? options.hash("yes", true) : options.hash("no", false);
}
};
@@ -424,6 +432,7 @@ protected boolean eq(final Object a, final Object b) {
/**
* Generate double from value or throw existing exception.
+ *
* @param value Value to cast.
* @param x Exception.
* @return Double.
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java
index 3cdd33fd7..e80887876 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java
@@ -1,23 +1,10 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
-import com.github.jknack.handlebars.internal.Throwing;
import static org.apache.commons.lang3.Validate.isTrue;
import static org.apache.commons.lang3.Validate.notEmpty;
import static org.apache.commons.lang3.Validate.notNull;
@@ -35,9 +22,12 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.Set;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,9 +37,7 @@
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.HelperRegistry;
import com.github.jknack.handlebars.internal.Files;
-
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineManager;
+import com.github.jknack.handlebars.internal.Throwing;
/**
* Default implementation of {@link HelperRegistry}.
@@ -62,9 +50,7 @@ public class DefaultHelperRegistry implements HelperRegistry {
/** The logging system. */
private final Logger logger = LoggerFactory.getLogger(HelperRegistry.class);
- /**
- * The JavaScript helpers environment for Rhino.
- */
+ /** The JavaScript helpers environment for Rhino. */
private static final String HELPERS_ENV;
static {
@@ -76,9 +62,7 @@ public class DefaultHelperRegistry implements HelperRegistry {
}
}
- /**
- * The helper registry.
- */
+ /** The helper registry. */
private final Map> helpers = new HashMap<>();
/** Decorators. */
@@ -201,28 +185,25 @@ public Set>> helpers() {
}
/**
- * Since nashorn doesn't yet supports the ES6's "const" or "let" literals.
- * This method adapts the given helper source written in ES6 to work
- * with nashorn (by converting let/const to var).
+ * Since nashorn doesn't yet supports the ES6's "const" or "let" literals. This method adapts the
+ * given helper source written in ES6 to work with nashorn (by converting let/const to var).
*
* @param source the helper source.
* @return the adapted helper source.
- **/
+ */
private String adaptES6Literals(final String source) {
Matcher m = es6VarPattern.matcher(source);
StringBuffer sb = new StringBuffer();
while (m.find()) {
- StringBuffer buf = new StringBuffer(m.group());
- buf.replace(m.start(1) - m.start(), m.end(1) - m.start(), "var");
- m.appendReplacement(sb, buf.toString());
+ StringBuffer buf = new StringBuffer(m.group());
+ buf.replace(m.start(1) - m.start(), m.end(1) - m.start(), "var");
+ m.appendReplacement(sb, buf.toString());
}
return m.appendTail(sb).toString();
}
/**
- *
* Register all the helper methods for the given helper source.
- *
*
* @param source The helper source.
* @param clazz The helper source class.
@@ -288,7 +269,8 @@ public HelperRegistry registerDecorator(final String name, final Decorator decor
return this;
}
- @Override public DefaultHelperRegistry setCharset(final Charset charset) {
+ @Override
+ public DefaultHelperRegistry setCharset(final Charset charset) {
this.charset = notNull(charset, "Charset required.");
return this;
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/EachHelper.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/EachHelper.java
index de405fc77..e643db6bd 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/EachHelper.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/EachHelper.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -28,29 +16,23 @@
import com.github.jknack.handlebars.Template;
/**
- * You can iterate over a list using the built-in each helper. Inside the
- * block, you can use this to reference the element being
- * iterated over.
+ * You can iterate over a list using the built-in each helper. Inside the block, you can use
+ * this to reference the element being iterated over.
*
* @author edgar.espina
* @since 0.3.0
*/
public class EachHelper implements Helper {
- /**
- * A singleton instance of this helper.
- */
+ /** A singleton instance of this helper. */
public static final Helper INSTANCE = new EachHelper();
- /**
- * The helper's name.
- */
+ /** The helper's name. */
public static final String NAME = "each";
- @SuppressWarnings({"rawtypes", "unchecked" })
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Override
- public Object apply(final Object context, final Options options)
- throws IOException {
+ public Object apply(final Object context, final Options options) throws IOException {
if (context instanceof Iterable) {
Options.Buffer buffer = options.buffer();
Iterator loop = ((Iterable) context).iterator();
@@ -62,7 +44,8 @@ public Object apply(final Object context, final Options options)
while (loop.hasNext()) {
Object it = loop.next();
Context itCtx = Context.newContext(parent, it);
- itCtx.combine("@key", index)
+ itCtx
+ .combine("@key", index)
.combine("@index", index)
.combine("@first", index == base ? "first" : "")
.combine("@last", !loop.hasNext() ? "last" : "")
@@ -90,12 +73,13 @@ public Object apply(final Object context, final Options options)
Entry entry = (Entry) loop.next();
Object key = entry.getKey();
Object value = entry.getValue();
- Context itCtx = Context.newBuilder(parent, value)
- .combine("@key", key)
- .combine("@index", index)
- .combine("@first", first ? "first" : "")
- .combine("@last", !loop.hasNext() ? "last" : "")
- .build();
+ Context itCtx =
+ Context.newBuilder(parent, value)
+ .combine("@key", key)
+ .combine("@index", index)
+ .combine("@first", first ? "first" : "")
+ .combine("@last", !loop.hasNext() ? "last" : "")
+ .build();
buffer.append(options.apply(fn, itCtx, Arrays.asList(value, key)));
first = false;
index++;
@@ -109,5 +93,4 @@ public Object apply(final Object context, final Options options)
return options.inverse();
}
}
-
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/EmbeddedHelper.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/EmbeddedHelper.java
index e4a59f6ef..780657b8b 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/EmbeddedHelper.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/EmbeddedHelper.java
@@ -1,23 +1,10 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
-import com.github.jknack.handlebars.io.TemplateSource;
import static org.apache.commons.lang3.Validate.notEmpty;
import java.io.IOException;
@@ -25,10 +12,10 @@
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
+import com.github.jknack.handlebars.io.TemplateSource;
/**
- * Given:
- * home.hbs
+ * Given: home.hbs
*
*
* <html>
@@ -79,27 +66,21 @@
*/
public class EmbeddedHelper implements Helper {
- /**
- * A singleton instance of this helper.
- */
+ /** A singleton instance of this helper. */
public static final Helper INSTANCE = new EmbeddedHelper();
- /**
- * The helper's name.
- */
+ /** The helper's name. */
public static final String NAME = "embedded";
@Override
- public Object apply(final String path, final Options options)
- throws IOException {
+ public Object apply(final String path, final Options options) throws IOException {
notEmpty(path, "found '%s', expected 'partial's name'", path);
String suffix = options.handlebars.getLoader().getSuffix();
String defaultId = (path + suffix).replace('/', '-').replace('.', '-');
String id = options.param(0, defaultId);
TemplateSource source = options.handlebars.getLoader().sourceAt(path);
StringBuilder script = new StringBuilder();
- script.append("");
return new Handlebars.SafeString(script);
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java
index 3252b8ec4..34b2f746e 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/HelperFunction.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -21,16 +9,16 @@
import java.lang.annotation.RetentionPolicy;
/**
- * Decorates a method that represents a helper function extracted via a "helper source"
- * with metadata that cannot be inferred from its signature, such as a custom helper name.
+ * Decorates a method that represents a helper function extracted via a "helper source" with
+ * metadata that cannot be inferred from its signature, such as a custom helper name.
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface HelperFunction {
- /**
- * The name used to invoke the decorated helper function in a handlebars template.
- * @return Name or null/empty to use default method name.
- */
- String value();
-
+ /**
+ * The name used to invoke the decorated helper function in a handlebars template.
+ *
+ * @return Name or null/empty to use default method name.
+ */
+ String value();
}
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/I18nHelper.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/I18nHelper.java
index 382e2230e..3726a2de9 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/I18nHelper.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/I18nHelper.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -44,13 +32,11 @@
/**
* Implementation of i18n helper for Java and JavaScript.
- *
- * The Java implementation use {@link ResourceBundle}.
- *
- *
- * The JavaScript version use the I18n library.
+ *
+ *
The Java implementation use {@link ResourceBundle}.
+ *
+ *
The JavaScript version use the I18n library.
* {@link ResourceBundle} are converted to JavaScript code.
- *
*
* If locale argument is present it will translate that locale to JavaScript. Otherwise, the
* default locale.
*
- * Use wrap=true for wrapping the code with a script tag.
+ *
Use wrap=true for wrapping the code with a script tag.
*
* @param localeName The locale's name. Optional.
* @param options The helper's options. Not null.
@@ -236,8 +204,8 @@ public Object apply(final String localeName, final Options options) throws IOExc
Locale locale = Locales.fromString(defaultIfEmpty(localeName, defaultLocale.toString()));
String baseName = options.hash("bundle", defaultBundle);
ClassLoader classLoader = options.hash("classLoader", getClass().getClassLoader());
- I18nSource localSource = source == null
- ? new DefI18nSource(charset, baseName, locale, classLoader) : source;
+ I18nSource localSource =
+ source == null ? new DefI18nSource(charset, baseName, locale, classLoader) : source;
StringBuilder buffer = new StringBuilder();
Boolean wrap = options.hash("wrap", true);
if (wrap) {
@@ -284,26 +252,22 @@ private String message(final String message) {
}
};
- /**
- * The default locale. Required.
- */
+ /** The default locale. Required. */
protected Locale defaultLocale = Locale.getDefault();
- /**
- * The default's bundle. Required.
- */
+ /** The default's bundle. Required. */
protected String defaultBundle = "messages";
/** The message source to use. */
protected I18nSource source;
- /** Charset. **/
+ /** Charset. * */
protected Charset charset = StandardCharsets.UTF_8;
/**
* Set the charset to use.
*
- * NotThreadSafe Make sure to call this method ONCE at start time.
+ *
NotThreadSafe Make sure to call this method ONCE at start time.
*
* @param charset Charset. Required.
*/
@@ -314,7 +278,7 @@ public void setCharset(final Charset charset) {
/**
* Set the message source.
*
- * NotThreadSafe Make sure to call this method ONCE at start time.
+ *
NotThreadSafe Make sure to call this method ONCE at start time.
*
* @param source The message source. Required.
*/
@@ -326,7 +290,7 @@ public void setSource(final I18nSource source) {
* Set the default bundle's name. Default is: messages and this method let you override the
* default bundle's name to something else.
*
- * NotThreadSafe Make sure to call this method ONCE at start time.
+ *
NotThreadSafe Make sure to call this method ONCE at start time.
*
* @param bundle The default's bundle name. Required.
*/
@@ -338,14 +302,13 @@ public void setDefaultBundle(final String bundle) {
* Set the default locale. Default is system dependent and this method let you override the
* default bundle's name to something else.
*
- * NotThreadSafe Make sure to call this method ONCE at start time.
+ *
NotThreadSafe Make sure to call this method ONCE at start time.
*
* @param locale The default locale name. Required.
*/
public void setDefaultLocale(final Locale locale) {
this.defaultLocale = notNull(locale, "A locale is required.");
}
-
}
/** Default implementation of I18nSource. */
@@ -354,10 +317,9 @@ class DefI18nSource implements I18nSource {
/**
* UTF8 resource bundle control.
*
- * Source: Source: https://stackoverflow.com/questions/4659929
+ *
Source: Source: https://stackoverflow.com/questions/4659929
*
* @author edgar
- *
*/
public static class UTF8Control extends ResourceBundle.Control {
/** Charset. */
@@ -371,17 +333,23 @@ public static class UTF8Control extends ResourceBundle.Control {
UTF8Control(final Charset charset) {
this.charset = charset;
}
+
@Override
- public ResourceBundle newBundle(final String baseName, final Locale locale, final String format,
- final ClassLoader loader, final boolean reload) throws IOException {
+ public ResourceBundle newBundle(
+ final String baseName,
+ final Locale locale,
+ final String format,
+ final ClassLoader loader,
+ final boolean reload)
+ throws IOException {
// The below is a copy of the default implementation.
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, "properties");
InputStream stream = null;
- try {
+ try {
stream = loader.getResourceAsStream(resourceName);
- PropertyResourceBundle bundle = new PropertyResourceBundle(
- new InputStreamReader(stream, charset));
+ PropertyResourceBundle bundle =
+ new PropertyResourceBundle(new InputStreamReader(stream, charset));
return bundle;
} finally {
if (stream != null) {
@@ -402,7 +370,10 @@ public ResourceBundle newBundle(final String baseName, final Locale locale, fina
* @param locale The locale.
* @param classLoader The classloader.
*/
- DefI18nSource(final Charset charset, final String baseName, final Locale locale,
+ DefI18nSource(
+ final Charset charset,
+ final String baseName,
+ final Locale locale,
final ClassLoader classLoader) {
bundle = ResourceBundle.getBundle(baseName, locale, classLoader, new UTF8Control(charset));
}
@@ -428,5 +399,5 @@ public String message(final String key, final Locale locale, final Object... arg
MessageFormat format = new MessageFormat(message, locale);
return format.format(args);
}
-
-};
+}
+;
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/I18nSource.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/I18nSource.java
index afbc2599b..6c6384be6 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/I18nSource.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/I18nSource.java
@@ -1,27 +1,15 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
import java.util.Locale;
/**
- * Resolve message keys and message for internationalization. See:
- * {@link I18nHelper#setSource(I18nSource)}.
+ * Resolve message keys and message for internationalization. See: {@link
+ * I18nHelper#setSource(I18nSource)}.
*
* @author edgar
* @since 1.2.1
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/IfHelper.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/IfHelper.java
index 504e2437a..a8fa6e262 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/IfHelper.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/IfHelper.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -24,28 +12,22 @@
import com.github.jknack.handlebars.Options.Buffer;
/**
- * You can use the if helper to conditionally render a block. If its argument
- * returns false, null or empty list/array (a "falsy" value), Handlebars will
- * not render the block.
+ * You can use the if helper to conditionally render a block. If its argument returns false, null or
+ * empty list/array (a "falsy" value), Handlebars will not render the block.
*
* @author edgar.espina
* @since 0.3.0
*/
public class IfHelper implements Helper {
- /**
- * A singleton instance of this helper.
- */
+ /** A singleton instance of this helper. */
public static final Helper INSTANCE = new IfHelper();
- /**
- * The helper's name.
- */
+ /** The helper's name. */
public static final String NAME = "if";
@Override
- public Object apply(final Object context, final Options options)
- throws IOException {
+ public Object apply(final Object context, final Options options) throws IOException {
Buffer buffer = options.buffer();
if (options.isFalsy(context)) {
buffer.append(options.inverse());
diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/helper/InlineDecorator.java b/handlebars/src/main/java/com/github/jknack/handlebars/helper/InlineDecorator.java
index 411561020..269304852 100644
--- a/handlebars/src/main/java/com/github/jknack/handlebars/helper/InlineDecorator.java
+++ b/handlebars/src/main/java/com/github/jknack/handlebars/helper/InlineDecorator.java
@@ -1,19 +1,7 @@
-/**
- * Copyright (c) 2012-2015 Edgar Espina
- *
- * This file is part of Handlebars.java.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Handlebars.java: https://github.com/jknack/handlebars.java
+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
+ * Copyright (c) 2012 Edgar Espina
*/
package com.github.jknack.handlebars.helper;
@@ -38,9 +26,7 @@
*/
public class InlineDecorator implements Decorator {
- /**
- * A singleton instance of this helper.
- */
+ /** A singleton instance of this helper. */
public static final Decorator INSTANCE = new InlineDecorator();
@Override
@@ -48,5 +34,4 @@ public void apply(final Template fn, final Options options) throws IOException {
Deque