use of com.google.template.soy.jbcsrc.api.SoySauce in project closure-templates by google.
the class SoyFileSet method compileTemplates.
/**
* Compiles this Soy file set into a set of java classes implementing the {@link SoySauce}
* interface.
*
* <p>This is useful for implementing 'edit refresh' workflows. Most production usecases should
* use the command line interface to 'ahead of time' compile templates to jar files and then use
* {@code PrecompiledSoyModule} to get access to a {@link SoySauce} object without invoking the
* compiler. This will allow applications to avoid invoking the soy compiler at runtime which can
* be relatively slow.
*
* @return A set of compiled templates
* @throws SoyCompilationException If compilation fails.
*/
public SoySauce compileTemplates() {
resetErrorReporter();
disallowExternalCalls();
ServerCompilationPrimitives primitives = compileForServerRendering();
throwIfErrorsPresent();
SoySauce sauce = doCompileSoySauce(primitives);
reportWarnings();
return sauce;
}
use of com.google.template.soy.jbcsrc.api.SoySauce in project gerrit by GerritCodeReview.
the class OutgoingEmail method configureRenderer.
/**
* Configures a soy renderer for the given template name and rendering data map.
*/
private SoySauce.Renderer configureRenderer(String templateName) {
int baseNameIndex = templateName.indexOf("_");
// In case there are multiple templates in file (now only InboundEmailRejection and
// InboundEmailRejectionHtml).
String fileNamespace = baseNameIndex == -1 ? templateName : templateName.substring(0, baseNameIndex);
String templateInFileNamespace = String.join(".", SOY_TEMPLATE_NAMESPACE, fileNamespace, templateName);
String templateInCommonNamespace = String.join(".", SOY_TEMPLATE_NAMESPACE, templateName);
SoySauce soySauce = args.soySauce.get();
// For backwards compatibility with existing customizations and plugin templates with the
// old non-unique namespace.
String fullTemplateName = soySauce.hasTemplate(templateInFileNamespace) ? templateInFileNamespace : templateInCommonNamespace;
return soySauce.renderTemplate(fullTemplateName).setData(soyContext);
}
use of com.google.template.soy.jbcsrc.api.SoySauce in project gerrit by GerritCodeReview.
the class MailSoySauceModuleTest method soySauceProviderReturnsCachedValue.
@Test
public void soySauceProviderReturnsCachedValue() throws Exception {
SitePaths sitePaths = new SitePaths(Paths.get("."));
Injector injector = Guice.createInjector(new MailSoySauceModule(), new AbstractModule() {
@Override
protected void configure() {
super.configure();
bind(ListeningExecutorService.class).annotatedWith(CacheRefreshExecutor.class).toInstance(newDirectExecutorService());
bind(SitePaths.class).toInstance(sitePaths);
bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(new Config());
bind(MetricMaker.class).to(DisabledMetricMaker.class);
install(new DefaultMemoryCacheModule());
}
});
Provider<SoySauce> soySauceProvider = injector.getProvider(Key.get(SoySauce.class, MailTemplates.class));
LoadingCache<String, SoySauce> cache = injector.getInstance(Key.get(new TypeLiteral<LoadingCache<String, SoySauce>>() {
}, Names.named(MailSoySauceModule.CACHE_NAME)));
assertThat(cache.stats().loadCount()).isEqualTo(0);
// Theoretically, this can be flaky, if the delay before the second get takes several seconds.
// We assume that tests is fast enough.
assertThat(soySauceProvider.get()).isNotNull();
assertThat(soySauceProvider.get()).isNotNull();
assertThat(cache.stats().loadCount()).isEqualTo(1);
}
Aggregations