Class ThemeBuilder
- All Implemented Interfaces:
Runnable
A view theme is a collection of assets that provides the base css and js for one or more views (see
org.kuali.rice.krad.uif.view.ViewTheme. The theme builder provides utilities for creating and
configuring themes that follow a standard directory convention.
By default, the theme builder processes any directories under '/themes' as theme directories. Other
theme directories can be added through the property getAdditionalThemeDirectories()
The basic functions provided by the theme builder are:
- Overlay assets from a parent theme directory (if a parent is configured). Only assets that exist in the parent directory but not in the child will be overlaid
- Applies one or more configured
ThemePreProcessorinstances to the theme files. For example, Less files are compiled to CSS files here by theLessThemePreProcessor - Collects JS and CSS resources for the theme. This includes bringing in plugin resources and base KRAD script. Resources can be filtered and ordered as needed
- Perform merging and minification for each file type. During this the file types can perform additional processing (for example, URL rewriting is done for CSS files)
To just perform the first step (overlay parent assets), the property isSkipThemeProcessing() can be set to
true. This is useful in development where an update to a parent file just needs pushed to the output directory.
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuildMappings(List<File> themeDirectories, List<File> pluginDirectories) Builds convenience maps (theme name to path map, theme name to properties mapping, and plugin name to path mapping) for the given theme and plugin directories.collectThemePluginDirs(Properties themeProperties) Helper method that filters the list of all plugins and returns those that should be used with the themeprotected voidcopyParentThemeConfig(String themeName) If the given theme has a parent, retrieve the theme properties (if exists) for the parent, then for each config property copy the parent value to the child theme properties if missingList of absolute paths to include as additional plugin directoriesList of absolute paths to include as additional theme directoriesgetAllThemeParents(String themeName, List<String> themeParents) Gets all parents (ancestors) for the given theme name.Retrieves the directories that should be processed as plugins.Version for the project that will be used to stamp the minified fileAbsolute path to the directory the theme builder should output content toRetrieves the directories that should be processed as themes.List of theme names that should be excluded from theme processingMap that associates theme names with their path, provided here for subclassesprotected Map<String,Properties> Map that associates theme names with their properties, provided here for subclassesList ofThemePreProcessorinstances that should be applied to the themesAbsolute path to the directory that contains the web application sourcebooleanIndicates whether processing of the themes should be skippedBuilds a list containing theme names in the order for which they should be processed.protected voidprocessThemeAssets(String themeName) Performs the various steps to process the given themevoidrun()Invoked from the spring context to execute the theme builder.voidsetAdditionalPluginDirectories(List<String> additionalPluginDirectories) Setter for the list of additional plugin directory pathsvoidsetAdditionalPluginDirectoriesStr(String additionalPluginDirectories) Convenience setter that takes a string and parses to populate the additional plugin directories listvoidsetAdditionalThemeDirectories(List<String> additionalThemeDirectories) Setter for the list of additional theme directory pathsvoidsetAdditionalThemeDirectoriesStr(String additionalThemeDirectories) Convenience setter that takes a string and parses to populate the additional theme directories listvoidsetProjectVersion(String projectVersion) Setter for the project versionvoidsetSkipThemeProcessing(boolean skipThemeProcessing) Setter to skip theme processingvoidsetThemeBuilderOutputDir(String themeBuilderOutputDir) Setter for the path to the output directoryvoidsetThemeExcludes(List<String> themeExcludes) Setter for the list of theme names to exclude from processingvoidsetThemeExcludesStr(String themeExcludes) Convenience setter that takes a string and parses to populate the theme excludes listvoidsetThemePreProcessors(List<ThemePreProcessor> themePreProcessors) Setter for the list of theme pre processorsvoidsetWebappSourceDir(String webappSourceDir) Setter for the path to the webapp source
-
Constructor Details
-
ThemeBuilder
public ThemeBuilder()
-
-
Method Details
-
run
public void run()Invoked from the spring context to execute the theme builder.Invokes processing of the main theme builder functions, this includes:
- Copying assets from web source directory to the output directory
- Retrieving all theme and plugin directories, then setting up convenience maps for acquiring paths
- Iterating through each theme that should be built (those not excluded with
getThemeExcludes()) - For each theme, invoking parent and additional directory overlays, then finally calling a helper method to process the theme assets
To just perform copying of the web assets, and parent/additional directory overlays, set the property
isSkipThemeProcessing()to true -
getThemeDirectories
Retrieves the directories that should be processed as themes.By default all directories in '/themes' are included as theme directories. Additional directories can be included by setting
getAdditionalThemeDirectories()- Returns:
- list of file objects pointing to the theme directories
-
getPluginDirectories
Retrieves the directories that should be processed as plugins.By default all directories in '/plugins' are included as plugins. Additional directories can be included by setting
getAdditionalPluginDirectories()- Returns:
- list of file objects pointing to the plugin directories
-
buildMappings
protected void buildMappings(List<File> themeDirectories, List<File> pluginDirectories) throws IOException Builds convenience maps (theme name to path map, theme name to properties mapping, and plugin name to path mapping) for the given theme and plugin directories.- Parameters:
themeDirectories- list of theme directories to build mappings forpluginDirectories- list of file directories to build mappings for- Throws:
IOException
-
orderThemesForBuilding
Builds a list containing theme names in the order for which they should be processed.For the parent overlays to work correctly, the parent must be processed before the child. There can be multiple parents in the hierarchy, so here we go through and figure out the correct order
- Returns:
- list of ordered theme names
-
getAllThemeParents
Gets all parents (ancestors) for the given theme name.The parent for a theme is determined by retrieving the theme's properties file, then pulling the property with key 'parent'. Then the properties file for the parent theme is pulled and check to see if it has a parent. So on until a theme is reached that does not have a parent
- Parameters:
themeName- name of theme to retrieve parents forthemeParents- list of parents that have been previously found (used to find circular references)- Returns:
- list of theme names that are parents to the given theme
-
copyParentThemeConfig
If the given theme has a parent, retrieve the theme properties (if exists) for the parent, then for each config property copy the parent value to the child theme properties if missing- Parameters:
themeName- name of the theme to pull parent config for and copy
-
processThemeAssets
Performs the various steps to process the given themeThe theme is processed first by applying any configured
ThemePreProcessorinstances (such as less processing). Once the pre processors are applied, the CSS and JS post processors are then invoked to do the final processing After processing is complete the 'theme-derived.properties' file gets written to the theme directory, which contains all the properties for the theme (set, inherited, derived)- Parameters:
themeName- name of the theme to process
-
collectThemePluginDirs
Helper method that filters the list of all plugins and returns those that should be used with the themeWhich plugins to include for a theme can be configured using the pluginIncludes and pluginExlcudes property keys
- Parameters:
themeProperties- properties file for the theme, used to retrieve the plugin configuration- Returns:
- map containing the plugins for the theme, map key is the plugin name and map value gives the plugin directory
-
getThemeNamePathMapping
Map that associates theme names with their path, provided here for subclasses- Returns:
- map of theme name/paths, map key is the theme name, map value is the theme path
-
getThemeNamePropertiesMapping
Map that associates theme names with their properties, provided here for subclasses- Returns:
- map of theme name/properties, map key is the theme name, map value is the properties object
-
getWebappSourceDir
Absolute path to the directory that contains the web application sourceGenerally this is the base directory for the application/module, then /src/main/webapp
If you are using the maven plugin this can be set by the maven property
webapp.source.dir- Returns:
- path to webapp source directory
-
setWebappSourceDir
Setter for the path to the webapp source- Parameters:
webappSourceDir-
-
getThemeBuilderOutputDir
Absolute path to the directory the theme builder should output content toGenerally this will be the output directory for the exploded war being created. However you can also choose to output to a temporary directory, then copy the assets over at a later phase
If you are using the maven plugin this can be set by the maven property
theme.builder.output.dir- Returns:
- path to the output directory
-
setThemeBuilderOutputDir
Setter for the path to the output directory- Parameters:
themeBuilderOutputDir-
-
getThemeExcludes
List of theme names that should be excluded from theme processingDirectories for themes that are excluded will be copied to the output directory but no further processing will occur on that theme.
If your web application receives web overlays which include themes, they will already be processed. Processing them again will result in duplicate content. Therefore you should exclude these themes using this property
If you are using the maven plugin this can be set by the maven property
theme.builder.excludes- Returns:
- list of excluded theme names
-
setThemeExcludes
Setter for the list of theme names to exclude from processing- Parameters:
themeExcludes-
-
setThemeExcludesStr
Convenience setter that takes a string and parses to populate the theme excludes list- Parameters:
themeExcludes- string containing theme names to exclude which are delimited using a comma
-
getAdditionalThemeDirectories
List of absolute paths to include as additional theme directoriesBy default all directories under the web root folder
themesare included. Other web directories can be processed as themes by including their path in this listIf you are using the maven plugin this can be set by the maven property
theme.builder.theme.adddirs- Returns:
- list of paths for additional themes
-
setAdditionalThemeDirectories
Setter for the list of additional theme directory paths- Parameters:
additionalThemeDirectories-
-
setAdditionalThemeDirectoriesStr
Convenience setter that takes a string and parses to populate the additional theme directories list- Parameters:
additionalThemeDirectories- string containing additional theme directories which are delimited using a comma
-
getAdditionalPluginDirectories
List of absolute paths to include as additional plugin directoriesBy default all directories under the web root folder
pluginsare included. Other web directories can be processed as plugins by including their path in this listIf you are using the maven plugin this can be set by the maven property
theme.builder.plugin.adddirs- Returns:
- list of paths for additional plugins
-
setAdditionalPluginDirectories
Setter for the list of additional plugin directory paths- Parameters:
additionalPluginDirectories-
-
setAdditionalPluginDirectoriesStr
Convenience setter that takes a string and parses to populate the additional plugin directories list- Parameters:
additionalPluginDirectories- string containing additional plugin directories which are delimited using a comma
-
getProjectVersion
Version for the project that will be used to stamp the minified fileIn order to facilitate automatic downloads between project releases, the minified files are stamped with the version number.
If you are using the maven plugin this can be set by the maven property
project.version- Returns:
- version string for project
-
setProjectVersion
Setter for the project version- Parameters:
projectVersion-
-
getThemePreProcessors
List ofThemePreProcessorinstances that should be applied to the themes- Returns:
- list of pre processors to apply
-
setThemePreProcessors
Setter for the list of theme pre processors- Parameters:
themePreProcessors-
-
isSkipThemeProcessing
public boolean isSkipThemeProcessing()Indicates whether processing of the themes should be skippedIn development it can be useful to just update the output directory with the theme assets, and skip processing such as Less and minification (which can be time consuming). Setting this flag to true will skip processing of pre and post processors, just doing the overlay. By default this is false
- Returns:
- true if theme processing should be skipped, false if not
-
setSkipThemeProcessing
public void setSkipThemeProcessing(boolean skipThemeProcessing) Setter to skip theme processing- Parameters:
skipThemeProcessing-
-