contentbox.plugins

Class JSMin

railo-context.Component
        extended by coldbox.system.FrameworkSupertype
            extended by coldbox.system.Plugin
                extended by contentbox.plugins.JSMin
Class Attributes:
  • singleton
  •  
  • synchronized : false
  •  
  • accessors : false
  •  
  • persistent : false
  •  

    Copyright 2009 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com Author : Luis Majano Description : This is a plugin that interfaces with our own flavor of JSMin to minify CSS and JavaScript files and also compress them into a single include file. We have also added LESS support for compiling LESS into CSS for you or on-demand. Configuration Settings: jsmin_enable : boolean (defaults to true) - flag to enable disable the packaging process jsmin_cacheLocation : string - the relative file location where cached minified js/css files will be stored, this location will be expanded. ex: includes/cache If any of the minify methods cannot find a location argument or the jsmin_cacheLocation setting then an exception will be thrown. Usage: minify(assets:string, location:relativePath) : html script or link The main method of operation is minify(). You pass to it a list of assets to compress, but they have to be of the same type: js or css/less. Do not alternate or weird results will happen. This method returns a script or link include that you would output on your layouts: #getMyPlugin("JSMin").minify('includes/js/myscripts.js,includes/js/jquery.js')# #getMyPlugin("JSMin").minify('includes/css/site.css,includes/css/boxes.css')# #getMyPlugin("JSMin").minify('includes/css/site.less,includes/css/boxes.less')# // With Location #getMyPlugin("JSMin").minify(assets='includes/css/site.less,includes/css/boxes.less', location='includes/mycache')# As you can see from the example above, you can easily render the minified version of all the assets. This plugin will minify each asset and if more than 1 is declared, then it will build a concatenated version of the js or css/less assets and cache them. If the files are of LESS extension, then the plugin will compile the LESS into CSS files. You can use the alternate 'location' argument to choose the location of the compressed and minified files. minifyToHead(assets:string, location:relativePath) : void This method basically sends the HTML links and script tags to the head section using cfhtmlhead. You can use this method when calling JSMin via handlers or plugins or any other location than layouts. compileLessSource(input:LESS, [ output:absolutePath ]) : CSS This method compiles LESS source into CSS for you and returns it to you if no output argument is used, else the compiled source is sent to the output file. An extra goody about this method is that compilation only takes place if the source LESS file has been modified. compileLess(input:absolutePath, [ output:absolutePath ]) : [void | CSS] This methods can compile an input LESS file into an output CSS file or you can omit passing the output file argument and the method will return to you the compiled CSS.

    Constructor Summary
    init(any controller)
          CONSTRUCTOR ********************************************.
    Method Summary
    JSMin cleanCache([any location=''])
         Clean the cache location for cached assets.
    any compileLess(any input, [any output])
         Compile LESS into CSS either to an output file or return.
    any compileLessSource(string input, [any output])
         Compile LESS source string into CSS.
    private any isLessModified(any input)
         Check if the LESS file has been modified or first time we see it.
    private any jsmin(any cacheKey, any assets, any location)
         JSMin a set of files and return the compressed version cache string file.
    any minify(any assets, [any location=''])
         Prepare source(s) statements using our fabulous jsmin compressor and return back the include HTML.
    JSMin minifyToHead(any assets, [any location=''])
         Prepare source(s) statements using our fabulous jsmin compressor and send them to the head section.
    any renderLinks(any assets)
         Renders links according to passed in assets.
     
    Methods inherited from class coldbox.system.Plugin
    getpluginAuthor, getpluginAuthorURL, getPluginDescription, getPluginName, getpluginPath, getPluginVersion, getRequestCollection, getRequestContext, setpluginAuthor, setpluginAuthorURL, setPluginDescription, setPluginName, setPluginVersion
     
    Methods inherited from class coldbox.system.FrameworkSupertype
    addAsset, announceInterception, getCache, getController, getDatasource, getInstance, getInterceptor, getModel, getModuleConfig, getModuleSettings, getMyPlugin, getPlugin, getRenderer, getSetting, getSettingStructure, includeUDF, loadApplicationHelpers, locateDirectoryPath, locateFilePath, persistVariables, populateModel, renderExternalView, renderLayout, renderView, runEvent, setController, setNextEvent, setSetting, settingExists
     
    Methods inherited from class railo-context.Component
    None

    Constructor Detail

    init

    public init(any controller)

    CONSTRUCTOR ********************************************

    Parameters:
    controller

    Method Detail

    cleanCache

    public JSMin cleanCache([any location=''])

    Clean the cache location for cached assets

    Parameters:
    location - The location to store the cached assets, else it defaults to the plugin's settings

    compileLess

    public any compileLess(any input, [any output])

    Compile LESS into CSS either to an output file or return

    Parameters:
    input - The input LESS absolute file location
    output - The output LESS absolute file location

    compileLessSource

    public any compileLessSource(string input, [any output])

    Compile LESS source string into CSS

    Parameters:
    input - The input LESS source code to compile back to CSS
    output - The output LESS absolute file location

    isLessModified

    private any isLessModified(any input)

    Check if the LESS file has been modified or first time we see it.

    Parameters:
    input

    jsmin

    private any jsmin(any cacheKey, any assets, any location)

    JSMin a set of files and return the compressed version cache string file

    Parameters:
    cacheKey - The cache key in use
    assets - A list of js or css files to compress and add to the page. They will be concatenated in order
    location - The location on disk to store the assets

    minify

    public any minify(any assets, [any location=''])

    Prepare source(s) statements using our fabulous jsmin compressor and return back the include HTML

    Parameters:
    assets - A list of js or css/less files to compress and add to the page. They will be concatenated in order
    location - The location to store the cached assets, else it defaults to the plugin's settings

    minifyToHead

    public JSMin minifyToHead(any assets, [any location=''])

    Prepare source(s) statements using our fabulous jsmin compressor and send them to the head section

    Parameters:
    assets - A list of js or css/less files to compress and add to the page. They will be concatenated in order
    location - The location to store the cached assets, else it defaults to the plugin's settings

    renderLinks

    public any renderLinks(any assets)

    Renders links according to passed in assets

    Parameters:
    assets - A list of js/css files to compress and add to the page