com.google.template.soy
Class SoyFileSet

java.lang.Object
  extended by com.google.template.soy.SoyFileSet

public final class SoyFileSet
extends Object

Represents a complete set of Soy files for compilation as one bundle. The files may depend on each other but should not have dependencies outside of the set.

Note: Soy file (or resource) contents must be encoded in UTF-8.


Nested Class Summary
static class SoyFileSet.Builder
          Builder for a SoyFileSet.
 
Method Summary
 SoyTofu compileToJavaObj()
          Deprecated. Use compileToTofu().
 SoyTofu compileToJavaObj(boolean useCaching)
          Deprecated. Use compileToTofu(com.google.template.soy.tofu.SoyTofuOptions).
 String compileToJavaSrc(SoyJavaSrcOptions javaSrcOptions, SoyMsgBundle msgBundle)
          Warning: The Java Src backend is experimental (incomplete, repetitive, untested, undocumented).
 List<String> compileToJsSrc(SoyJsSrcOptions jsSrcOptions, SoyMsgBundle msgBundle)
          Compiles this Soy file set into JS source code files and returns these JS files as a list of strings, one per file.
 SoyTemplateRuntimes compileToRuntimes(String bundleName, SoyJavaSrcOptions options, SoyMsgBundle msgBundle)
          Warning: The Java Src backend is experimental (incomplete, repetitive, untested, undocumented).
 SoyTofu compileToTofu()
          Compiles this Soy file set into a Java object (type SoyTofu) capable of rendering the compiled templates.
 SoyTofu compileToTofu(SoyTofuOptions tofuOptions)
          Compiles this Soy file set into a Java object (type SoyTofu) capable of rendering the compiled templates.
 SoyMsgBundle extractMsgs()
          Extracts all messages from this Soy file set into a SoyMsgBundle (which can then be turned into an extracted messages file with the help of a SoyMsgBundleHandler).
 com.google.common.collect.ImmutableMap<String,String> generateParseInfo(String javaPackage, String javaClassNameSource)
          Generates Java classes containing parse info (param names, template names, meta info).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

generateParseInfo

public com.google.common.collect.ImmutableMap<String,String> generateParseInfo(String javaPackage,
                                                                               String javaClassNameSource)
                                                                        throws SoySyntaxException
Generates Java classes containing parse info (param names, template names, meta info). There will be one Java class per Soy file.

Parameters:
javaPackage - The Java package for the generated classes.
javaClassNameSource - Source of the generated class names. Must be one of "filename", "namespace", or "generic".
Returns:
A map from generated file name (of the form "<*>SoyInfo.java") to generated file content.
Throws:
SoySyntaxException - If a syntax error is found.

extractMsgs

public SoyMsgBundle extractMsgs()
                         throws SoySyntaxException
Extracts all messages from this Soy file set into a SoyMsgBundle (which can then be turned into an extracted messages file with the help of a SoyMsgBundleHandler).

Returns:
A SoyMsgBundle containing all the extracted messages (locale "en").
Throws:
SoySyntaxException - If a syntax error is found.

compileToTofu

public SoyTofu compileToTofu()
                      throws SoySyntaxException
Compiles this Soy file set into a Java object (type SoyTofu) capable of rendering the compiled templates. The resulting SoyTofu does not cache intermediate results after substitutions from the SoyMsgBundle and the SoyCssRenamingMap.

Returns:
The resulting SoyTofu object.
Throws:
SoySyntaxException - If a syntax error is found.
See Also:
compileToTofu(com.google.template.soy.tofu.SoyTofuOptions)

compileToTofu

public SoyTofu compileToTofu(SoyTofuOptions tofuOptions)
                      throws SoySyntaxException
Compiles this Soy file set into a Java object (type SoyTofu) capable of rendering the compiled templates.

Parameters:
tofuOptions - The compilation options for the Tofu backend.
Returns:
The resulting SoyTofu object.
Throws:
SoySyntaxException - If a syntax error is found.

compileToJavaObj

@Deprecated
public SoyTofu compileToJavaObj()
                         throws SoySyntaxException
Deprecated. Use compileToTofu().

Compiles this Soy file set into a Java object (type SoyTofu) capable of rendering the compiled templates. The resulting SoyTofu does not cache intermediate results after substitutions from the SoyMsgBundle and the SoyCssRenamingMap.

Returns:
The result of compiling this Soy file set into a Java object.
Throws:
SoySyntaxException - If a syntax error is found.
See Also:
compileToTofu()

compileToJavaObj

@Deprecated
public SoyTofu compileToJavaObj(boolean useCaching)
                         throws SoySyntaxException
Deprecated. Use compileToTofu(com.google.template.soy.tofu.SoyTofuOptions).

Compiles this Soy file set into a Java object (type SoyTofu) capable of rendering the compiled templates.

Parameters:
useCaching - Whether the resulting SoyTofu instance should cache intermediate results after substitutions from the SoyMsgBundle and the SoyCssRenamingMap. It is recommended to set this param to true if you're planning to reuse the SoyTofu instance to render multiple times.

Specifically, if this param is set to true, then (a) The first time the SoyTofu is used with a new combination of SoyMsgBundle and SoyCssRenamingMap, the render will be slower. (Note that this first-render slowness can be eliminated by calling the method SoyTofu.addToCache(com.google.template.soy.msgs.SoyMsgBundle, com.google.template.soy.shared.SoyCssRenamingMap) to prime the cache.) (b) The subsequent times the SoyTofu is used with an already-seen combination of SoyMsgBundle and SoyCssRenamingMap, the render will be faster.

The cache will use memory proportional to the number of distinct combinations of SoyMsgBundle and SoyCssRenamingMap your app uses (note most apps have at most one SoyCssRenamingMap). If you find memory usage to be a problem, you can manually control the contents of the cache. See SoyTofu.Renderer#setDontAddToCache for details.

Returns:
The result of compiling this Soy file set into a Java object.
Throws:
SoySyntaxException - If a syntax error is found.
See Also:
compileToTofu(com.google.template.soy.tofu.SoyTofuOptions)

compileToRuntimes

public SoyTemplateRuntimes compileToRuntimes(String bundleName,
                                             SoyJavaSrcOptions options,
                                             SoyMsgBundle msgBundle)
Warning: The Java Src backend is experimental (incomplete, repetitive, untested, undocumented).

Returns a bundle of templates compiled using the experimental java compiler that will be automatically recompiled if the underlying Soy sources are modified.

Returns:
The compiled result.

compileToJavaSrc

public String compileToJavaSrc(SoyJavaSrcOptions javaSrcOptions,
                               SoyMsgBundle msgBundle)
Warning: The Java Src backend is experimental (incomplete, repetitive, untested, undocumented).

To use Soy from Java, you should call compileToTofu() to obtain a SoyTofu object that will be able to render any public template in this Soy file set.

Parameters:
javaSrcOptions - The compilation options for the Java Src output target.
msgBundle - The bundle of translated messages, or null to use the messages from the Soy source.
Returns:
Java source code in one big ugly blob. Can be put inside any class without needing additional imports because all class names in the generated code are fully qualified.

compileToJsSrc

public List<String> compileToJsSrc(SoyJsSrcOptions jsSrcOptions,
                                   @Nullable
                                   SoyMsgBundle msgBundle)
                            throws SoySyntaxException
Compiles this Soy file set into JS source code files and returns these JS files as a list of strings, one per file.

Parameters:
jsSrcOptions - The compilation options for the JS Src output target.
msgBundle - The bundle of translated messages, or null to use the messages from the Soy source.
Returns:
A list of strings where each string represents the JS source code that belongs in one JS file. The generated JS files correspond one-to-one to the original Soy source files.
Throws:
SoySyntaxException - If a syntax error is found.