-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
162 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
handlebars-helpers | ||
====== | ||
|
||
A collection of Handlebars.java helpers, donated by the community. | ||
|
||
[assign](https://github.com/jknack/handlebars.java/blob/master/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/AssignHelper.java) | ||
====== | ||
create auxiliary/temprary variables. Example: | ||
|
||
``` | ||
{{#assign "benefitsTitle"}} benefits.{{type}}.title {{/assign}} | ||
<span class="benefit-title"> {{i18n benefitsTitle}} </span> | ||
``` | ||
|
||
[isEven, isOdd & stripes](https://github.com/jknack/handlebars.java/blob/master/handlebars-helpers/src/main/java/com/github/jknack/handlebars/helper/NumberHelper.java) | ||
====== | ||
commons functions for numbers | ||
|
||
``` | ||
{{isEven number}} // output: even | ||
{{isEven number "row-even"}} // output: row-even | ||
``` | ||
|
||
include | ||
===== | ||
This is a port of [https://github.com/wycats/handlebars.js/pull/368](https://github.com/wycats/handlebars.js/pull/368). | ||
|
||
**NOTE**: The helper is required if you want to use handlebars.js, bc handlebars.js doesn't implement ```partials``` according to the Mustache Spec. | ||
All the feature of the ```include``` helper are supported with plain ```partials``` in Handlebars.java. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<parent> | ||
<groupId>com.github.jknack</groupId> | ||
<artifactId>handlebars.java</artifactId> | ||
<version>1.1.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.github.jknack</groupId> | ||
<artifactId>handlebars-helpers</artifactId> | ||
|
||
<name>Handlebars Helpers</name> | ||
<description>A collection helpers donated by the community</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.jknack</groupId> | ||
<artifactId>handlebars</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- Servlet API --> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.jknack</groupId> | ||
<artifactId>handlebars</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
<classifier>tests</classifier> | ||
</dependency> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.easymock</groupId> | ||
<artifactId>easymock</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
handlebars-helpers/src/test/java/com/github/jknack/handlebars/helper/AssignHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.jknack.handlebars.helper; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.Test; | ||
|
||
import com.github.jknack.handlebars.AbstractTest; | ||
import com.github.jknack.handlebars.Context; | ||
import com.github.jknack.handlebars.Handlebars; | ||
|
||
public class AssignHelperTest extends AbstractTest { | ||
|
||
@Override | ||
protected Handlebars newHandlebars() { | ||
return super.newHandlebars().registerHelper(AssignHelper.NAME, AssignHelper.INSTANCE); | ||
} | ||
|
||
@Test | ||
public void assignResult() throws IOException { | ||
shouldCompileTo( | ||
"{{#assign \"benefitsTitle\"}} benefits.{{type}}.title {{/assign}}", | ||
$("type", "discounts"), ""); | ||
} | ||
|
||
@Test | ||
public void assignContext() throws IOException { | ||
Context context = Context.newContext($("type", "discounts")); | ||
|
||
shouldCompileTo("{{#assign \"benefitsTitle\"}} benefits.{{type}}.title {{/assign}}", | ||
context, ""); | ||
|
||
assertEquals("benefits.discounts.title", context.data("benefitsTitle")); | ||
} | ||
|
||
} |
8 changes: 7 additions & 1 deletion
8
...t/java/handlebarsjs/spec/IncludeTest.java → ...jknack/handlebars/helper/IncludeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
handlebars/src/test/java/com/github/jknack/handlebars/AssignHelperTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters