[英]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.