Java Code Examples for com.mitchellbosecke.pebble.PebbleEngine#getTemplate()

The following examples show how to use com.mitchellbosecke.pebble.PebbleEngine#getTemplate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CMSURLHandler.java    From fenixedu-cms with GNU Lesser General Public License v3.0 7 votes vote down vote up
private void handleLeadingSlash(final HttpServletRequest req, HttpServletResponse res, Site sites) throws PebbleException,
        IOException, ServletException {
    if (req.getMethod().equals("GET")) {
        res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
        res.setHeader("Location", rewritePageUrl(req));
        return;
    } else if (req.getMethod().equals("POST")) {
        if (CoreConfiguration.getConfiguration().developmentMode()) {
            PebbleEngine engine = new PebbleEngine.Builder().loader(new StringLoader()).extension(new CMSExtensions()).build();
            PebbleTemplate compiledTemplate =
                    engine.getTemplate("<html><head></head><body><h1>POST action with backslash</h1><b>You posting data with a URL with a backslash. Alter the form to post with the same URL without the backslash</body></html>");
            res.setStatus(500);
            res.setContentType("text/html");
            compiledTemplate.evaluate(res.getWriter(), I18N.getLocale());
        } else {
            renderer.errorPage(req, res, sites, 500);
        }
    }
}
 
Example 2
Source File: PebbleTemplateEngine.java    From pippo with Apache License 2.0 6 votes vote down vote up
@Override
public void renderString(String templateContent, Map<String, Object> model, Writer writer) {
    String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG);

    if (StringUtils.isNullOrEmpty(language)) {
        language = getLanguageOrDefault(language);
    }
    Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE);
    if (locale == null) {
        locale = getLocaleOrDefault(language);
    }

    try {
        PebbleEngine stringEngine = new PebbleEngine.Builder()
            .loader(new StringLoader())
            .strictVariables(engine.isStrictVariables())
            .templateCache(null)
            .build();

        PebbleTemplate template = stringEngine.getTemplate(templateContent);
        template.evaluate(writer, model, locale);
        writer.flush();
    } catch (Exception e) {
        throw new PippoRuntimeException(e);
    }
}
 
Example 3
Source File: Pebble.java    From template-benchmark with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Setup
public void setup() throws PebbleException {
    PebbleEngine engine = new PebbleEngine.Builder().autoEscaping(false).build();
    template = engine.getTemplate("templates/stocks.pebble.html");
    this.context = getContext();
}