Class ConsoleFreemarkerMixin.Builder
- All Implemented Interfaces:
ViewMixinBuilder<FreemarkerMixin.Builder>
- Enclosing class:
- ConsoleFreemarkerMixin
ConsoleFreemarkerMixin.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder()Constructor — package access forConsoleFreemarkerMixin.create(). -
Method Summary
Modifier and TypeMethodDescriptionadopterAssets(ClassLoader loader, String resourceRoot) Enables theassetUrl(path)template function that versions the adopter's own static assets.Sets the classpath base path under which template resources are resolved.build()Builds theConsoleFreemarkerMixin.cardRequires(String type, String... packs) Adds packs every card of a type requires, after the built-in one (datatables→"datatables-glue").cardType(CardTypeHandler handler) Registers a server-side card type handler for this mixin's<@card>directive, on top ofCardTypeRegistry.standard().chromeTemplate(String chromeTemplate) Sets the consumer chrome template that<@page>includes after capturing its body.devMode(boolean value) Validates every page contract againstjuneau-page.schema.jsonwhen<@console>closes, and fails the render with E-14 on any finding.providedPacks(String... names) Names packs the app's chrome already loads.Registers an app-suppliedToolkitPack.Kind.RUNTIMEtoolkit pack with no dependencies.Registers an app-supplied toolkit pack.requirePacks(String... names) Opts in to the startup WebJar check: the named packs (for example"charts") are expanded throughdependsOnand every WebJar they reach is probed when the mixin is built, so a missingorg.webjars.npm:echartsfails at startup (E-70) instead of on the first chart page.Methods inherited from class org.apache.juneau.rest.server.view.freemarker.FreemarkerMixin.Builder
cacheTemplates, exposeFields, getBasePath, getObjectWrapper, getTemplateSuffix, isCacheTemplates, isExposeFields, objectWrapper, templateSuffix
-
Constructor Details
-
Builder
protected Builder()Constructor — package access forConsoleFreemarkerMixin.create().
-
-
Method Details
-
basePath
Sets the classpath base path under which template resources are resolved.Defaults to
"/". A typical configured value is"/templates/"— the same Spring-Boot-compatible layout convention the sibling JSP / Thymeleaf / Mustache bridges use.Covariantly narrowed to this
Builderso a fluent chain can mix inherited setters (e.g.basePath(String)) with the console-specificchromeTemplate(String)/registerToolkitPack(ToolkitPack)in any order.- Specified by:
basePathin interfaceViewMixinBuilder<FreemarkerMixin.Builder>- Overrides:
basePathin classFreemarkerMixin.Builder- Parameters:
value- The base path.nullor blank values reset to the defaultFreemarkerMixin.DEFAULT_BASE_PATH.- Returns:
- This object.
-
chromeTemplate
Sets the consumer chrome template that<@page>includes after capturing its body.Resolved on the consumer's own
basePath-rooted loader. Defaults toConsoleFreemarkerMixin.DEFAULT_CHROME_TEMPLATE.- Parameters:
chromeTemplate- The chrome template name. Must not benull.- Returns:
- This object.
-
registerToolkitPack
public ConsoleFreemarkerMixin.Builder registerToolkitPack(String name, List<String> cssPaths, List<String> jsPaths) Registers an app-suppliedToolkitPack.Kind.RUNTIMEtoolkit pack with no dependencies.Same as
registerToolkitPack(ToolkitPack)withkind(RUNTIME)and the default resolver.- Parameters:
name- The pack name.cssPaths- Ordered CSS asset paths.jsPaths- Ordered JS asset paths.- Returns:
- This object.
-
registerToolkitPack
Registers an app-supplied toolkit pack.A pack with the name of a built-in or earlier pack replaces it completely, including its
dependsOn.build()validates the pack graph.- Parameters:
pack- The pack.- Returns:
- This object.
-
providedPacks
Names packs the app's chrome already loads. A provided pack contributes no URLs; its dependencies still load unless they are provided too.- Parameters:
names- Registered pack names.- Returns:
- This object.
-
requirePacks
Opts in to the startup WebJar check: the named packs (for example"charts") are expanded throughdependsOnand every WebJar they reach is probed when the mixin is built, so a missingorg.webjars.npm:echartsfails at startup (E-70) instead of on the first chart page. An app pack registered withregisterToolkitPack(ToolkitPack)that depends on"echarts"opts in too.- Parameters:
names- Registered pack names.- Returns:
- This object.
-
cardRequires
Adds packs every card of a type requires, after the built-in one (datatables→"datatables-glue").- Parameters:
type- The card type.packs- Registered pack names.- Returns:
- This object.
-
cardType
Registers a server-side card type handler for this mixin's<@card>directive, on top ofCardTypeRegistry.standard().Most custom cards need only a JS handler; register a
CardTypeHandlerhere when the server must validate or enrich the body. To also load toolkit packs for the type, usecardRequires(String, String...).- Parameters:
handler- The handler. Must not benull .- Returns:
- This object.
- Throws:
IllegalArgumentException- E-21 bad type name; E-22 reserved type; E-20 already registered.
-
devMode
Validates every page contract againstjuneau-page.schema.jsonwhen<@console>closes, and fails the render with E-14 on any finding.Defaults to the
juneau.console.devModesystem property. Intended for development and tests; it parses and validates the contract on every render.Example:
@Bean public FreemarkerMixin freemarker() {return ConsoleFreemarkerMixin.create ().devMode(true ).basePath("/templates/" ).build(); }- Parameters:
value- Whether to validate.- Returns:
- This object.
-
adopterAssets
Enables theassetUrl(path)template function that versions the adopter's own static assets.assetUrl('/js/app.js')returns/js/app.js?v=<crc32 of the bundled bytes>, where the bytes are read once (and the token cached) fromresourceRoot + pathonloader. This is the adopter-side counterpart of Juneau's ownviewAssetUrl/consoleJsUrl/chromeCssUrl/themeAssetUrlcache-busters, for files the servlet container's static handler serves. A path with a query string, a non-root-absolute path (e.g. an external URL), or a path naming no bundled resource is returned unchanged (the last also logs a warning indev mode). The URL path itself is never rewritten, so any context-path prefix must be added by the template.Example:
@Bean public FreemarkerMixin freemarker() {return ConsoleFreemarkerMixin.create () .basePath("/templates/" ) .adopterAssets(getClass().getClassLoader(),"static" )// /js/app.js -> classpath static/js/app.js .build(); }<script src="${assetUrl('/js/app.js')}"></script>
- Parameters:
loader- The class loader that holds the assets. Must not benull.resourceRoot- The classpath directory the URL paths are relative to (e.g."static"); a leading and trailing slash are optional. Must not benull.- Returns:
- This object.
-
build
Builds theConsoleFreemarkerMixin.Overrides
FreemarkerMixin.Builder#build()— without this override, the inherited method would silently return a plainFreemarkerMixin, not aConsoleFreemarkerMixin.- Overrides:
buildin classFreemarkerMixin.Builder- Returns:
- A new
ConsoleFreemarkerMixininstance.
-