[英]How to integrate Print Directive of Google Closure Template (Soy)
如果可能的话,我想知道如何逐步集成Google Closure Template的打印插件(又名Soy),主要是因为我对Java很不好。 下面的页面说明了如何执行此操作,但是我需要更多详细信息。
https://developers.google.com/closure/templates/docs/plugins
任何帮助表示赞赏。
您需要查看Clojure源代码,以了解它如何创建自己的指令。 这很容易。
首先,您需要了解如何实施指令。 为此,请参见示例。 下载clojure模板源代码并查看:
./java/tests/com/google/template/soy/basicdirectives/TruncateDirective.java
然后,您需要了解一点点Google Guice 。 创建一个Guice模块以添加您的指令:
public class MySoyModule extends AbstractModule {
@Override
protected void configure() {
Multibinder<SoyPrintDirective> soyDirectivesSetBinder = Multibinder.newSetBinder(binder(), SoyPrintDirective.class);
soyDirectivesSetBinder.addBinding().to(DateDirective.class);
}
}
然后,使用Guice注入器实例化您的构建器,如下所示:
Injector injector = Guice.createInjector(new SoyModule(), new MySoyModule());
SoyFileSet.Builder sfsBuilder = injector.getInstance(SoyFileSet.Builder.class);
SoyFileSet sfs = sfsBuilder.add(SoyUtils.class.getResource(source)).build();
现在您可以调用模板:
SoyTofu simpleTofu = sfs.compileToTofu().forNamespace("soy.examples.simple");
而已。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.