Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b2772f
commit be140ad
Showing
3 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
group 'org.jtwig' | ||
version '1.0' | ||
|
||
apply plugin: 'java' | ||
|
||
sourceCompatibility = 1.7 | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
jcenter() | ||
maven { | ||
url "http://dl.bintray.com/jtwig/maven" | ||
} | ||
} | ||
|
||
dependencies { | ||
compile "org.jtwig:jtwig-json-extension:1.+" | ||
compile "com.fasterxml.jackson.core:jackson-databind:2.5.3" | ||
} |
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,2 @@ | ||
rootProject.name = 'gradle-jtwig-json-extension-simple' | ||
|
45 changes: 45 additions & 0 deletions
45
gradle-jtwig-json-extension-simple/src/main/java/org/jtwig/example/json/SimpleJsonApp.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,45 @@ | ||
package org.jtwig.example.json; | ||
|
||
import org.jtwig.JtwigModel; | ||
import org.jtwig.JtwigTemplate; | ||
import org.jtwig.environment.EnvironmentConfiguration; | ||
import org.jtwig.environment.EnvironmentConfigurationBuilder; | ||
import org.jtwig.json.JsonExtension; | ||
|
||
public class SimpleJsonApp { | ||
public static void main(String[] args) { | ||
EnvironmentConfiguration configuration = EnvironmentConfigurationBuilder.configuration() | ||
.extensions().add(JsonExtension.defaultJsonExtension()).and() | ||
.build(); | ||
JtwigTemplate jtwigTemplate = JtwigTemplate.inlineTemplate("{{ json_encode(variable) }}", configuration); | ||
JtwigModel jtwigModel = JtwigModel.newModel().with("variable", new Model( | ||
"My Name", 30, "Committer" | ||
)); | ||
|
||
System.out.println(jtwigTemplate.render(jtwigModel)); | ||
} | ||
|
||
private static class Model { | ||
private final String name; | ||
private final int age; | ||
private final String group; | ||
|
||
public Model(String name, int age, String group) { | ||
this.name = name; | ||
this.age = age; | ||
this.group = group; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public String getGroup() { | ||
return group; | ||
} | ||
} | ||
} |