Search in sources :

Example 1 with STRawGroupDir

use of org.stringtemplate.v4.STRawGroupDir in project stagen by wiztools.

the class STTemplateExecutor method render.

@Override
public String render(Map<String, Object> config, File templateFile) throws ExecutorException {
    try {
        final File tmplDir = templateFile.getParentFile();
        final String tmplName = Util.getBaseFileName(templateFile.getName());
        STGroup stg = new STRawGroupDir(tmplDir.toURI().toURL(), Charsets.UTF_8.name(), delimiterStartChar, delimiterStopChar);
        ST st = stg.getInstanceOf(tmplName);
        // Populate data:
        config.entrySet().stream().forEach((e) -> {
            st.add(e.getKey(), e.getValue());
        });
        return st.render();
    } catch (MalformedURLException ex) {
        throw new ExecutorException(ex);
    }
}
Also used : ST(org.stringtemplate.v4.ST) MalformedURLException(java.net.MalformedURLException) STGroup(org.stringtemplate.v4.STGroup) STRawGroupDir(org.stringtemplate.v4.STRawGroupDir) File(java.io.File)

Aggregations

File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 ST (org.stringtemplate.v4.ST)1 STGroup (org.stringtemplate.v4.STGroup)1 STRawGroupDir (org.stringtemplate.v4.STRawGroupDir)1