Interface Template

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Template EMPTY
      An empty template implementation.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.String apply​(Context context)
      Merge the template tree using the given context.
      void apply​(Context context, java.io.Writer writer)
      Merge the template tree using the given context.
      java.lang.String apply​(java.lang.Object context)
      Merge the template tree using the given context.
      void apply​(java.lang.Object context, java.io.Writer writer)
      Merge the template tree using the given context.
      <T> TypeSafeTemplate<T> as()
      Creates a new TypeSafeTemplate.
      <T,​S extends TypeSafeTemplate<T>>
      S
      as​(java.lang.Class<S> type)
      Creates a new TypeSafeTemplate.
      java.util.List<java.lang.String> collect​(TagType... tagType)
      Collect all the tag names under the given tagType.
      java.util.List<java.lang.String> collectReferenceParameters()
      Collects all the parameters which are also variables.
      java.lang.String filename()  
      int[] position()  
      java.lang.String text()
      Provide the raw text.
      java.lang.String toJavaScript()
      Convert this template to JavaScript template (a.k.a precompiled template).
    • Field Detail

      • EMPTY

        static final Template EMPTY
        An empty template implementation.
    • Method Detail

      • apply

        void apply​(java.lang.Object context,
                   java.io.Writer writer)
            throws java.io.IOException
        Merge the template tree using the given context.
        Parameters:
        context - The context object. May be null.
        writer - The writer object. Required.
        Throws:
        java.io.IOException - If a resource cannot be loaded.
      • apply

        java.lang.String apply​(java.lang.Object context)
                        throws java.io.IOException
        Merge the template tree using the given context.
        Parameters:
        context - The context object. May be null.
        Returns:
        The resulting template.
        Throws:
        java.io.IOException - If a resource cannot be loaded.
      • apply

        void apply​(Context context,
                   java.io.Writer writer)
            throws java.io.IOException
        Merge the template tree using the given context.
        Parameters:
        context - The context object. Required.
        writer - The writer object. Required.
        Throws:
        java.io.IOException - If a resource cannot be loaded.
      • apply

        java.lang.String apply​(Context context)
                        throws java.io.IOException
        Merge the template tree using the given context.
        Parameters:
        context - The context object. Required.
        Returns:
        The resulting template.
        Throws:
        java.io.IOException - If a resource cannot be loaded.
      • text

        java.lang.String text()
        Provide the raw text.
        Returns:
        The raw text.
      • toJavaScript

        java.lang.String toJavaScript()
        Convert this template to JavaScript template (a.k.a precompiled template). Compilation is done by handlebars.js and a JS Engine (usually Rhino).
        Returns:
        A pre-compiled JavaScript version of this template.
      • as

        <T,​S extends TypeSafeTemplate<T>> S as​(java.lang.Class<S> type)
        Creates a new TypeSafeTemplate.
        Type Parameters:
        T - The root type.
        S - The template type.
        Parameters:
        type - The template type. Required.
        Returns:
        A new TypeSafeTemplate.
      • collect

        java.util.List<java.lang.String> collect​(TagType... tagType)
        Collect all the tag names under the given tagType.

        Usage:

         {{hello}}
         {{var 1}}
         {{{tripleVar}}}
         

        collect(TagType.VAR) returns [hello, var]

        collect(TagType.TRIPLE_VAR) returns [tripleVar]

        collect(TagType.VAR, TagType.TRIPLE_VAR) returns [hello, var, tripleVar]

        Parameters:
        tagType - The tag type. Required.
        Returns:
        A list with tag names.
      • collectReferenceParameters

        java.util.List<java.lang.String> collectReferenceParameters()
        Collects all the parameters which are also variables.

        Usage:

         {{#if v1}}{{/if}}
         {{#each v2 "test"}}{{/each}}
         

        collectReferenceParameters() returns [v1, v2]

        Returns:
        A list with reference parameter names.
      • filename

        java.lang.String filename()
        Returns:
        The template file's name.
      • position

        int[] position()
        Returns:
        The line and column where the template was found.