Class ThemeDirectiveModel

java.lang.Object
org.apache.juneau.console.freemarker.ThemeDirectiveModel
All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel, freemarker.template.TemplateModel

public final class ThemeDirectiveModel extends Object implements freemarker.template.TemplateDirectiveModel
The <@theme name="…"> chrome FreeMarker directive: names the active stock theme once, in the chrome, points the chrome at that theme's shipped stylesheet, and — when a nested <@token> body is present — builds a Theme of custom overrides on top of it.

Its only attribute is name (optional), one of ConsoleChromeMixin.BUILTIN_THEME_NAMES (open, light-red, light-brown, red, gray — the kebab-case of the Theme constants). format=, an unknown attribute, an empty name="", and an unknown theme name are all rejected (fail closed). There is deliberately no default=: if the tag is present, that is the theme.

Nameless form:

Without name=, the directive inherits the page theme as its seed: <@console theme="…"> if given, else the PageSpec.theme(String) value, else open. It never conflicts with a page-spec theme, so <@theme><@token …/></@theme> customises whatever theme the page already selected.

Custom tokens:

The named stock palette is the seed: this directive opens a ThemeBuildContext holding a Theme.Builder copied from the named stock palette, renders the nested body so each <@token> folds its leaf or alias into that builder, then builds the theme. When the body declared at least one token, the theme's override block (ConsoleChromeMixin.overrideBlock(Theme): leaves escaped, aliases verbatim) is emitted inline after the stock-theme <link>. A body-less <@theme> is just the stock theme. A build() failure (unknown var() target, cycle, a name on both channels) is a template error carrying Theme.Builder's sentence.

A <@token scheme="dark"> adds to a separate dark rule, emitted after the light block in the same inline <style>; see TokenDirectiveModel. A body with only dark tokens emits no light block. A dark alias whose target is not a light-theme token or alias, a Theme.OPEN token, a chrome role alias or another dark declaration is rejected.

Example:

<#-- Stock palette only: links juneau-theme-light-brown.css, no inline block. --> <@theme name="light-brown"/> <#-- Stock palette plus one leaf override: link, then <style>html:root{...}</style>. --> <@theme name="light-brown"><@token name="--jc-accent-selected" value="#8a5a1a"/></@theme>

How the link lands:

<@theme> must be nested inside <@console>; it records the resolved stock-theme URL (via ConsoleChromeMixin.themeAssetUrl(org.apache.juneau.rest.server.RestRequest, String)) and the optional override block on the PageCapture, and <@console> emits both in its head cascade. A <@theme> authored outside <@console> is rejected fail-closed (E-18).

Since:
10.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The shared-variable name this directive registers under.

    Fields inherited from interface freemarker.template.TemplateModel

    NOTHING
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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:
      execute in interface freemarker.template.TemplateDirectiveModel
      Throws:
      freemarker.template.TemplateException
      IOException