public class ThemeBuilder extends Object implements org.kuali.common.util.execute.Executable
A view theme is a collection of assets that provides the base css and js for one or more views (see
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:
ThemePreProcessor
instances to the theme files. For example, Less
files are compiled to CSS files here by the LessThemePreProcessor
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.ThemeBuilderOverlays
,
ThemePreProcessor
,
ThemeFilesProcessor
Constructor and Description |
---|
ThemeBuilder() |
Modifier and Type | Method and Description |
---|---|
protected void |
buildMappings(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.
|
protected Map<String,File> |
collectThemePluginDirs(Properties themeProperties)
Helper method that filters the list of all plugins and returns those that should be used
with the theme
|
protected void |
copyParentThemeConfig(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 missing
|
void |
execute()
Invoked from the spring context to execute the theme builder.
|
List<String> |
getAdditionalPluginDirectories()
List of absolute paths to include as additional plugin directories
|
List<String> |
getAdditionalThemeDirectories()
List of absolute paths to include as additional theme directories
|
protected List<String> |
getAllThemeParents(String themeName,
List<String> themeParents)
Gets all parents (ancestors) for the given theme name.
|
protected List<File> |
getPluginDirectories()
Retrieves the directories that should be processed as plugins.
|
String |
getProjectVersion()
Version for the project that will be used to stamp the minified file
|
String |
getThemeBuilderOutputDir()
Absolute path to the directory the theme builder should output content to
|
protected List<File> |
getThemeDirectories()
Retrieves the directories that should be processed as themes.
|
List<String> |
getThemeExcludes()
List of theme names that should be excluded from theme processing
|
protected Map<String,String> |
getThemeNamePathMapping()
Map that associates theme names with their path, provided here for subclasses
|
protected Map<String,Properties> |
getThemeNamePropertiesMapping()
Map that associates theme names with their properties, provided here for subclasses
|
List<ThemePreProcessor> |
getThemePreProcessors()
List of
ThemePreProcessor instances that should be applied to the themes |
String |
getWebappSourceDir()
Absolute path to the directory that contains the web application source
|
boolean |
isSkipThemeProcessing()
Indicates whether processing of the themes should be skipped
|
protected List<String> |
orderThemesForBuilding()
Builds a list containing theme names in the order for which they should be processed.
|
protected void |
processThemeAssets(String themeName)
Performs the various steps to process the given theme
|
void |
setAdditionalPluginDirectories(List<String> additionalPluginDirectories)
Setter for the list of additional plugin directory paths
|
void |
setAdditionalPluginDirectoriesStr(String additionalPluginDirectories)
Convenience setter that takes a string and parses to populate the additional plugin directories list
|
void |
setAdditionalThemeDirectories(List<String> additionalThemeDirectories)
Setter for the list of additional theme directory paths
|
void |
setAdditionalThemeDirectoriesStr(String additionalThemeDirectories)
Convenience setter that takes a string and parses to populate the additional theme directories list
|
void |
setProjectVersion(String projectVersion)
Setter for the project version
|
void |
setSkipThemeProcessing(boolean skipThemeProcessing)
Setter to skip theme processing
|
void |
setThemeBuilderOutputDir(String themeBuilderOutputDir)
Setter for the path to the output directory
|
void |
setThemeExcludes(List<String> themeExcludes)
Setter for the list of theme names to exclude from processing
|
void |
setThemeExcludesStr(String themeExcludes)
Convenience setter that takes a string and parses to populate the theme excludes list
|
void |
setThemePreProcessors(List<ThemePreProcessor> themePreProcessors)
Setter for the list of theme pre processors
|
void |
setWebappSourceDir(String webappSourceDir)
Setter for the path to the webapp source
|
public ThemeBuilder()
public void execute()
Invokes processing of the main theme builder functions, this includes:
getThemeExcludes()
)
To just perform copying of the web assets, and parent/additional directory overlays, set the property
isSkipThemeProcessing()
to true
execute
in interface org.kuali.common.util.execute.Executable
protected List<File> getThemeDirectories()
By default all directories in '/themes' are included as theme directories. Additional directories can
be included by setting getAdditionalThemeDirectories()
protected List<File> getPluginDirectories()
By default all directories in '/plugins' are included as plugins. Additional directories can
be included by setting getAdditionalPluginDirectories()
protected void buildMappings(List<File> themeDirectories, List<File> pluginDirectories) throws IOException
themeDirectories
- list of theme directories to build mappings forpluginDirectories
- list of file directories to build mappings forIOException
protected List<String> orderThemesForBuilding()
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
protected List<String> getAllThemeParents(String themeName, List<String> themeParents)
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
themeName
- name of theme to retrieve parents forthemeParents
- list of parents that have been previously found (used to find circular references)protected void copyParentThemeConfig(String themeName)
themeName
- name of the theme to pull parent config for and copyprotected void processThemeAssets(String themeName)
The theme is processed first by applying any configured ThemePreProcessor
instances (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)
themeName
- name of the theme to processprotected Map<String,File> collectThemePluginDirs(Properties themeProperties)
Which plugins to include for a theme can be configured using the pluginIncludes and pluginExlcudes property keys
themeProperties
- properties file for the theme, used to retrieve the plugin configurationprotected Map<String,String> getThemeNamePathMapping()
protected Map<String,Properties> getThemeNamePropertiesMapping()
public String getWebappSourceDir()
Generally 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
public void setWebappSourceDir(String webappSourceDir)
webappSourceDir
- public String getThemeBuilderOutputDir()
Generally 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
public void setThemeBuilderOutputDir(String themeBuilderOutputDir)
themeBuilderOutputDir
- public List<String> getThemeExcludes()
Directories 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
public void setThemeExcludes(List<String> themeExcludes)
themeExcludes
- public void setThemeExcludesStr(String themeExcludes)
themeExcludes
- string containing theme names to exclude which are delimited using a commapublic List<String> getAdditionalThemeDirectories()
By default all directories under the web root folder themes
are included. Other web
directories can be processed as themes by including their path in this list
If you are using the maven plugin this can be set by the maven property theme.builder.theme.adddirs
public void setAdditionalThemeDirectories(List<String> additionalThemeDirectories)
additionalThemeDirectories
- public void setAdditionalThemeDirectoriesStr(String additionalThemeDirectories)
additionalThemeDirectories
- string containing additional theme directories which are
delimited using a commapublic List<String> getAdditionalPluginDirectories()
By default all directories under the web root folder plugins
are included. Other web
directories can be processed as plugins by including their path in this list
If you are using the maven plugin this can be set by the maven property theme.builder.plugin.adddirs
public void setAdditionalPluginDirectories(List<String> additionalPluginDirectories)
additionalPluginDirectories
- public void setAdditionalPluginDirectoriesStr(String additionalPluginDirectories)
additionalPluginDirectories
- string containing additional plugin directories which are
delimited using a commapublic String getProjectVersion()
In 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
public void setProjectVersion(String projectVersion)
projectVersion
- public List<ThemePreProcessor> getThemePreProcessors()
ThemePreProcessor
instances that should be applied to the themespublic void setThemePreProcessors(List<ThemePreProcessor> themePreProcessors)
themePreProcessors
- public boolean isSkipThemeProcessing()
In 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
public void setSkipThemeProcessing(boolean skipThemeProcessing)
skipThemeProcessing
- Copyright © 2005–2016 The Kuali Foundation. All rights reserved.