Search in sources :

Example 1 with SafeString

use of com.mitchellbosecke.pebble.extension.escaper.SafeString in project Orchid by JavaEden.

the class PebbleWrapperTemplateFilter method doApply.

private Object doApply(Object input, Map<String, Object> args, EvaluationContext context) throws PebbleException {
    args.put(inputParam, input);
    TemplateFunction freshFunction = contextProvider.get().resolve(functionClass);
    Object pageVar = context.getVariable("page");
    final OrchidPage actualPage;
    if (pageVar instanceof OrchidPage) {
        actualPage = (OrchidPage) pageVar;
    } else {
        actualPage = null;
    }
    freshFunction.extractOptions(contextProvider.get(), args);
    Object output = freshFunction.apply(contextProvider.get(), actualPage);
    if (freshFunction.isSafeString()) {
        return new SafeString(output.toString());
    } else {
        return output;
    }
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) TemplateFunction(com.eden.orchid.api.compilers.TemplateFunction) SafeString(com.mitchellbosecke.pebble.extension.escaper.SafeString)

Example 2 with SafeString

use of com.mitchellbosecke.pebble.extension.escaper.SafeString in project Orchid by JavaEden.

the class PebbleWrapperTemplateFunction method doExecute.

private Object doExecute(Map<String, Object> args, EvaluationContext context) {
    TemplateFunction freshFunction = contextProvider.get().resolve(functionClass);
    Object pageVar = context.getVariable("page");
    final OrchidPage actualPage;
    if (pageVar instanceof OrchidPage) {
        actualPage = (OrchidPage) pageVar;
    } else {
        actualPage = null;
    }
    freshFunction.extractOptions(contextProvider.get(), args);
    Object output = freshFunction.apply(contextProvider.get(), actualPage);
    if (freshFunction.isSafeString()) {
        return new SafeString(output.toString());
    } else {
        return output;
    }
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) TemplateFunction(com.eden.orchid.api.compilers.TemplateFunction) SafeString(com.mitchellbosecke.pebble.extension.escaper.SafeString)

Aggregations

TemplateFunction (com.eden.orchid.api.compilers.TemplateFunction)2 OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)2 SafeString (com.mitchellbosecke.pebble.extension.escaper.SafeString)2