Class TokenDirectiveModel
- All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel,freemarker.template.TemplateModel
<@token name="--jc-…" value="…"/> / <@token name="--jc-…" alias="var(--jc-…)"/> chrome
FreeMarker directive: one custom theme-token override authored inside a <@theme> element.
Exactly one of value= / alias= is required, and they are mutually exclusive — they are the
two disjoint Theme channels:
value=is a leaf: a CSS literal, or avar(--jc-name)reference thatTheme.Builder#token(String, String)resolves to a literal at build time (the substringvar(does not reach the served leaf map).alias=is a derived reference: avar(--jc-name)thatTheme.Builder#alias(String, String)keeps as a reference surviving to the wire. A literal cannot express a live alias — that is why the attr exists.
The name/value/target guards and reserved-namespace rejection are the Java Theme.Builder's own (fail
closed); an IllegalArgumentException it raises is re-surfaced through FtlAttrLists.reject(String)
so its exact sentence reaches the HTTP 500 body. The directive writes no markup — it folds the declaration
into the enclosing ThemeBuildContext, which <@theme> builds after its body pass.
scheme="dark" declares the token for the dark colour scheme only. Dark declarations render in their own
html:root[data-jc-scheme="dark"] rule after the light override block, holding only the declared names. A
dark value= must be a literal (a var() leaf would resolve against the light palette); a dark
alias= stays a live reference. dark is the only accepted value: a light token omits
scheme=.
Example:
<@theme name="light-red"> <#-- A leaf: a literal. --> <@token name="--jc-pill-red-bg" value="#fdeceb"/> <#-- An alias: a live reference. --> <@token name="--jc-tab-bar-bg" alias="var(--jc-card-bg)"/> <#-- Dark scheme only. --> <@token name="--jc-link" value="#6cb4ff" scheme="dark"/> </@theme> <#-- Rejected: both value= and alias=, neither one, or a reserved --jc-chrome-* name. --> <@token name="--jc-x" value="#fff" alias="var(--jc-accent)"/> <@token name="--jc-x"/> <@token name="--jc-chrome-control-height" value="26px"/>
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe shared-variable name this directive registers under.Fields inherited from interface freemarker.template.TemplateModel
NOTHING -
Method Summary
-
Field Details
-
NAME
The shared-variable name this directive registers under.- See Also:
-
-
Method Details
-
execute
public void execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException, IOException - Specified by:
executein interfacefreemarker.template.TemplateDirectiveModel- Throws:
freemarker.template.TemplateExceptionIOException
-