Class ViewTheme
- All Implemented Interfaces:
Serializable,Cloneable,Copyable,DictionaryBean,UifDictionaryBean
The list of CSS and JS files that are sourced in for a view come from its theme, along with any
additional files configured for the specific view. Generally an application will have one theme for the
entire application.
The theme has logic for 'dev' mode versus 'test/prod' mode. This is controlled through the
rice.krad.dev.mode configuration variable. In development mode it will source in all the CSS
and JS files individually (to allow for easier debugging). In non-development mode it will source in a
minified file. The path for the minified files can be specified by setting getMinCssFile() and
getMinScriptFile(). If not set, it will be formed by using the getName(),
getMinVersionSuffix(), and min suffix (this is the file name generated by the theme builder). To
indicate the min file should not be sourced in regardless of the environment, set the property
isIncludeMinFiles() to false
The path to the minified file is determined by getDirectory(). It this is not set, it is defaulted to
be '/themes' plus the name of the theme (eg '/themes/kboot')
There are two ways the theme can be configured, manual or by convention. If you want to manually configured the
view theme, set isUsesThemeBuilder() to false. For dev mode, you must then set the getMinCssSourceFiles() and getMinScriptSourceFiles() lists to the theme files. For configuration
by convention, only the theme getName() is required. The directory will be assumed to be '/themes/{name}'.
Furthermore the list of min CSS and JS files will be retrieved from the theme.properties file created by the
theme builder
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
- See Also:
-
Field Summary
Fields inherited from class org.kuali.rice.krad.datadictionary.DictionaryBeanBase
componentCode, namespaceCode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInvoked by View#performApplyModel method to setup defaults for the themeorg.kuali.rice.core.api.config.property.ConfigurationServiceHelper method to retrieve an instance ofConfigurationServiceList of file paths (relative to the web root) or URLs that will be sourced into the view as CSS filesPath to the directory (relative to the web root) that holds the assets for the themePath to the directory (relative to the web root) that contains images for the themeFile path for the minified CSS fileList of file paths (relative to web root) or URLs that make up the minified CSS fileFile path for the minified JS fileList of file paths (relative to web root) or URLs that make up the minified JS fileWhen the min file paths are not set, the min file names will be generated using the theme name, version, and the min suffix.getName()A name that identifies the view theme, when using the theme builder this should be the same as the directory (for example, if directory is '/themes/kboot', the theme name will be 'kboot')protected String[]getPropertyValue(Properties properties, String key) Helper method to retrieve the value of a property from the given Properties object as a string array (string is parsed using comma delimiter)List of file paths (relative to the web root) or URLs that will be sourced into the view as JS filesRetrieves the directory associated with the themeprotected PropertiesRetrieves the theme properties associated with the themeprotected booleanIndicates whether Less files should be included instead of Css files when running in dev mode.protected booleanIndicates whether operation is in development mode by checking the KRAD configuration parameterbooleanIndicates the min files should be sourced into the CSS and JS lists when not in development mode (this is regardless of whether theme builder is being used or not)booleanIndicates whether the theme has been built (or will be built) using the theme builder and therefore the theme configuration can be defaulted according to the conventions used by the builderprotected StringreplaceIncludeWithLessFile(String cssFilePath, String[] lessFileNames) Attempts to find a Less file match for the given css file, and if found returns the corresponding Less file path, otherwise the css path is returned unmodified.voidsetCssFiles(List<String> cssFiles) Setter for the list of CSS files that should be sourced in along with the minified filesvoidsetDirectory(String directory) Setter for the theme directory pathvoidsetImageDirectory(String imageDirectory) Setter for the directory that contains images for the themevoidsetIncludeMinFiles(boolean includeMinFiles) Setter for including min files in the CSS and JS listsvoidsetMinCssFile(String minCssFile) Setter for the min CSS file pathvoidsetMinCssSourceFiles(List<String> minCssSourceFiles) Setter for the min file CSS listprotected voidSets thegetMinScriptSourceFiles()andgetMinCssSourceFiles()lists from the corresponding properties in the theme properties file.voidsetMinScriptFile(String minScriptFile) Setter for the min JS file pathvoidsetMinScriptSourceFiles(List<String> minScriptSourceFiles) Setter for the min file JS listvoidsetMinVersionSuffix(String minVersionSuffix) Setter for the min file version stringvoidSetter for the theme namevoidsetScriptFiles(List<String> scriptFiles) Setter for the list of JS files that should be sourced in along with the minified filesvoidsetUsesThemeBuilder(boolean usesThemeBuilder) Setter the indicates whether the theme uses the theme builderMethods inherited from class org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase
getExpressionGraph, getPropertyExpression, getPropertyExpressions, setExpressionGraph, setPropertyExpressionsMethods inherited from class org.kuali.rice.krad.datadictionary.DictionaryBeanBase
clone, copy, dataDictionaryPostProcessing, getComponentCode, getNamespaceCode, setComponentCode, setNamespaceCodeMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.kuali.rice.krad.datadictionary.DictionaryBean
dataDictionaryPostProcessing, getComponentCode, getNamespaceCode
-
Constructor Details
-
ViewTheme
public ViewTheme()
-
-
Method Details
-
configureThemeDefaults
public void configureThemeDefaults()Invoked by View#performApplyModel method to setup defaults for the themeChecks whether we are in dev mode, if so it adds all the CSS and JS files as resources. If
isUsesThemeBuilder()is true, retrieve the theme-derived.properties file in the theme directory to get the listing of CSS and JS files for theme When not in dev mode, builds the min file name and path for CSS and JS, which is added to the list that is sourced in -
getThemeDirectory
Retrieves the directory associated with the themeIf
getDirectory()is not configured, the theme directory is assumed to be located in the 'themes' folder of the web root. The directory name is assumed to be the name of the theme- Returns:
- String path to theme directory relative to the web root
-
setMinFileLists
protected void setMinFileLists()Sets thegetMinScriptSourceFiles()andgetMinCssSourceFiles()lists from the corresponding properties in the theme properties file.In dev mode, any css files that were generate from Less files are replaced with an include for the Less file. This is so the less files can be modified directly (without running the theme builder. For more information see Less Usage
-
getThemeProperties
Retrieves the theme properties associated with the themeThe theme builder creates a file named
UifConstants.THEME_DERIVED_PROPERTY_FILElocated in the theme directory. Here the path is formed and loaded into a properties object- Returns:
- Properties object containing theme properties, or null if the properties file was not found
- Throws:
IOException
-
getPropertyValue
Helper method to retrieve the value of a property from the given Properties object as a string array (string is parsed using comma delimiter)- Parameters:
properties- properties object to pull property value fromkey- key for the property to retrieve- Returns:
- string array parsed from the property value, or null if property was not found or empty
-
replaceIncludeWithLessFile
Attempts to find a Less file match for the given css file, and if found returns the corresponding Less file path, otherwise the css path is returned unmodified.- Parameters:
cssFilePath- path to css file to find Less files forlessFileNames- array of less files names that are available for the theme- Returns:
- String path to less file include, or original css file include
-
inDevMode
protected boolean inDevMode()Indicates whether operation is in development mode by checking the KRAD configuration parameter- Returns:
- true if in dev mode, false if not
-
includeLess
protected boolean includeLess()Indicates whether Less files should be included instead of Css files when running in dev mode.- Returns:
- true if less files should be subsituted, false if not
-
getName
A name that identifies the view theme, when using the theme builder this should be the same as the directory (for example, if directory is '/themes/kboot', the theme name will be 'kboot')When using the theme builder (config by convention), the name is required configuration
- Returns:
- name for the theme
-
setName
Setter for the theme name- Parameters:
name-
-
getDirectory
Path to the directory (relative to the web root) that holds the assets for the themeWhen using the theme builder the directory is not required and will default to '/themes/{name}'
- Returns:
- path to theme directory
-
setDirectory
Setter for the theme directory path- Parameters:
directory-
-
getImageDirectory
Path to the directory (relative to the web root) that contains images for the themeConfigured directory will populate the
UifConstants.ContextVariableNames.THEME_IMAGEScontext variable which can be referenced with an expression for an image sourceWhen using the theme builder the image directory is not required and will default to a sub directory of the theme directory with name 'images'
- Returns:
- theme image directory
-
setImageDirectory
Setter for the directory that contains images for the theme- Parameters:
imageDirectory-
-
getMinVersionSuffix
When the min file paths are not set, the min file names will be generated using the theme name, version, and the min suffix. This property is set to indicate the version number to useFor application themes this can be set to the config parameter ${app.version}
- Returns:
- version string for the min file name
-
setMinVersionSuffix
Setter for the min file version string- Parameters:
minVersionSuffix-
-
isIncludeMinFiles
public boolean isIncludeMinFiles()Indicates the min files should be sourced into the CSS and JS lists when not in development mode (this is regardless of whether theme builder is being used or not)Default is true for including min files
- Returns:
- true if min files should be sourced in, false if not
-
setIncludeMinFiles
public void setIncludeMinFiles(boolean includeMinFiles) Setter for including min files in the CSS and JS lists- Parameters:
includeMinFiles-
-
getMinCssFile
File path for the minified CSS fileWhen min file is not set it will be generated by using the theme directory, name, version, and min prefix. This corresponds to the min file names generated by the theme builder For example, with name 'kboot' and version '2.3.0' the min file name will be '/themes/kboot/stylesheets/kboot.2.3.0.min.css'
- Returns:
- path of min css file
-
setMinCssFile
Setter for the min CSS file path- Parameters:
minCssFile-
-
getMinScriptFile
File path for the minified JS fileWhen min file is not set it will be generated by using the theme directory, name, version, and min prefix. This corresponds to the min file names generated by the theme builder For example, with name 'kboot' and version '2.3.0' the min file name will be '/themes/kboot/scripts/kboot.2.3.0.min.js'
- Returns:
- path of min css file
-
setMinScriptFile
Setter for the min JS file path- Parameters:
minScriptFile-
-
getMinCssSourceFiles
List of file paths (relative to web root) or URLs that make up the minified CSS fileIn development mode, instead of sourcing in the min CSS file, the list of files specified here will be included. This is to facilitate easier debugging. When using the theme builder this list is automatically retrieved and populated from the theme properties
- Returns:
- list of min CSS file paths or URLs
-
setMinCssSourceFiles
Setter for the min file CSS list- Parameters:
minCssSourceFiles-
-
getMinScriptSourceFiles
List of file paths (relative to web root) or URLs that make up the minified JS fileIn development mode, instead of sourcing in the min JS file, the list of files specified here will be included. This is to facilitate easier debugging. When using the theme builder this list is automatically retrieved and populated from the theme properties
- Returns:
- list of min JS file paths or URLs
-
setMinScriptSourceFiles
Setter for the min file JS list- Parameters:
minScriptSourceFiles-
-
getCssFiles
List of file paths (relative to the web root) or URLs that will be sourced into the view as CSS filesGenerally this list should be left empty, and the min file lists configured instead (or none with theme builder). However if there are resources that are not part of the minified CSS file that should be included with the theme they can be added here The minified file path (or list of individual files that make up the minification) will be added to the beginning of this list. Therefore any entries explicitly added through configuration will be sourced in last
- Returns:
- list of file paths or URLs for CSS
-
setCssFiles
Setter for the list of CSS files that should be sourced in along with the minified files- Parameters:
cssFiles-
-
getScriptFiles
List of file paths (relative to the web root) or URLs that will be sourced into the view as JS filesGenerally this list should be left empty, and the min file lists configured instead (or none with theme builder). However if there are resources that are not part of the minified JS file that should be included with the theme they can be added here The minified file path (or list of individual files that make up the minification) will be added to the beginning of this list. Therefore any entries explicitly added through configuration will be sourced in last
- Returns:
- list of file paths or URLs for JS
-
setScriptFiles
Setter for the list of JS files that should be sourced in along with the minified files- Parameters:
scriptFiles-
-
isUsesThemeBuilder
public boolean isUsesThemeBuilder()Indicates whether the theme has been built (or will be built) using the theme builder and therefore the theme configuration can be defaulted according to the conventions used by the builderWhen set to true, only the
getName()property is required to be configured for the theme. All other configuration will be determined based on convention. When manually configuring the theme, this flag should be turned off (by default this flag is on)- Returns:
- true if the theme uses the theme builder, false if not
-
setUsesThemeBuilder
public void setUsesThemeBuilder(boolean usesThemeBuilder) Setter the indicates whether the theme uses the theme builder- Parameters:
usesThemeBuilder-
-
getConfigurationService
public org.kuali.rice.core.api.config.property.ConfigurationService getConfigurationService()Helper method to retrieve an instance ofConfigurationService- Returns:
- instance of ConfigurationService
-