Closure Tools

Plugins

  1. Overview
  2. Plugins for Functions or Print Directives
  3. Message Plugins

Overview

You can write simple plugins in Java for any additional functions, print directives, or other message file formats that you need. To write a plugin, first check out the Closure Templates source code from the Closure Templates project page, then follow the instructions below to create your own plugin classes, using the existing plugin packages as examples.

For full details of plugin interfaces in Closure Templates, see the Javadoc.

Plugins for Functions or Print Directives

To write additional functions to use in template expressions, use the package basicfunctions as an example. If you're using templates from Java, your functions' plugin classes must implement the interface SoyTofuFunction, and if you're using templates from JavaScript, your functions' plugin classes must implement the interface SoyJsSrcFunction.

To write additional print directives to use in your templates' print commands, use the existing package basicdirectives as an example. If you're using templates from Java, your directives' plugin classes must implement the interface SoyTofuPrintDirective, and if you're using templates from JavaScript, your directives' plugin classes must implement the interface SoyJsSrcPrintDirective.

Your plugin implementations can use the Java packages named restricted. However, they must not use packages named internal nor any compiler passes, which are usually in packages named *passes.

You also need to write a simple Guice module that binds your plugins. Use the existing plugin packages as examples. To use your plugins from Java, your application should create a Guice injector that includes your plugin's Guice module. To use your plugins with the executable jars, pass the plugin's Guice module class to the command-line flag --pluginModules.

Message Plugins

To write a plugin for a custom message type, use the package xliffmsgplugin as an example by writing a class that implements the SoyMsgPlugin interface.

If your project uses Guice, or if you're using the executable jars SoyToJsSrcCompiler or SoyMsgExtractor, you need a simple Guice module that binds your plugin. To do this, use XliffMsgPluginModule.java as an example. To use your message plugin with the executable jars, pass the plugin's Guice module class to the command-line flag --messagePluginModule.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.