Class ComponentRegistry
java.lang.Object
dev.jcputney.mjml.component.ComponentRegistry
Registry mapping MJML tag names to component factories. Supports registration of custom
components.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateComponent(MjmlNode node, GlobalContext globalContext, RenderContext renderContext) Creates a component instance for the given node.voidfreeze()Freezes this registry, preventing further registrations.booleanhasFactory(String tagName) Returns whether a factory is registered for the given tag name.voidregister(String tagName, ComponentFactory factory) Registers a component factory for the given tag name.
-
Constructor Details
-
ComponentRegistry
public ComponentRegistry()Creates a new, empty component registry.
-
-
Method Details
-
register
Registers a component factory for the given tag name.- Parameters:
tagName- the MJML tag name to register (e.g. "mj-section")factory- the factory used to create component instances for the tag- Throws:
IllegalStateException- if the registry has been frozen
-
freeze
public void freeze()Freezes this registry, preventing further registrations. -
hasFactory
Returns whether a factory is registered for the given tag name.- Parameters:
tagName- the MJML tag name to check- Returns:
trueif a factory is registered for the tag
-
createComponent
public BaseComponent createComponent(MjmlNode node, GlobalContext globalContext, RenderContext renderContext) Creates a component instance for the given node. Returns null if no factory is registered for the tag.- Parameters:
node- the parsed MJML node to create a component forglobalContext- the document-wide context gathered during head processingrenderContext- the current rendering context (container width, position, etc.)- Returns:
- the created component instance, or
nullif no factory is registered
-