简体   繁体   中英

How can I create my own custom functions for Closure templates in Plovr

I'm using Plovr and would like to use my own custom function (specifically a ucfirst function) inside templates. At the moment I'm only interested in rendering the templates as javascript, and since this is a fairly simple case I think actually writing the code shouldn't be too much of an issue (using a Plovr-included custom function as a starting point).

The question then becomes: how do I build it and use it with Plovr?

First, you should look at the soy-function-plugins plovr option, if you have not already.

As shown in the example, you need to create a Guice module that loads the classes for your custom functions (such as PlovrModule.java ). The example from the options page works without any extra work because org.plovr.soy.function.PlovrModule is already in plovr.jar , so it is already on the classpath when you run plovr. If your AbstractModule / SoyJsSrcFunction is compiled into another jar, such as my-soy.jar , then you also need to be sure to include it on the classpath when running plovr:

java -classpath my-soy.jar:plovr.jar org.plovr.cli.Main path/to/config.js OPTIONS

soy-function-plugins was introduced in theFebruary 2011 plovr release .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM