Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mustache.java 0.8.x #244

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
6 changes: 3 additions & 3 deletions codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>mustache.java</artifactId>
<groupId>com.github.spullara.mustache.java</groupId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
</dependency>

<!-- ASM -->
Expand All @@ -35,7 +35,7 @@
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
3 changes: 1 addition & 2 deletions compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<parent>
<artifactId>mustache.java</artifactId>
<groupId>com.github.spullara.mustache.java</groupId>
<version>0.8.18-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
<version>0.8.19-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>compiler</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public static void escape(String value, Writer writer, boolean escapeEscaped) {
case '\'':
position = append(value, writer, position, i, "&#39;");
break;
case '=':
position = append(value, writer, position, i, "&#61;");
break;
case '`':
position = append(value, writer, position, i, "&#96;");
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,10 @@ public void testEscape() throws Exception {
escape("\"Hello\" &amp&#zz 'world'!\n&sam&#", sw, true);
assertEquals("&quot;Hello&quot; &amp;amp&amp;#zz &#39;world&#39;!&#10;&amp;sam&amp;#", sw.toString());
}
{
StringWriter sw = new StringWriter();
escape("\"Hello\" =` 'world'!", sw, true);
assertEquals("&quot;Hello&quot; &#61;&#96; &#39;world&#39;!", sw.toString());
}
}
}
5 changes: 2 additions & 3 deletions handlebar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<parent>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>mustache.java</artifactId>
<version>0.8.18-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
<version>0.8.19-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -28,7 +27,7 @@
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
Expand Down
9 changes: 4 additions & 5 deletions indy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
<parent>
<artifactId>mustache.java</artifactId>
<groupId>com.github.spullara.mustache.java</groupId>
<version>0.8.18-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
<version>0.8.19-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>indy</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>indy</name>
Expand All @@ -20,7 +19,7 @@
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>codegen</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
</dependency>

<!-- JRuby -->
Expand All @@ -47,7 +46,7 @@
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
6 changes: 3 additions & 3 deletions mustache-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<parent>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>mustache.java</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
</parent>
<artifactId>mustache-maven-plugin</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>mustache-maven-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
Expand Down Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>mustache.java</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
<description>Implementation of the Mustache language in Java.</description>

<modules>
Expand Down
5 changes: 2 additions & 3 deletions scala-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<parent>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>mustache.java</artifactId>
<version>0.8.18-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
<version>0.8.19-SNAPSHOT</version>
</parent>

<artifactId>scala-extensions</artifactId>
Expand All @@ -16,7 +15,7 @@
<module>scala-extensions-2.8</module>
<module>scala-extensions-2.9</module>
<module>scala-extensions-2.10</module>
<!-- <module>scala-extensions-2.11</module> -->
<module>scala-extensions-2.11</module>
</modules>
<packaging>pom</packaging>
</project>
2 changes: 1 addition & 1 deletion scala-extensions/scala-extensions-2.10/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ lazy val `scala-extensions-2-10` = project
libraryDependencies ++= Seq(
"com.github.spullara.mustache.java" % "compiler" % "0.8.17-SNAPSHOT",
"junit" % "junit" % "4.8.2" % "test",
"com.twitter" % "util-core" % "6.12.1"
"com.twitter" % "util-core" % "6.23.0"
)
)
8 changes: 4 additions & 4 deletions scala-extensions/scala-extensions-2.10/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>scala-extensions</artifactId>
<groupId>com.github.spullara.mustache.java</groupId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.8.18-SNAPSHOT</version>
<version>0.8.19-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -62,8 +62,8 @@
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
<version>6.12.1</version>
<artifactId>util-core_2.10</artifactId>
<version>6.23.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.twitter.mustache

import com.twitter.util.Future
import java.util.concurrent.Callable

class TwitterObjectHandler extends ScalaObjectHandler {

override def coerce(value: Object) = {
value match {
case f: Future[_] => {
new Callable[Any]() {
def call() = {
val value = f.get().asInstanceOf[Object]
coerce(value)
}
}
}
case _ => super.coerce(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,43 @@ class ObjectHandlerTest {
Assert.assertEquals("fred", sw.toString())
}

@Test
def testTwitterHandler() {
val pool = Executors.newCachedThreadPool()
val futurePool = FuturePool(pool)
val mf = new DefaultMustacheFactory()
mf.setObjectHandler(new TwitterObjectHandler)
mf.setExecutorService(pool)
val m = mf.compile(
new StringReader("{{#list}}{{optionalHello}}, {{futureWorld}}!" +
"{{#test}}?{{/test}}{{^test}}!{{/test}}{{#num}}?{{/num}}{{^num}}!{{/num}}" +
"{{#map}}{{value}}{{/map}}\n{{/list}}"),
"helloworld"
)
val sw = new StringWriter
val writer = m.execute(sw, new {
val list = Seq(new {
lazy val optionalHello = Some("Hello")
val futureWorld = futurePool {
"world"
}
val test = true
val num = 0
}, new {
val optionalHello = Some("Goodbye")
val futureWorld = futurePool {
"thanks for all the fish"
}
lazy val test = Future { false }
val map = Map(("value", "test"))
val num = 1
})
})
// You must use close if you use concurrent latched writers
writer.close()
Assert.assertEquals("Hello, world!?!\nGoodbye, thanks for all the fish!!?test\n", sw.toString)
}

@Test
def testScalaHandler() {
val pool = Executors.newCachedThreadPool()
Expand Down
11 changes: 11 additions & 0 deletions scala-extensions/scala-extensions-2.11/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
lazy val `scala-extensions-2-10` = project
.in(file("."))
.settings(
resolvers += Resolver.mavenLocal,
scalaVersion := "2.11.4",
libraryDependencies ++= Seq(
"com.github.spullara.mustache.java" % "compiler" % "0.8.17-SNAPSHOT",
"junit" % "junit" % "4.8.2" % "test",
"com.twitter" % "util-core" % "6.23.0"
)
)
112 changes: 112 additions & 0 deletions scala-extensions/scala-extensions-2.11/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>scala-extensions</artifactId>
<groupId>com.github.spullara.mustache.java</groupId>
<version>0.8.19-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>scala-extensions-2.11</artifactId>
<packaging>jar</packaging>

<name>scala-extensions-2.11</name>
<description>Scala extensions for mustache.java</description>
<url>http://github.com/spullara/mustache.java</url>

<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>

<developers>
<developer>
<name>Sam Pullara</name>
<email>[email protected]</email>
<url>http://www.javarants.com</url>
</developer>
</developers>

<repositories>
<repository>
<id>Twitter</id>
<url>http://maven.twttr.com/</url>
</repository>
</repositories>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.8.19-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<!-- Scala -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core_2.11</artifactId>
<version>6.23.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.14.1</version>
<dependencies>
<dependency>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading