Skip to content

Commit

Permalink
add new repository for community helpers #225 #217 #216 #218 #140 #208
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Aug 19, 2013
1 parent 2bd52a3 commit f2034a8
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 55 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ Hello {{#child}}{{this.value}}{{/child}}
## Want to contribute?
* Fork the project on Github.
* Wandering what to work on? See task/bug list and pick up something you would like to work on.
* Do you want to donate one or more helpers? See [handlebars=helpers](https://github.com/jknack/handlebars.java/tree/master/handlebars-helpers) a repository for community's helpers.
* Create an issue or fix one from [issues list](https://github.com/jknack/handlebars.java/issues).
* If you know the answer to a question posted to our [mailing list](https://groups.google.com/forum/#!forum/handlebarsjava) - don't hesitate to write a reply.
* Share your ideas or ask questions on [mailing list](https://groups.google.com/forum/#!forum/handlebarsjava) - don't hesitate to write a reply - that helps us improve javadocs/FAQ.
Expand Down
30 changes: 30 additions & 0 deletions handlebars-helpers/README.md
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.
66 changes: 66 additions & 0 deletions handlebars-helpers/pom.xml
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>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* {{#assign "benefitsTitle"}} benefits.{{type}}.title {{/assign}}
* &lt;span class="benefit-title"&gt; {{i18n benefitsTitle}} &lt;/span&gt;
* </pre>
*
* @author https://github.com/Jarlakxen
*/
public class AssignHelper implements Helper<String> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
/**
* 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<String> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

/**
* Commons number function helpers.
*
* @author https://github.com/Jarlakxen
*/
public enum NumberHelper implements Helper<Object> {

Expand Down
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"));
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package handlebarsjs.spec;
package com.github.jknack.handlebars.helper;

import java.io.IOException;

import org.junit.Test;

import com.github.jknack.handlebars.AbstractTest;
import com.github.jknack.handlebars.Handlebars;

public class IncludeTest extends AbstractTest {

@Override
protected Handlebars newHandlebars() {
return super.newHandlebars().registerHelper(IncludeHelper.NAME, IncludeHelper.INSTANCE);
}

@Test
public void include() throws IOException {
String template = "{{#each dudes}}{{include \"dude\" greeting=\"Hi\"}} {{/each}}";
Expand Down
15 changes: 14 additions & 1 deletion handlebars/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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">
<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>
Expand Down Expand Up @@ -55,6 +56,18 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@

import com.github.jknack.handlebars.cache.NullTemplateCache;
import com.github.jknack.handlebars.cache.TemplateCache;
import com.github.jknack.handlebars.helper.AssignHelper;
import com.github.jknack.handlebars.helper.BlockHelper;
import com.github.jknack.handlebars.helper.EachHelper;
import com.github.jknack.handlebars.helper.EmbeddedHelper;
import com.github.jknack.handlebars.helper.I18nHelper;
import com.github.jknack.handlebars.helper.IfHelper;
import com.github.jknack.handlebars.helper.IncludeHelper;
import com.github.jknack.handlebars.helper.MethodHelper;
import com.github.jknack.handlebars.helper.PartialHelper;
import com.github.jknack.handlebars.helper.PrecompileHelper;
Expand Down Expand Up @@ -1092,9 +1090,7 @@ private static void registerBuiltinsHelpers(final Handlebars handlebars) {
handlebars.registerHelper(EmbeddedHelper.NAME, EmbeddedHelper.INSTANCE);
handlebars.registerHelper(BlockHelper.NAME, BlockHelper.INSTANCE);
handlebars.registerHelper(PartialHelper.NAME, PartialHelper.INSTANCE);
handlebars.registerHelper(IncludeHelper.NAME, IncludeHelper.INSTANCE);
handlebars.registerHelper(PrecompileHelper.NAME, PrecompileHelper.INSTANCE);
handlebars.registerHelper(AssignHelper.NAME, AssignHelper.INSTANCE);
I18nHelper.registerHelpers(handlebars);
}

Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<modules>
<module>handlebars</module>
<module>handlebars-helpers</module>
<module>handlebars-springmvc</module>
<module>handlebars-json</module>
<module>handlebars-jackson2</module>
Expand Down

0 comments on commit f2034a8

Please sign in to comment.