ee.mare.indrek.jtlt
Interface TemplateMacro

All Known Implementing Classes:
KeyMacro, MacroAdapter

public interface TemplateMacro

Macros can be used to extend the template files syntax. Macros must be registered at the TemplateContext you are using. Whenever a macro with given name is found the process method is called. Macros also allow you to use parameters that are set at individual template classes.

See Also:
TemplateContext.registerMacro(ee.mare.indrek.jtlt.TemplateMacro)

Method Summary
 String getName()
          Get the name of the macro.
 boolean isParsetime()
          Returns whether a macro is parsetime or not.
 boolean isRecursive()
          Whether to recursively parse the output of this the macro.
 String process(TemplateParams ctx, String name, String args)
          This method is called with given block context whenever a macro with registered name is found inside the tempalate.
 

Method Detail

getName

public String getName()
Get the name of the macro. Macro is called whenever a name is used inside the template.


isParsetime

public boolean isParsetime()
Returns whether a macro is parsetime or not. Being parsetime means here that the macro does not depend on template instance specified parameters and can be resolved at parsing time. But resolving macros only at parsetime is faster than doing it on every created template. Not all instances of macro usage may be parsed at parsetime tho. For example when the result of recursive macro contains it.


isRecursive

public boolean isRecursive()
Whether to recursively parse the output of this the macro. If the macro is used at parsetime the result can contain additional sub blocks.


process

public String process(TemplateParams ctx,
                      String name,
                      String args)
This method is called with given block context whenever a macro with registered name is found inside the tempalate. The macros are resolved immediately only if they are parsetime, otherwise on every Template.toString the data structures are parsed and macros expanded. If macro is parsetime the ctx is taken from the generator. You can add parameters into the template using the Template.addParam, for parsetime macros you'd have to extend the TemplateGenerator.

Returns:
the string value to be replaced into the template
See Also:
TemplateParams.findParam(java.lang.String, boolean), Template.addParam(java.lang.String, java.lang.Object)