-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: purchase reminder has readme and example java code
- Loading branch information
Showing
3 changed files
with
43 additions
and
1 deletion.
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,37 @@ | ||
import io.github.erdos.stencil.API; | ||
import io.github.erdos.stencil.EvaluatedDocument; | ||
import io.github.erdos.stencil.PreparedTemplate; | ||
import io.github.erdos.stencil.TemplateData; | ||
import io.github.erdos.stencil.standalone.JsonParser; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String... args) throws IOException { | ||
|
||
// prepare template file | ||
PreparedTemplate template = API.prepare(findFile("template.docx")); | ||
|
||
// read template data from a JSON | ||
String jsonData = new String(Files.readAllBytes(findFile("data.json").toPath())); | ||
Map templateDataMap = (Map) JsonParser.parse(jsonData); | ||
|
||
// assemble template data | ||
TemplateData data = TemplateData.fromMap(templateDataMap); | ||
|
||
// render template | ||
EvaluatedDocument result = API.render(template, data); | ||
|
||
// write generated document to a file | ||
File output = new File("purchase-reminder-output.docx"); | ||
result.writeToFile(output); | ||
} | ||
|
||
private static File findFile(String name) { | ||
return new File(Main.class.getResource(name).getFile()); | ||
} | ||
} |
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,5 @@ | ||
# Simple variables and tables | ||
|
||
In this example, you can see how to insert simple variables in a template. You can also see a table with dynamic rows. | ||
|
||
See the [Main.java](Main.java) file for usage. |
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