Search in sources :

Example 1 with SoySauce

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;
}
Also used : SoySauce(com.google.template.soy.jbcsrc.api.SoySauce)

Example 2 with SoySauce

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);
}
Also used : SoySauce(com.google.template.soy.jbcsrc.api.SoySauce)

Example 3 with SoySauce

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);
}
Also used : SoySauce(com.google.template.soy.jbcsrc.api.SoySauce) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) Config(org.eclipse.jgit.lib.Config) SitePaths(com.google.gerrit.server.config.SitePaths) AbstractModule(com.google.inject.AbstractModule) DefaultMemoryCacheModule(com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) Test(org.junit.Test)

Aggregations

SoySauce (com.google.template.soy.jbcsrc.api.SoySauce)3 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)1 DefaultMemoryCacheModule (com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule)1 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)1 SitePaths (com.google.gerrit.server.config.SitePaths)1 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 TypeLiteral (com.google.inject.TypeLiteral)1 Config (org.eclipse.jgit.lib.Config)1 Test (org.junit.Test)1