use of org.jtwig.JtwigModel in project sakuli by ConSol.
the class AbstractTemplateOutputBuilder method createOutput.
/**
* Converts the current test suite to a string based on the template for the concrete converter.
*
* @return
*/
public String createOutput() throws SakuliForwarderException {
try {
JtwigModel model = createModel();
EnvironmentConfiguration configuration = EnvironmentConfigurationBuilder.configuration().extensions().add(new SpacelessExtension(new SpacelessConfiguration(new LeadingWhitespaceRemover()))).and().functions().add(new IsBlankFunction()).add(new GetOutputStateFunction()).add(new GetOutputDurationFunction()).add(new ExtractScreenshotFunction(screenshotDivConverter)).add(new AbbreviateFunction()).and().build();
JtwigTemplate template = JtwigTemplate.fileTemplate(getTemplatePath().toFile(), configuration);
logger.debug(String.format("Render model into JTwig template. Model: '%s'", model));
return template.render(model);
} catch (Throwable thr) {
throw new SakuliForwarderException(thr, "Exception during rendering of Twig template occurred!");
}
}
use of org.jtwig.JtwigModel in project amos-ss17-alexa by c-i-ber.
the class BudgetReportService method onIntent.
@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
IntentRequest request = requestEnvelope.getRequest();
if (request.getIntent().getName().equals(BUDGET_REPORT_EMAIL_INTENT)) {
// Load the mail template from resources
JtwigTemplate template = JtwigTemplate.classpathTemplate("html-templates/budget-report.twig");
List<BudgetReportCategory> categories = new ArrayList<>();
// DynamoDbClient.instance.getItems(Category.TABLE_NAME, Category::new);
List<Category> dbCategories = DynamoDbMapper.getInstance().loadAll(Category.class);
for (Category cat : dbCategories) {
categories.add(new BudgetReportCategory(cat.getName(), cat.getSpending(), cat.getLimit()));
}
JtwigModel model = JtwigModel.newModel().with("categories", categories);
// Render mail template
String body = template.render(model);
String answer = "Okay, ich habe dir deinen Ausgabenreport per E-Mail gesendet.";
boolean isDebug = SessionStorage.getInstance().getStorage(requestEnvelope.getSession().getSessionId()).containsKey("DEBUG");
if (!isDebug && !EMailClient.SendHTMLEMail("Ausgabenreport", body)) {
answer = "Leider konnte der Ausgabenreport nicht gesendet werden.";
}
return getResponse("Ausgabenreport", answer);
}
return null;
}
use of org.jtwig.JtwigModel in project sakuli by ConSol.
the class AbstractTemplateOutputBuilder method createOutput.
/**
* Converts the current test data entity to a string based on the template for the concrete converter.
*
* @param abstractTestDataEntity Test data entity, which has to be converted
* @return A string representation of the provided test data entity
*/
public String createOutput(AbstractTestDataEntity abstractTestDataEntity) throws SakuliForwarderCheckedException {
try {
JtwigModel model = createModel(abstractTestDataEntity);
EnvironmentConfiguration configuration = EnvironmentConfigurationBuilder.configuration().extensions().add(new SpacelessExtension(new SpacelessConfiguration(new LeadingWhitespaceRemover()))).and().functions().add(new IsBlankFunction()).add(new GetOutputStateFunction()).add(new GetOutputDurationFunction()).add(new ExtractScreenshotFunction(screenshotDivConverter)).add(new AbbreviateFunction()).add(new UnixTimestampConverterFunction()).add(new GetTestDataEntityTypeFunction()).and().build();
JtwigTemplate template = JtwigTemplate.fileTemplate(getTemplatePath().toFile(), configuration);
logger.debug(String.format("Render model into JTwig template. Model: '%s'", model));
return template.render(model);
} catch (Exception e) {
throw new SakuliForwarderCheckedException(e, "Exception during rendering of Twig template occurred!");
}
}
use of org.jtwig.JtwigModel in project sakuli by ConSol.
the class AbstractTemplateOutputBuilderTest method createModel.
@Test
public void createModel() {
JtwigModel model = testling.createModel(testSuite);
assertEquals(model.get(TEST_DATA_ENTITY.getName()).get().getValue(), testSuite);
assertEquals(model.get(SAKULI_PROPERTIES.getName()).get().getValue(), sakuliProperties);
assertEquals(model.get(CHECK_MK_PROPERTIES.getName()).get().getValue(), checkMKProperties);
}
Aggregations