use of com.mitchellbosecke.pebble.PebbleEngine in project osiostatsgenerator by piyush1594.
the class StatsGenerator method printHTMLStats.
private static String printHTMLStats() throws PebbleException, IOException {
PebbleEngine engine = new PebbleEngine.Builder().build();
PebbleTemplate compiledTemplate = engine.getTemplate("templates/stats_table.html");
Writer writer = new StringWriter();
Map<String, Object> context = new HashMap<String, Object>();
context.put("websiteTitle", "OpenShift.io GitHub Stats");
context.put("stats", Stats);
context.put("now", Calendar.getInstance().getTime());
compiledTemplate.evaluate(writer, context);
String output = writer.toString();
return output;
}
use of com.mitchellbosecke.pebble.PebbleEngine in project Orchid by JavaEden.
the class PebbleCompiler method compile.
@Override
public void compile(OutputStream os, @Nullable OrchidResource resource, String extension, String input, Map<String, Object> data) {
try {
PebbleTemplateLoader loader = new PebbleTemplateLoader(contextProvider.get(), contextProvider.get().getTheme());
PebbleEngine engine = new PebbleEngine.Builder().loader(loader).executorService(executor).extension(extensionArray).methodAccessValidator(new NoOpMethodAccessValidator()).newLineTrimming(false).tagCache(tagCache).templateCache(templateCache).build();
engine.getExtensionRegistry().getAttributeResolver().add(new GetMethodAttributeResolver());
LexerImpl lexer = new LexerImpl(engine.getSyntax(), engine.getExtensionRegistry().getUnaryOperators().values(), engine.getExtensionRegistry().getBinaryOperators().values());
TokenStream tokenStream = lexer.tokenize(new StringReader(input), "");
Parser parser = new ParserImpl(engine.getExtensionRegistry().getUnaryOperators(), engine.getExtensionRegistry().getBinaryOperators(), engine.getExtensionRegistry().getTokenParsers(), new ParserOptions());
RootNode root = parser.parse(tokenStream);
PebbleTemplateImpl compiledTemplate = new PebbleTemplateImpl(engine, root, "");
for (NodeVisitorFactory visitorFactory : engine.getExtensionRegistry().getNodeVisitors()) {
visitorFactory.createVisitor(compiledTemplate).visit(root);
}
ByteArrayOutputStream os1 = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(os1, StandardCharsets.UTF_8);
compiledTemplate.evaluate(writer, data);
writer.close();
os.write(os1.toByteArray());
} catch (PebbleException e) {
OrchidExtensionsKt.logSyntaxError(input, extension, e.getLineNumber(), 0, e.getMessage(), e.getCause());
} catch (Exception e) {
Clog.e("Error rendering Pebble template (see template source below)", e);
Clog.e(input);
contextProvider.get().diagnosisMessage(() -> ExceptionUtils.getStackTrace(e));
}
}
use of com.mitchellbosecke.pebble.PebbleEngine in project symja_android_library by axkr.
the class TemplateUtils method getNewEngine.
public static PebbleEngine getNewEngine() {
PebbleEngine engine;
try {
Loader<?> loader = new ClasspathLoader();
if (templateLocations != null && !templateLocations.isEmpty()) {
List<Loader<?>> loaders = new ArrayList<>();
for (String templateLocation : templateLocations) {
FileLoader fileLoader = new FileLoader();
fileLoader.setPrefix(templateLocation);
loaders.add(fileLoader);
}
// add this one last, so it is shadowed
loaders.add(loader);
loader = new DelegatingLoader(loaders);
}
engine = new PebbleEngine.Builder().loader(loader).strictVariables(false).build();
} catch (PebbleException e) {
throw new IllegalStateException(e);
}
return engine;
}
Aggregations