Class RenderContext
java.lang.Object
dev.jcputney.mjml.context.RenderContext
Per-component render context that carries the current container width as the rendering pipeline
descends the component tree. Width narrows: body(600) -> section -> column -> content component.
-
Constructor Summary
ConstructorsConstructorDescriptionRenderContext(double containerWidth) Creates a new root render context with the given container width. -
Method Summary
Modifier and TypeMethodDescriptionReturns the column width specification as computed by the parent section.doubleReturns the current container width in pixels.intgetIndex()Returns the zero-based index of this component among its siblings.booleanisFirst()Returns whether this component is the first among its siblings.booleanReturns whether this component is nested inside anmj-group.booleanReturns whether this component is nested inside anmj-wrapper.booleanisLast()Returns whether this component is the last among its siblings.nextUniqueId(String prefix) Returns a deterministic unique ID with the given prefix.withColumnWidth(double width, String columnWidthSpec) Creates a child context with container width and column width specification.withInsideGroup(boolean insideGroup) Creates a child context indicating the component is inside a group.withInsideWrapper(boolean insideWrapper) Creates a child context indicating the component is inside a wrapper.withPosition(int index, boolean first, boolean last) Creates a child context with positioning info for column rendering.withWidth(double width) Creates a child context with a narrower container width.
-
Constructor Details
-
RenderContext
public RenderContext(double containerWidth) Creates a new root render context with the given container width. The context starts with default values: index 0, first and last both true, not inside a wrapper or group, and a fresh ID counter.- Parameters:
containerWidth- the initial container width in pixels (e.g. 600)
-
-
Method Details
-
getContainerWidth
public double getContainerWidth()Returns the current container width in pixels.- Returns:
- the container width in pixels
-
getColumnWidthSpec
Returns the column width specification as computed by the parent section. For percentage widths: "33.33" (just the number) For pixel widths: "150px" (with px suffix) For auto columns: "100" or "33.333333333333336" (full precision)- Returns:
- the column width specification string, or
nullif not set
-
getIndex
public int getIndex()Returns the zero-based index of this component among its siblings.- Returns:
- the sibling index
-
isFirst
public boolean isFirst()Returns whether this component is the first among its siblings.- Returns:
trueif this is the first sibling
-
isLast
public boolean isLast()Returns whether this component is the last among its siblings.- Returns:
trueif this is the last sibling
-
isInsideWrapper
public boolean isInsideWrapper()Returns whether this component is nested inside anmj-wrapper.- Returns:
trueif inside a wrapper
-
isInsideGroup
public boolean isInsideGroup()Returns whether this component is nested inside anmj-group.- Returns:
trueif inside a group
-
nextUniqueId
-
withWidth
Creates a child context with a narrower container width.- Parameters:
width- the new container width in pixels- Returns:
- a new render context with the updated width
-
withColumnWidth
Creates a child context with container width and column width specification.- Parameters:
width- the new container width in pixelscolumnWidthSpec- the column width specification string (e.g. "33.33" or "150px")- Returns:
- a new render context with the updated width and column width spec
-
withPosition
Creates a child context with positioning info for column rendering.- Parameters:
index- the zero-based index of the column among its siblingsfirst- whether this is the first siblinglast- whether this is the last sibling- Returns:
- a new render context with the updated position info
-
withInsideWrapper
Creates a child context indicating the component is inside a wrapper.- Parameters:
insideWrapper- whether the component is inside anmj-wrapper- Returns:
- a new render context with the updated wrapper flag
-
withInsideGroup
Creates a child context indicating the component is inside a group.- Parameters:
insideGroup- whether the component is inside anmj-group- Returns:
- a new render context with the updated group flag
-