Interface TypeSafeTemplate<T>

  • Type Parameters:
    T - The root object type.

    public interface TypeSafeTemplate<T>
    Make handlebars templates type-safe. Users can extend the TypeSafeTemplate and add new methods.

    Usage:

      public interface UserTemplate extends TypeSafeTemplate<User> {
        UserTemplate setAge(int age);
    
        UserTemplate setRole(String role);
    
        ...
      }
    
      UserTemplate template = new Handlebars().compileInline("{{name}} is {{age}} years old!")
        .as(UserTemplate.class);
    
      template.setAge(32);
    
      assertEquals("Edgar is 32 years old!", template.apply(new User("Edgar")));
     
    Since:
    0.10.0
    See Also:
    Template.as(Class), Template.as()
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.String apply​(T context)
      Merge the template tree using the given context.
      void apply​(T context, java.io.Writer writer)
      Merge the template tree using the given context.
    • Method Detail

      • apply

        void apply​(T 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​(T 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.