org.kuali.rice.krad.theme.postprocessor
Class ThemeJsFilesProcessor

java.lang.Object
  extended by org.kuali.rice.krad.theme.postprocessor.ThemeFilesProcessor
      extended by org.kuali.rice.krad.theme.postprocessor.ThemeJsFilesProcessor

public class ThemeJsFilesProcessor
extends ThemeFilesProcessor

Theme files processor for JavaScript files

Merge contents are checked for a trailing semi-colon, and altered if not found to contain one. For minification, the Google Closure compiler is used: Google Closure

Author:
Kuali Rice Team (rice.collab@kuali.org)
See Also:
ThemeFilesProcessor, Compiler

Field Summary
 
Fields inherited from class org.kuali.rice.krad.theme.postprocessor.ThemeFilesProcessor
PLUGIN_FILES_KEY, projectVersion, SUBDIR_FILES_KEY, themeDirectory, themeName, themePluginDirsMap, themeProperties, workingDir
 
Constructor Summary
ThemeJsFilesProcessor(String themeName, File themeDirectory, Properties themeProperties, Map<String,File> themePluginDirsMap, File workingDir, String projectVersion)
           
 
Method Summary
protected  void addAdditionalFiles(List<File> themeFiles)
          Adds JS files from the krad scripts directory to the theme file list
protected  String getExcludesConfigKey()
          Key for the property within the theme's properties file that can be configured to exlcude files of the type being processed
protected  String getFileListingConfigKey()
          Key for the property that will be written to the theme derived properties to list the included files for the file type
protected  String getFileTypeDirectoryName()
          Name of the directory relative to the theme directory which contains files for the type
protected  String getFileTypeExtension()
          Extension (ex.
protected  Set<String> ignoredAnnotations()
          Build a Set of annotations for the compiler to ignore in jsdoc blocks
protected  void minify(File mergedFile, File minifiedFile)
          Minifies the JS contents from the given merged file into the minified file
protected  String processMergeFileContents(String fileContents, File fileToMerge, File mergedFile)
          Checks the given file contents to determine if the last character is a semicolon, if not the contents are appended with a semicolon to prevent problems when other content is appended
protected  List<String> retrieveKradScriptLoadOrder()
          Builds a list of KRAD script file names that indicates the order they should be loaded in
protected  List<File> sortThemeFiles(List<File> pluginFiles, List<File> subDirFiles)
          Sorts the list of JS files from the plugin and sub directories
 
Methods inherited from class org.kuali.rice.krad.theme.postprocessor.ThemeFilesProcessor
addMissingPluginDirs, collectThemeFiles, createMergedFile, getFileExcludes, getFileIncludes, getFileTypeSubDirectory, getPropertyValueAsPluginDirs, getThemePropertyValue, mergeFiles, process
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThemeJsFilesProcessor

public ThemeJsFilesProcessor(String themeName,
                             File themeDirectory,
                             Properties themeProperties,
                             Map<String,File> themePluginDirsMap,
                             File workingDir,
                             String projectVersion)
Method Detail

getFileTypeExtension

protected String getFileTypeExtension()
Description copied from class: ThemeFilesProcessor
Extension (ex. 'css') for the file type being processed

Specified by:
getFileTypeExtension in class ThemeFilesProcessor
Returns:
file type extension
See Also:
ThemeFilesProcessor.getFileTypeExtension()

getExcludesConfigKey

protected String getExcludesConfigKey()
Description copied from class: ThemeFilesProcessor
Key for the property within the theme's properties file that can be configured to exlcude files of the type being processed

Specified by:
getExcludesConfigKey in class ThemeFilesProcessor
Returns:
property key for file type excludes
See Also:
ThemeFilesProcessor.getExcludesConfigKey()

getFileTypeDirectoryName

protected String getFileTypeDirectoryName()
Description copied from class: ThemeFilesProcessor
Name of the directory relative to the theme directory which contains files for the type

Specified by:
getFileTypeDirectoryName in class ThemeFilesProcessor
Returns:
directory name
See Also:
ThemeFilesProcessor.getFileTypeDirectoryName()

getFileListingConfigKey

protected String getFileListingConfigKey()
Description copied from class: ThemeFilesProcessor
Key for the property that will be written to the theme derived properties to list the included files for the file type

Specified by:
getFileListingConfigKey in class ThemeFilesProcessor
Returns:
property key for file type listing
See Also:
ThemeFilesProcessor.getFileListingConfigKey()

addAdditionalFiles

protected void addAdditionalFiles(List<File> themeFiles)
Adds JS files from the krad scripts directory to the theme file list

Specified by:
addAdditionalFiles in class ThemeFilesProcessor
Parameters:
themeFiles - list of additional files to included for the theme
See Also:
ThemeFilesProcessor#addAdditionalFiles(java.util.List)

sortThemeFiles

protected List<File> sortThemeFiles(List<File> pluginFiles,
                                    List<File> subDirFiles)
Sorts the list of JS files from the plugin and sub directories

The sorting algorithm is as follows:

  1. Any files which match patterns configured by the property jsLoadFirst
  2. JS files from plugin directories, first ordered by any files that match patterns configured with pluginJsLoadOrder, followed by all remaining plugin files
  3. KRAD script files, in the order retrieved from retrieveKradScriptLoadOrder()
  4. JS files from the theme subdirectory, first ordered by any files that match patterns configured with themeJsLoadOrder, then any remaining theme files
  5. Files that match patterns configured by the property jsLoadLast. Note any files that match here will be excluded from any of the previous steps

Specified by:
sortThemeFiles in class ThemeFilesProcessor
Parameters:
pluginFiles - list of files that will be included and come from a plugin directory
subDirFiles - list of files that will be included and come from the theme subdirectory
Returns:
list of all files to include for the theme in the correct source order
See Also:
ThemeFilesProcessor#sortThemeFiles(java.util.List, java.util.List), retrieveKradScriptLoadOrder()

retrieveKradScriptLoadOrder

protected List<String> retrieveKradScriptLoadOrder()
                                            throws IOException
Builds a list of KRAD script file names that indicates the order they should be loaded in

Populates a properties object from the file ThemeBuilderConstants.KRAD_SCRIPT_LOAD_PROPERTIES_FILE located in the KRAD script directory. Then pulls the value for the property org.kuali.rice.krad.theme.util.ThemeBuilderConstants#LOAD_ORDER_PROPERTY_KEY to get the configured file load order. The KRAD scripts directory is then listed to get the remaining files names which are added at the end of the file list

Returns:
list of KRAD file names (not including path or file extension)
Throws:
IOException

processMergeFileContents

protected String processMergeFileContents(String fileContents,
                                          File fileToMerge,
                                          File mergedFile)
                                   throws IOException
Checks the given file contents to determine if the last character is a semicolon, if not the contents are appended with a semicolon to prevent problems when other content is appended

Specified by:
processMergeFileContents in class ThemeFilesProcessor
Parameters:
fileContents - contents of the file that will be added
fileToMerge - file the contents were pulled from
mergedFile - file receiving the merged contents
Returns:
file contents to merge (possibly altered)
Throws:
IOException
See Also:
ThemeFilesProcessor.processMergeFileContents(java.lang.String, java.io.File, java.io.File)

minify

protected void minify(File mergedFile,
                      File minifiedFile)
               throws IOException
Minifies the JS contents from the given merged file into the minified file

Minification is performed using the Google Closure compiler, using com.google.javascript.jscomp.CompilationLevel#WHITESPACE_ONLY and EcmaScript5 language level

Specified by:
minify in class ThemeFilesProcessor
Parameters:
mergedFile - file containing the merged contents
minifiedFile - file created to receive the minified contents
Throws:
IOException
See Also:
ThemeFilesProcessor.minify(java.io.File, java.io.File), Compiler

ignoredAnnotations

protected Set<String> ignoredAnnotations()
Build a Set of annotations for the compiler to ignore in jsdoc blocks

Returns:
Iterable


Copyright © 2005–2014 The Kuali Foundation. All rights reserved.