com.google.template.soy
Class SoyUtils

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

public class SoyUtils
extends Object

Public utilities for Soy users.


Method Summary
static void generateCompileTimeGlobalsFile(Map<String,?> compileTimeGlobalsMap, Appendable output)
          Generates the text for a compile-time globals file in the format expected by the Soy compiler and appends the generated text to the given Appendable.
static void generateCompileTimeGlobalsFile(Map<String,?> compileTimeGlobalsMap, File file)
          Generates a compile-time globals file in the format expected by the Soy compiler.
static com.google.common.collect.ImmutableMap<String,com.google.template.soy.data.restricted.PrimitiveData> parseCompileTimeGlobals(com.google.common.io.InputSupplier<? extends Reader> inputSupplier)
          Parses a globals file in the format created by generateCompileTimeGlobalsFile(java.util.Map, java.lang.Appendable) into a map from global name to primitive value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

generateCompileTimeGlobalsFile

public static void generateCompileTimeGlobalsFile(Map<String,?> compileTimeGlobalsMap,
                                                  Appendable output)
                                           throws IOException
Generates the text for a compile-time globals file in the format expected by the Soy compiler and appends the generated text to the given Appendable.

The generated lines will follow the iteration order of the provided map.

Important: When you write the output to a file, be sure to use UTF-8 encoding.

Parameters:
compileTimeGlobalsMap - Map from compile-time global name to value. The values can be any of the Soy primitive types: null, boolean, integer, float (Java double), or string.
output - The object to append the generated text to.
Throws:
SoySyntaxException - If one of the values is not a valid Soy primitive type.
IOException - If there is an error appending to the given Appendable.
See Also:
generateCompileTimeGlobalsFile(Map, File)

generateCompileTimeGlobalsFile

public static void generateCompileTimeGlobalsFile(Map<String,?> compileTimeGlobalsMap,
                                                  File file)
                                           throws IOException
Generates a compile-time globals file in the format expected by the Soy compiler.

The generated lines will follow the iteration order of the provided map.

Parameters:
compileTimeGlobalsMap - Map from compile-time global name to value. The values can be any of the Soy primitive types: null, boolean, integer, float (Java double), or string.
file - The file to write the generated text to.
Throws:
SoySyntaxException - If one of the values is not a valid Soy primitive type.
IOException - If there is an error appending to the given Appendable.
See Also:
generateCompileTimeGlobalsFile(Map, Appendable)

parseCompileTimeGlobals

public static com.google.common.collect.ImmutableMap<String,com.google.template.soy.data.restricted.PrimitiveData> parseCompileTimeGlobals(com.google.common.io.InputSupplier<? extends Reader> inputSupplier)
                                                                                                                                    throws IOException,
                                                                                                                                           SoySyntaxException
Parses a globals file in the format created by generateCompileTimeGlobalsFile(java.util.Map, java.lang.Appendable) into a map from global name to primitive value.

Parameters:
inputSupplier - A supplier that returns a reader for the globals file.
Returns:
The parsed globals map.
Throws:
IOException - If an error occurs while reading the globals file.
SoySyntaxException - If the globals file is not in the correct format.