Java Code Examples for com.google.template.soy.SoyFileSet#Builder

The following examples show how to use com.google.template.soy.SoyFileSet#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Renderer.java    From js-dossier with Apache License 2.0 6 votes vote down vote up
@Inject
Renderer(
    Provider<SoyFileSet.Builder> filesetBuilderProvider,
    ImmutableSet<Descriptors.GenericDescriptor> descriptors,
    JsonRenderer jsonRenderer) {
  this.filesetBuilderProvider = filesetBuilderProvider;
  this.tofu =
      filesetBuilderProvider
          .get()
          .add(Renderer.class.getResource("resources/types.soy"))
          .add(Renderer.class.getResource("resources/dossier.soy"))
          .addProtoDescriptors(descriptors)
          .build()
          .compileToTofu();
  this.jsonRenderer = jsonRenderer;
}
 
Example 2
Source File: ClosureTemplateEngine.java    From spark-template-engines with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a closure template engine with the given soy file paths.
 *
 * @param soyFilePaths one or more paths to .soy files relative to /templates in the resources folder.
 * @throws IllegalArgumentException if the input is null.
 */
public ClosureTemplateEngine(final String... soyFilePaths) {
    Preconditions.checkNotNull(soyFilePaths, "at least one path to soy file must be specified");

    SoyFileSet.Builder sfsBuilder = SoyFileSet.builder();
    for (final String soyFilePath : soyFilePaths) {
        sfsBuilder = sfsBuilder.add(ClosureTemplateEngine.class.getResource("/templates/" + soyFilePath));
    }

    soyTofu = sfsBuilder.build().compileToTofu();
}
 
Example 3
Source File: DefaultTofuCompiler.java    From spring-soy-view with Apache License 2.0 5 votes vote down vote up
private void addCompileTimeGlobalModel(final SoyFileSet.Builder sfsBuilder) {
    final Optional<SoyMapData> soyMapData = compileTimeGlobalModelResolver.resolveData();
    if (soyMapData.isPresent()) {
        final Map<String, ?> mapData = soyMapData.get().asMap();
        if (mapData.size() > 0) {
            logger.debug("Setting compile time globals, entries number:" + mapData.size());
            sfsBuilder.setCompileTimeGlobals(mapData);
        }
    }
}
 
Example 4
Source File: DefaultTofuCompiler.java    From spring-soy-view with Apache License 2.0 5 votes vote down vote up
private SoyFileSet buildSoyFileSetFrom(final Collection<URL> urls) {
    final SoyFileSet.Builder builder = new SoyFileSet.Builder();

    for (final URL url : urls) {
        builder.setAllowExternalCalls(true);
        builder.add(url);
    }

    addCompileTimeGlobalModel(builder);

    return builder.build();
}
 
Example 5
Source File: TemplateRenderer.java    From deploymentmanager-autogen with Apache License 2.0 4 votes vote down vote up
/** Use {@link FileSet#builder} to create an instance. */
@Inject
private Builder(SoyFileSet.Builder soyFileSetBuilder) {
  this.soyFileSetBuilder = soyFileSetBuilder;
}
 
Example 6
Source File: SanitizeHtmlFunction.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
@Inject
SanitizeHtmlFunction(Provider<SoyFileSet.Builder> sfsBuilder) {
  this.sfsBuilder = sfsBuilder;
}
 
Example 7
Source File: DefaultTofuCompiler.java    From spring-soy-view with Apache License 2.0 3 votes vote down vote up
@Override
public SoyTofu compile(@Nullable final Collection<URL> urls) throws IOException {
    Preconditions.checkNotNull("compileTimeGlobalModelResolver", compileTimeGlobalModelResolver);

    if (urls == null || urls.isEmpty()) {
        throw new IOException("Unable to compile, no urls found");
    }

    logger.debug("SoyTofu compilation of templates:" + urls.size());
    final long time1 = System.currentTimeMillis();

    final SoyFileSet.Builder sfsBuilder = new SoyFileSet.Builder();

    for (final URL url : urls) {
        sfsBuilder.add(url);
    }

    addCompileTimeGlobalModel(sfsBuilder);

    final SoyFileSet soyFileSet = sfsBuilder.build();

    final SoyTofuOptions soyTofuOptions = createSoyTofuOptions();
    final SoyTofu soyTofu = soyFileSet.compileToTofu(soyTofuOptions);

    final long time2 = System.currentTimeMillis();

    logger.debug("SoyTofu compilation complete." + (time2 - time1) + " ms");

    return soyTofu;
}