Skip to content

Commit 9c3fabf

Browse files
committed
fix upgrade to handlebars 4.7.3
1 parent 6fef5d3 commit 9c3fabf

18 files changed

Lines changed: 170 additions & 101 deletions

File tree

handlebars-maven-plugin/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@
7878
<version>21.0</version>
7979
</dependency>
8080

81+
<dependency>
82+
<groupId>org.apache.commons</groupId>
83+
<artifactId>commons-lang3</artifactId>
84+
</dependency>
85+
86+
<dependency>
87+
<groupId>org.apache.commons</groupId>
88+
<artifactId>commons-text</artifactId>
89+
</dependency>
8190

8291
<!-- Test dependencies -->
8392
<dependency>

handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/Issue234.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public void withAmdOutput() throws Exception {
2424
plugin.addTemplate("c");
2525
plugin.setAmd(true);
2626
plugin.setProject(newProject());
27-
plugin.setHandlebarsJsFile("/handlebars-v4.0.4.js");
27+
plugin.setHandlebarsJsFile("/handlebars-v4.7.3.js");
2828

2929
plugin.execute();
3030

31-
assertEquals(FileUtils.fileRead("src/test/resources/issue234.expected.js"),
32-
FileUtils.fileRead("target/issue234.js"));
31+
assertEquals(FileUtils.fileRead("target/issue234.js"), FileUtils.fileRead("src/test/resources/issue234.expected").trim(),
32+
FileUtils.fileRead("target/issue234.js").trim());
3333
}
3434

3535
private MavenProject newProject(final String... classpath)

handlebars-maven-plugin/src/test/java/com/github/jknack/handlebars/maven/PrecompilePluginTest.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ public void i18nJs() throws Exception {
2727
plugin.setSuffix(".html");
2828
plugin.setOutput("target/helpers-i18njs.js");
2929
plugin.setProject(newProject());
30-
plugin.setHandlebarsJsFile("/handlebars-v4.0.4.js");
30+
plugin.setHandlebarsJsFile("/handlebars-v4.7.3.js");
3131

3232
plugin.execute();
3333

34-
assertEquals(FileUtils.fileRead("src/test/resources/helpers-i18njs.expected"),
35-
FileUtils.fileRead("target/helpers-i18njs.js"));
34+
assertEquals(FileUtils.fileRead("target/helpers-i18njs.js"),
35+
FileUtils.fileRead("src/test/resources/helpers-i18njs.expected").trim(),
36+
FileUtils.fileRead("target/helpers-i18njs.js").trim());
3637
}
3738

3839
@Test
@@ -44,12 +45,13 @@ public void chooseSpecificFiles() throws Exception {
4445
plugin.addTemplate("a");
4546
plugin.addTemplate("c");
4647
plugin.setProject(newProject());
47-
plugin.setHandlebarsJsFile("/handlebars-v4.0.4.js");
48+
plugin.setHandlebarsJsFile("/handlebars-v4.7.3.js");
4849

4950
plugin.execute();
5051

51-
assertEquals(FileUtils.fileRead("src/test/resources/specific-files.expected"),
52-
FileUtils.fileRead("target/specific-files.js"));
52+
assertEquals(FileUtils.fileRead("target/specific-files.js"),
53+
FileUtils.fileRead("src/test/resources/specific-files.expected").trim(),
54+
FileUtils.fileRead("target/specific-files.js").trim());
5355
}
5456

5557
@Test
@@ -59,7 +61,7 @@ public void outputDirMustBeCreated() throws Exception {
5961
plugin.setSuffix(".html");
6062
plugin.setOutput("target/newdir/helpers.js");
6163
plugin.setProject(newProject());
62-
plugin.setHandlebarsJsFile("/handlebars-v4.0.4.js");
64+
plugin.setHandlebarsJsFile("/handlebars-v4.7.3.js");
6365

6466
plugin.execute();
6567
}
@@ -71,7 +73,7 @@ public void missingHelperMustBeSilent() throws Exception {
7173
plugin.setSuffix(".html");
7274
plugin.setOutput("target/missing-helpers.js");
7375
plugin.setProject(newProject());
74-
plugin.setHandlebarsJsFile("/handlebars-v4.0.4.js");
76+
plugin.setHandlebarsJsFile("/handlebars-v4.7.3.js");
7577

7678
plugin.execute();
7779
}
@@ -83,7 +85,7 @@ public void noFileMustBeCreatedIfNoTemplatesWereFound() throws Exception {
8385
plugin.setSuffix(".html");
8486
plugin.setOutput("target/no-helpers.js");
8587
plugin.setProject(newProject());
86-
plugin.setHandlebarsJsFile("/handlebars-v4.0.4.js");
88+
plugin.setHandlebarsJsFile("/handlebars-v4.7.3.js");
8789

8890
plugin.execute();
8991

@@ -125,7 +127,7 @@ public void mustFailOnUnExpectedException() throws Exception {
125127
plugin.setSuffix(".html");
126128
plugin.setOutput("target/no-helpers.js");
127129
plugin.setProject(project);
128-
plugin.setHandlebarsJsFile("/handlebars-v4.0.4.js");
130+
plugin.setHandlebarsJsFile("/handlebars-v4.7.3.js");
129131

130132
plugin.execute();
131133
}
@@ -137,7 +139,7 @@ public void fileWithRuntimeMustBeLargerThanNormalFiles() throws Exception {
137139
withoutRT.setSuffix(".html");
138140
withoutRT.setOutput("target/without-rt-helpers.js");
139141
withoutRT.setProject(newProject());
140-
withoutRT.setHandlebarsJsFile("/handlebars-v4.0.4.js");
142+
withoutRT.setHandlebarsJsFile("/handlebars-v4.7.3.js");
141143

142144
withoutRT.execute();
143145

@@ -147,7 +149,7 @@ public void fileWithRuntimeMustBeLargerThanNormalFiles() throws Exception {
147149
withRT.setOutput("target/with-rt-helpers.js");
148150
withRT.setRuntime("src/test/resources/handlebars.runtime.js");
149151
withRT.setProject(newProject());
150-
withRT.setHandlebarsJsFile("/handlebars-v4.0.4.js");
152+
withRT.setHandlebarsJsFile("/handlebars-v4.7.3.js");
151153

152154
withRT.execute();
153155

@@ -163,7 +165,7 @@ public void normalFileShouleBeLargerThanMinimizedFiles() throws Exception {
163165
withoutRT.setSuffix(".html");
164166
withoutRT.setOutput("target/helpers-normal.js");
165167
withoutRT.setProject(newProject());
166-
withoutRT.setHandlebarsJsFile("/handlebars-v4.0.4.js");
168+
withoutRT.setHandlebarsJsFile("/handlebars-v4.7.3.js");
167169

168170
withoutRT.execute();
169171

@@ -173,7 +175,7 @@ public void normalFileShouleBeLargerThanMinimizedFiles() throws Exception {
173175
withRT.setOutput("target/helpers.min.js");
174176
withRT.setMinimize(true);
175177
withRT.setProject(newProject());
176-
withRT.setHandlebarsJsFile("/handlebars-v4.0.4.js");
178+
withRT.setHandlebarsJsFile("/handlebars-v4.7.3.js");
177179
withRT.execute();
178180

179181
assertTrue("Normal file must be larger than minimized",
@@ -188,12 +190,13 @@ public void partials() throws Exception {
188190
plugin.setSuffix(".html");
189191
plugin.setOutput("target/helpers.js");
190192
plugin.setProject(newProject());
191-
plugin.setHandlebarsJsFile("/handlebars-v4.0.4.js");
193+
plugin.setHandlebarsJsFile("/handlebars-v4.7.3.js");
192194

193195
plugin.execute();
194196

195-
assertEquals(FileUtils.fileRead("src/test/resources/helpers.expected"),
196-
FileUtils.fileRead("target/helpers.js"));
197+
assertEquals(FileUtils.fileRead("target/helpers.js"),
198+
FileUtils.fileRead("src/test/resources/helpers.expected").trim(),
199+
FileUtils.fileRead("target/helpers.js").trim());
197200
}
198201

199202
private MavenProject newProject(final String... classpath)

handlebars-maven-plugin/src/test/resources/helpers-i18njs.expected

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
(function () {
22
// Source: src/test/resources/i18nJs/i18njs.html
33

4-
var template = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
5-
var helper;
6-
7-
return container.escapeExpression(((helper = (helper = helpers.i18nJs || (depth0 != null ? depth0.i18nJs : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"i18nJs","hash":{},"data":data}) : helper)))
4+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
5+
var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) {
6+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
7+
return parent[propertyName];
8+
}
9+
return undefined
10+
};
11+
12+
return container.escapeExpression(((helper = (helper = lookupProperty(helpers,"i18nJs") || (depth0 != null ? lookupProperty(depth0,"i18nJs") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"i18nJs","hash":{},"data":data,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}}) : helper)))
813
+ "\n"
9-
+ container.escapeExpression((helpers.i18n || (depth0 && depth0.i18n) || helpers.helperMissing).call(depth0 != null ? depth0 : {},"hello",{"name":"i18n","hash":{},"data":data}))
14+
+ container.escapeExpression((lookupProperty(helpers,"i18n")||(depth0 && lookupProperty(depth0,"i18n"))||container.hooks.helperMissing).call(depth0 != null ? depth0 : (container.nullContext || {}),"hello",{"name":"i18n","hash":{},"data":data,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":16}}}))
1015
+ "\n"
11-
+ container.escapeExpression((helpers.i18n || (depth0 && depth0.i18n) || helpers.helperMissing).call(depth0 != null ? depth0 : {},"formatted","Edgar!",{"name":"i18n","hash":{},"data":data}))
16+
+ container.escapeExpression((lookupProperty(helpers,"i18n")||(depth0 && lookupProperty(depth0,"i18n"))||container.hooks.helperMissing).call(depth0 != null ? depth0 : (container.nullContext || {}),"formatted","Edgar!",{"name":"i18n","hash":{},"data":data,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":29}}}))
1217
+ "\n"
13-
+ container.escapeExpression((helpers.i18n || (depth0 && depth0.i18n) || helpers.helperMissing).call(depth0 != null ? depth0 : {},"args","a","b","c",{"name":"i18n","hash":{},"data":data}))
18+
+ container.escapeExpression((lookupProperty(helpers,"i18n")||(depth0 && lookupProperty(depth0,"i18n"))||container.hooks.helperMissing).call(depth0 != null ? depth0 : (container.nullContext || {}),"args","a","b","c",{"name":"i18n","hash":{},"data":data,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":27}}}))
1419
+ "\n";
1520
},"useData":true});
1621
var templates = Handlebars.templates = Handlebars.templates || {};
@@ -40,4 +45,4 @@ return I18n.t(key, i18nOpts);
4045

4146

4247

43-
})();
48+
})();

handlebars-maven-plugin/src/test/resources/helpers.expected

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
(function () {
22
// Source: src/test/resources/partials/level1/level1.html
33

4-
var template = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
5-
var helper;
4+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
5+
var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) {
6+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
7+
return parent[propertyName];
8+
}
9+
return undefined
10+
};
611

712
return "<h1>I'm "
8-
+ container.escapeExpression(((helper = (helper = helpers.level1 || (depth0 != null ? depth0.level1 : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"level1","hash":{},"data":data}) : helper)))
13+
+ container.escapeExpression(((helper = (helper = lookupProperty(helpers,"level1") || (depth0 != null ? lookupProperty(depth0,"level1") : depth0)) != null ? helper : container.hooks.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"level1","hash":{},"data":data,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":18}}}) : helper)))
914
+ "</h1>";
1015
},"useData":true});
1116
var templates = Handlebars.templates = Handlebars.templates || {};
@@ -16,11 +21,16 @@
1621

1722
// Source: src/test/resources/partials/partial/base.html
1823

19-
var template = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
20-
var stack1;
24+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
25+
var stack1, lookupProperty = container.lookupProperty || function(parent, propertyName) {
26+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
27+
return parent[propertyName];
28+
}
29+
return undefined
30+
};
2131

2232
return "I'm the base partial\n"
23-
+ ((stack1 = container.invokePartial(partials["partial/partial"],depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
33+
+ ((stack1 = container.invokePartial(lookupProperty(partials,"partial/partial"),depth0,{"name":"partial/partial","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
2434
},"usePartial":true,"useData":true});
2535
var templates = Handlebars.templates = Handlebars.templates || {};
2636
templates['partial/base'] = template;
@@ -30,7 +40,7 @@
3040

3141
// Source: src/test/resources/partials/partial/partial.html
3242

33-
var template = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
43+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
3444
return "I'm the child partial";
3545
},"useData":true});
3646
var templates = Handlebars.templates = Handlebars.templates || {};
@@ -41,7 +51,7 @@
4151

4252
// Source: src/test/resources/partials/root.html
4353

44-
var template = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
54+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
4555
return "Hello "
4656
+ container.escapeExpression(container.lambda(depth0, depth0))
4757
+ "!";
@@ -53,4 +63,4 @@
5363

5464

5565

56-
})();
66+
})();

handlebars-maven-plugin/src/test/resources/issue234.expected.js renamed to handlebars-maven-plugin/src/test/resources/issue234.expected

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Source: src/test/resources/templates/a.hbs
22
define('a.hbs', ['handlebars'], function(Handlebars) {
3-
var template = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
3+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
44
return "I'm template a.\nHello "
55
+ container.escapeExpression(container.lambda(depth0, depth0))
66
+ "!";
@@ -14,7 +14,7 @@ define('a.hbs', ['handlebars'], function(Handlebars) {
1414

1515
// Source: src/test/resources/templates/c.hbs
1616
define('c.hbs', ['handlebars'], function(Handlebars) {
17-
var template = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
17+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
1818
return "I'm template c.\nHello "
1919
+ container.escapeExpression(container.lambda(depth0, depth0))
2020
+ "!";
@@ -25,4 +25,3 @@ define('c.hbs', ['handlebars'], function(Handlebars) {
2525
partials['c'] = template;
2626
return template;
2727
});
28-

handlebars-maven-plugin/src/test/resources/specific-files.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function () {
22
// Source: src/test/resources/templates/a.hbs
33

4-
var template = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
4+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
55
return "I'm template a.\nHello "
66
+ container.escapeExpression(container.lambda(depth0, depth0))
77
+ "!";
@@ -14,7 +14,7 @@
1414

1515
// Source: src/test/resources/templates/c.hbs
1616

17-
var template = Handlebars.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
17+
var template = Handlebars.template({"compiler":[8,">= 4.3.0"],"main":function(container,depth0,helpers,partials,data) {
1818
return "I'm template c.\nHello "
1919
+ container.escapeExpression(container.lambda(depth0, depth0))
2020
+ "!";
@@ -26,4 +26,4 @@
2626

2727

2828

29-
})();
29+
})();

handlebars/src/main/java/com/github/jknack/handlebars/HandlebarsError.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
*/
3131
public class HandlebarsError implements Serializable {
3232

33-
/**
34-
* The serial UUID.
35-
*/
36-
private static final long serialVersionUID = -8453345164714701546L;
37-
3833
/**
3934
* The error's line number.
4035
*/

handlebars/src/test/java/com/github/jknack/handlebars/Issue322.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ public class Issue322 extends AbstractTest {
1111
@Test
1212
public void defaults() throws IOException {
1313
assertEquals(
14-
"{\"compiler\":[7,\">= 4.0.0\"],\"main\":function(container,depth0,helpers,partials,data) {\n" +
15-
" var helper;\n" +
16-
"\n" +
17-
" return \"Hi \"\n" +
18-
" + container.escapeExpression(((helper = (helper = helpers[\"var\"] || (depth0 != null ? depth0[\"var\"] : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === \"function\" ? helper.call(depth0 != null ? depth0 : {},{\"name\":\"var\",\"hash\":{},\"data\":data}) : helper)))\n" +
19-
" + \"!\";\n" +
20-
"},\"useData\":true}", compile("Hi {{var}}!").toJavaScript());
14+
"{\"compiler\":[8,\">= 4.3.0\"],\"main\":function(container,depth0,helpers,partials,data) {\n"
15+
+ " var helper, lookupProperty = container.lookupProperty || function(parent, propertyName) {\n"
16+
+ " if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {\n"
17+
+ " return parent[propertyName];\n"
18+
+ " }\n"
19+
+ " return undefined\n"
20+
+ " };\n"
21+
+ "\n"
22+
+ " return \"Hi \"\n"
23+
+ " + 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"
24+
+ " + \"!\";\n"
25+
+ "},\"useData\":true}", compile("Hi {{var}}!").toJavaScript());
2126
}
2227

2328
@Test(expected = IllegalArgumentException.class)

handlebars/src/test/java/com/github/jknack/handlebars/PrecompileHelperTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ public void precompile() throws IOException {
4141
InputStream in =
4242
getClass().getResourceAsStream("/" + wrapper + ".precompiled.js");
4343

44-
assertEquals(IOUtils.toString(in).replace("\r\n", "\n"), js.replace("\r\n", "\n"));
44+
assertEquals(wrapper, spaceSafe(IOUtils.toString(in)), spaceSafe(js));
4545

4646
in.close();
4747
}
4848

49+
private String spaceSafe(String value) {
50+
return value.replaceAll("\\s+", " ").trim();
51+
}
52+
4953
@Test
5054
public void precompileWithPartial() throws IOException {
5155
String js =
@@ -55,7 +59,7 @@ public void precompileWithPartial() throws IOException {
5559
InputStream in =
5660
getClass().getResourceAsStream("/partial.precompiled.js");
5761

58-
assertEquals(IOUtils.toString(in).replace("\r\n", "\n"), js.replace("\r\n", "\n"));
62+
assertEquals(spaceSafe(IOUtils.toString(in)), spaceSafe(js));
5963

6064
in.close();
6165
}

0 commit comments

Comments
 (0)