JtlFactory class final
A concrete, fully configurable factory for the JetLeaf template engine, implementing ConfigurableJtl and providing a complete, ready-to-use template engine instance.
JtlFactory acts as the central hub of the JetLeaf framework, managing all core components required for template rendering. It is designed to be both immediately usable with defaults and highly configurable for advanced use cases. Developers can replace any of the core components at runtime or via constructor injection, allowing full control over rendering behavior, caching strategies, variable resolution, expression evaluation, template asset management, and filter application.
This class is intended for scenarios including:
- Production usage where default implementations are sufficient.
- Testing or sandboxing, where components need to be replaced with mocks or stubs.
- Custom template pipelines, where advanced rendering logic or preprocessing is required.
- Dynamic configuration, such as runtime switching of caches, renderers, or variable resolvers based on environment or user context.
Features
- Provides default implementations for all core components:
- InMemoryTemplateCache for caching rendered templates
DefaultAssetPathResourcefor template loading- TemplateFilterRegistry for variable filters
- DefaultExpressionEvaluator for evaluating template expressions
- DefaultVariableResolver for resolving template variables
- DefaultTemplateRenderer for parsing and rendering templates
- Supports hot-swapping of components via setter methods
- Lazy initialization of components like the renderer for efficient resource usage
- Ensures consistent rendering behavior across templates by centralizing context, filters, and evaluators
Design Notes
- All core fields are private and accessed through the ConfigurableJtl interface methods to enforce encapsulation.
- Replacing components at runtime affects all subsequent template renders.
- The factory is compatible with all JetLeaf templates, contexts, and rendering extensions.
- Provides a single, unified entry point for configuring and rendering templates in a maintainable and testable way.
- Implemented types
Constructors
- JtlFactory({TemplateCache? templateCache, AssetBuilder? assetBuilder, TemplateFilterRegistry? filterRegistry, TemplateExpressionEvaluator? expressionEvaluator, TemplateVariableResolver? variableResolver, TemplateRenderer? renderer})
- A concrete, fully configurable factory for the JetLeaf template engine, implementing ConfigurableJtl and providing a complete, ready-to-use template engine instance.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getAssetBuilder(
) → AssetBuilder -
Returns the
AssetBuilderused to locate or load template content.override -
getCache(
) → TemplateCache -
Returns the TemplateCache used for storing and retrieving rendered templates.
override
-
getExpressionEvaluator(
) → TemplateExpressionEvaluator -
Returns the TemplateExpressionEvaluator for evaluating expressions
within templates.
override
-
getFilterRegistry(
) → TemplateFilterRegistry -
Returns the TemplateFilterRegistry used to manage filters for template variables.
override
-
getRenderer(
) → TemplateRenderer -
Returns the TemplateRenderer responsible for rendering templates.
override
-
getVariableResolver(
) → TemplateVariableResolver -
Returns the TemplateVariableResolver for resolving template variables
to their runtime string representations.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
render(
Template template, [Asset? built]) → SourceCode -
Renders the given
templateinto a SourceCode object.override -
setAssetBuilder(
AssetBuilder assetBuilder) → void -
Replaces the
AssetBuilderused to locate or load template content.override -
setExpressionEvaluator(
TemplateExpressionEvaluator expressionEvaluator) → void -
Replaces the TemplateExpressionEvaluator used by the template engine.
override
-
setFilterRegistry(
TemplateFilterRegistry filterRegistry) → void -
Replaces the TemplateFilterRegistry used for variable filters in templates.
override
-
setTemplateCache(
TemplateCache templateCache) → void -
Replaces the TemplateCache used for storing and retrieving rendered templates.
override
-
setTemplateRenderer(
TemplateRenderer templateRenderer) → void -
Replaces the TemplateRenderer used to render templates into SourceCode.
override
-
setVariableResolver(
TemplateVariableResolver variableResolver) → void -
Replaces the TemplateVariableResolver used by the template engine.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited