All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.plugins.spincast-pebble.spincast-pebble.html Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
{#==========================================
Spincast Pebble plugin
==========================================#}
{% extends "../../layout.html" %}

{% block sectionClasses %}plugins plugins-spincast-pebble{% endblock %}
{% block meta_title %}Plugins - Spincast Pebble{% endblock %}
{% block meta_description %}Spincast Pebble plugin provides templating functionalities using Pebble.{% endblock %}

{% block scripts %}

{% endblock %}

{% block body %}

Overview

The Spincast Pebble provides templating and HTML generation functionalities using Pebble. It contains an implementation of the ITemplatingEngine interface.

Most of the time, the ITemplatingEngine interface is used directly from the request context via the templating() add-on or via some dedicated methods on the response() add-on.

For example:

{% verbatim %}

public class AppController {

    public void myHandler(IDefaultRequestContext context) {

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("name", "Stromgol");

        // Sends an evaluated template using the "response()" add-on:
        context.response().sendHtmlTemplate("/templates/myTemplate.html", params);

        // Evaluates some inline content using the "templating()" add-on:
        String html = context.templating().evaluate("<h1>Hi {{name}}!</h1>", params);
        System.out.println(html); // <h1>Hi Stromgol!</h1>
    }
}
{% endverbatim %}

Installation

If you use the spincast-default artifact, this plugin is already installed so you have nothing more to do!

If you start from scratch using the spincast-core artifact, you can use the plugin by adding this artifact to your project:

<dependency>
    <groupId>org.spincast</groupId>
    <artifactId>spincast-plugins-pebble</artifactId>
    <version>{{spincastCurrrentVersion}}</version>
</dependency>

You then install the plugin's Guice module, by passing it to the Guice.createInjector(...) method:

Injector guice = Guice.createInjector(
        new SpincastCoreGuiceModule(args),
        new SpincastPebblePluginGuiceModule(IAppRequestContext.class, IAppWebsocketContext.class)
        // other modules...
        );

... or by using the install(...) method from your custom Guice module:

public class AppModule extends SpincastCoreGuiceModule {

    @Override
    protected void configure() {
        super.configure();
        install(new SpincastPebblePluginGuiceModule(getRequestContextType(), 
                                                    getWebsocketContextType()));
        // other modules...
    }
    
    // ...
}

The ITemplatingEngine interface

Methods :

  • String evaluate(String content, Map<String, Object> params)
    Evaluates the content, using the given parameters.
    Uses the default Locale.
  • String evaluate(String content, Map<String, Object> params, Locale locale)
    Evaluates the content, using the given parameters.
    Uses the specified Locale.
  • String evaluate(String content, IJsonObject jsonObject)
    Evaluates the content, using the given parameters. specified as a IJsonObject.
    Uses the default Locale.
  • String evaluate(String content, IJsonObject jsonObject, Locale locale)
    Evaluates the content, using the given parameters. specified as a IJsonObject.
    Uses the specified Locale.
  • String fromTemplate(String templatePath, Map<String, Object> params)
    Evaluates a template using the given parameters.
    Uses the default Locale.
    @param templatePath must be a classpath's relative path.
  • String fromTemplate(String templatePath, Map<String, Object> params, Locale locale)
    Evaluates a template using the given parameters.
    Uses the specified Locale.
    @param templatePath must be a classpath's relative path.
  • String fromTemplate(String templatePath, IJsonObject jsonObject)
    Evaluates a template using the parameters specified as a IJsonObject.
    Uses the default Locale.
    @param templatePath must be a classpath's relative path.
  • String fromTemplate(String templatePath, IJsonObject jsonObject, Locale locale)
    Evaluates a template using the parameters specified as a IJsonObject.
    Uses the specified Locale.
    @param templatePath must be a classpath's relative path.
  • String fromTemplate(String templatePath, boolean isClasspathPath, Map<String, Object> params)
    Evaluates a template using the given parameters.
    Uses the default Locale.
    @param isClasspathPath if true, the 'templatePath' is considered as a classpath's relative path. If false, it is considered as an absolute file system path.
  • String fromTemplate(String templatePath, boolean isClasspathPath, Map<String, Object> params, Locale locale)
    Evaluates a template using the given parameters.
    Uses the specified Locale.
    @param isClasspathPath if true, the 'templatePath' is considered as a classpath's relative path. If false, it is considered as an absolute file system path.
  • String fromTemplate(String templatePath, boolean isClasspathPath, IJsonObject jsonObject)
    Evaluates a template using the parameters specified as a IJsonObject.
    Uses the default Locale.
    @param isClasspathPath if true, the 'templatePath' is considered as a classpath's relative path. If false, it is considered as an absolute file system path.
  • String fromTemplate(String templatePath, boolean isClasspathPath, IJsonObject jsonObject, Locale locale)
    Evaluates a template using the parameters specified as a IJsonObject.
    Uses the specified Locale.
    @param isClasspathPath if true, the 'templatePath' is considered as a classpath's relative path. If false, it is considered as an absolute file system path.
  • {% verbatim %}
  • String createPlaceholder(String variable)
    Creates a placeholder using the current templating engine implementation.


    This is mainly useful for the tests, which don't know in advance which templating engine will be used, so which syntax to use for the placeholders.


    For example, using Pebble, a call to createPlaceholder("name") will result in "{{name}}" (without the quotes).

  • {% endverbatim %}

Configurations

You can bind a ISpincastPebbleTemplatingEngineConfig implementation to tweak the default configurations used by Pebble. By default, the SpincastPebbleTemplatingEngineConfigDefault class is used as the implementation.

The main configuration, getExtension(), allows you to add a custom extension to Pebble. Learn more about extensions on Pebble website.

  • Extension getExtension()
    Pebble extension to register: allows you to add custom filters, functions, etc.

{% endblock %}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy