com.google.template.soy.tofu
Interface SoyTofu


public interface SoyTofu

SoyTofu is the public interface for a Java object that represents a compiled Soy file set.

Important: Users should use the methods here (on a SoyTofu object created by Soy), but should not create their own implementations this interface.


Nested Class Summary
static interface SoyTofu.Renderer
          Renderer for a template.
 
Method Summary
 void addToCache(SoyMsgBundle msgBundle, SoyCssRenamingMap cssRenamingMap)
          Primes the cache with the given combination of SoyMsgBundle and SoyCssRenamingMap.
 SoyTofu forNamespace(String namespace)
          Gets a new SoyTofu instance with a different namespace (or no namespace).
 String getNamespace()
          Gets the namespace of this SoyTofu object.
 com.google.common.collect.ImmutableSortedSet<String> getUsedIjParamsForTemplate(SoyTemplateInfo templateInfo)
          Gets the set of injected param keys used by a template (and its transitive callees).
 com.google.common.collect.ImmutableSortedSet<String> getUsedIjParamsForTemplate(String templateName)
          Gets the set of injected param keys used by a template (and its transitive callees).
 boolean isCaching()
          Gets whether this instance caches intermediate Soy trees after substitutions from the SoyMsgBundle and the SoyCssRenamingMap.
 SoyTofu.Renderer newRenderer(SoyTemplateInfo templateInfo)
          Gets a new Renderer for a template.
 SoyTofu.Renderer newRenderer(String templateName)
          Gets a new Renderer for a template.
 String render(SoyTemplateInfo templateInfo, Map<String,?> data, SoyMsgBundle msgBundle)
          Deprecated. Use newRenderer(SoyTemplateInfo).
 String render(SoyTemplateInfo templateInfo, SoyMapData data, SoyMsgBundle msgBundle)
          Deprecated. Use newRenderer(SoyTemplateInfo).
 String render(String templateName, Map<String,?> data, SoyMsgBundle msgBundle)
          Deprecated. Use newRenderer(String).
 String render(String templateName, SoyMapData data, SoyMsgBundle msgBundle)
          Deprecated. Use newRenderer(String).
 

Method Detail

getNamespace

String getNamespace()
Gets the namespace of this SoyTofu object. The namespace is simply a convenience allowing newRenderer() to be called with a partial template name (e.g. ".fooTemplate"). Note: The namespace may be null, in which case newRenderer() must be called with the full template name.

Returns:
The namespace of this SoyTofu object, or null if no namespace.

forNamespace

SoyTofu forNamespace(@Nullable
                     String namespace)
Gets a new SoyTofu instance with a different namespace (or no namespace). Note: The new SoyTofu instance will still be backed by the same compiled Soy file set.

Parameters:
namespace - The namespace for the new SoyTofu instance, or null for no namespace.
Returns:
A new SoyTofu instance with a different namespace (or no namespace).

isCaching

boolean isCaching()
Gets whether this instance caches intermediate Soy trees after substitutions from the SoyMsgBundle and the SoyCssRenamingMap.

Returns:
Whether this instance caches intermediate Soy trees after substitutions from the SoyMsgBundle and the SoyCssRenamingMap.

addToCache

void addToCache(@Nullable
                SoyMsgBundle msgBundle,
                @Nullable
                SoyCssRenamingMap cssRenamingMap)
Primes the cache with the given combination of SoyMsgBundle and SoyCssRenamingMap. Priming the cache will eliminate the slowness for the first render. This method must be called separately for each distinct combination of SoyMsgBundle and SoyCssRenamingMap for which you wish to prime the cache. Only applicable when isCaching() is true.

Parameters:
msgBundle - The message bundle to prime the cache with.
cssRenamingMap - The CSS renaming map to prime the cache with.

newRenderer

SoyTofu.Renderer newRenderer(SoyTemplateInfo templateInfo)
Gets a new Renderer for a template.

The usage pattern is soyTofu.newRenderer(...).setData(...).setInjectedData(...).setMsgBundle(...).render() where any of the set* parts can be omitted if it's null.

Parameters:
templateInfo - Info for the template to render.
Returns:
A new renderer for the given template.

newRenderer

SoyTofu.Renderer newRenderer(String templateName)
Gets a new Renderer for a template.

The usage pattern is soyTofu.newRenderer(...).setData(...).setInjectedData(...).setMsgBundle(...).render() where any of the set* parts can be omitted if it's null.

Parameters:
templateName - The name of the template to render. If this SoyTofu instance is not namespaced, then this parameter should be the full name of the template including the namespace. If this SoyTofu instance is namespaced, then this parameter should be a partial name beginning with a dot (e.g. ".fooTemplate").
Returns:
A new renderer for the given template.

getUsedIjParamsForTemplate

com.google.common.collect.ImmutableSortedSet<String> getUsedIjParamsForTemplate(SoyTemplateInfo templateInfo)
Gets the set of injected param keys used by a template (and its transitive callees).

Note: The SoyTemplateInfo object already has a method getUsedIjParams(). That method should produce the same results as this method, unless the bundle of Soy files included when running the SoyParseInfoGenerator is different from the bundle of Soy files included when creating this SoyTofu object.

Parameters:
templateInfo - Info for the template to get injected params of.
Returns:
The set of injected param keys used by the given template.

getUsedIjParamsForTemplate

com.google.common.collect.ImmutableSortedSet<String> getUsedIjParamsForTemplate(String templateName)
Gets the set of injected param keys used by a template (and its transitive callees).

Parameters:
templateName - The name of the template to get injected params of.
Returns:
The set of injected param keys used by the given template.

render

@Deprecated
String render(SoyTemplateInfo templateInfo,
                         @Nullable
                         Map<String,?> data,
                         @Nullable
                         SoyMsgBundle msgBundle)
Deprecated. Use newRenderer(SoyTemplateInfo).

Renders a template.

Note: If you call this method instead of render(SoyTemplateInfo, SoyMapData, SoyMsgBundle), your template data will be converted to a SoyMapData object on each call. This may not be a big deal if you only need to use the data object once. But if you need to reuse the same data object for multiple calls, it's more efficient to build your own SoyMapData object and reuse it with render(SoyTemplateInfo, SoyMapData, SoyMsgBundle).

Parameters:
templateInfo - Info for the template to render.
data - The data to call the template with. Can be null if the template has no parameters.
msgBundle - The bundle of translated messages, or null to use the messages from the Soy source.
Returns:
The rendered text.

render

@Deprecated
String render(SoyTemplateInfo templateInfo,
                         @Nullable
                         SoyMapData data,
                         @Nullable
                         SoyMsgBundle msgBundle)
Deprecated. Use newRenderer(SoyTemplateInfo).

Renders a template.

Parameters:
templateInfo - Info for the template to render.
data - The data to call the template with. Can be null if the template has no parameters.
msgBundle - The bundle of translated messages, or null to use the messages from the Soy source.
Returns:
The rendered text.

render

@Deprecated
String render(String templateName,
                         @Nullable
                         Map<String,?> data,
                         @Nullable
                         SoyMsgBundle msgBundle)
Deprecated. Use newRenderer(String).

Renders a template.

Note: If you call this method instead of render(String, SoyMapData, SoyMsgBundle), your template data will be converted to a SoyMapData object on each call. This may not be a big deal if you only need to use the data object once. But if you need to reuse the same data object for multiple calls, it's more efficient to build your own SoyMapData object and reuse it with render(String, SoyMapData, SoyMsgBundle).

Parameters:
templateName - The name of the template to render. If this SoyTofu instance is namespaced, then this parameter should be a partial name beginning with a dot (e.g. ".fooTemplate").
data - The data to call the template with. Can be null if the template has no parameters.
msgBundle - The bundle of translated messages, or null to use the messages from the Soy source.
Returns:
The rendered text.

render

@Deprecated
String render(String templateName,
                         @Nullable
                         SoyMapData data,
                         @Nullable
                         SoyMsgBundle msgBundle)
Deprecated. Use newRenderer(String).

Renders a template.

Parameters:
templateName - The name of the template to render. If this SoyTofu instance is namespaced, then this parameter should be a partial name beginning with a dot (e.g. ".fooTemplate").
data - The data to call the template with. Can be null if the template has no parameters.
msgBundle - The bundle of translated messages, or null to use the messages from the Soy source.
Returns:
The rendered text.