java.lang.Object
com.renomad.minum.templating.TemplateProcessor
This class provides methods for working with templates.
The first step is to write a template. Here is an example:
Hello, my name is {{name}}
Then, feed that string into the buildProcessor(java.lang.String) method, like
this:
String input = "Hello, my name is {{name}}"
TemplateProcessor helloProcessor = TemplateProcessor.buildProcessor(input);
The returned value ("helloProcessor") can be rendered with different values. For example:
Map<String,String> myMap = Map.of("name", "Susanne");
String fullyRenderedString = helloProcessor.renderTemplate(myMap);
The result is:
Hello, my name is Susanne
-
Method Summary
Modifier and TypeMethodDescriptionstatic TemplateProcessorbuildProcessor(String template) Builds aTemplateProcessorfrom a string containing a proper template.Returns the raw template string provided at creation.renderTemplate(List<Map<String, String>> data) Given a list, map of key names -> value, render one template for each, joined by a newline.Render a list of maps.renderTemplate(Map<String, String> myMap) Given a map of key names -> value, render a template.
-
Method Details
-
renderTemplate
Given a map of key names -> value, render a template. -
renderTemplate
Given a list, map of key names -> value, render one template for each, joined by a newline. UserenderTemplate(List, String)for control over the delimiter. -
renderTemplate
Render a list of maps.Similar to
renderTemplate(Map)but takes a list of maps instead of just one. The "delimiter" argument is inserted between each rendered template. -
buildProcessor
Builds aTemplateProcessorfrom a string containing a proper template. Templated values are surrounded by double-curly-braces, i.e. {{foo}} or {{ foo }} -
getOriginalText
Returns the raw template string provided at creation.
-