To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Changeset 4464

Show
Ignore:
Timestamp:
01/07/12 14:17:56 (5 months ago)
Author:
tboutell
Message:

New 'prepend' option to aAssets::compileLessIfNeeded() and aAssets::cexecute() specifies LESS code to be prepended to the content of the file to be compiled. This is useful for automatically setting LESS variables based on configuration settings. Needed by PR

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/branches/1.5/lib/toolkit/BaseaAssets.class.php

    r4339 r4464  
    5555   * be used to retrieve the cached array; if you get an array back $info['compiled'] has 
    5656   * the compiled CSS code. 
     57   * 
     58   * If $options['prepend'] is set it is prepended to the LESS code before compilation. 
    5759   */ 
    5860  static public function compileLessIfNeeded($path, $compiled, $options = array()) 
     
    121123    } 
    122124    $lastUpdated = is_array($info) ? $info['updated'] : 0; 
    123     $info = aAssets::cexecute($info, false); 
     125     
     126    $lessOptions = array(); 
     127    if (isset($options['prepend'])) 
     128    { 
     129      $lessOptions['prepend'] = $options['prepend']; 
     130    } 
     131    $info = aAssets::cexecute($info, false, $lessOptions); 
    124132                // Our replacement for cexecute() calls parse() on the contents of a file, so 
    125133                // the cache info structure is missing the name of the original requested file. 
     
    207215         * The cache structure is a plain-ol' PHP associative array and can 
    208216         * be serialized and unserialized without a hitch. 
     217         * 
     218         * If $options['prepend'] is present that LESS code is prepended before 
     219         * the compilation. 
    209220         *  
    210221         * @param mixed $in Input 
    211          * @param bool $force Force rebuild? 
     222         * @param bool $force Force rebuild 
     223         * @param array $options  
    212224         * @return array lessphp cache structure 
    213225         */ 
    214         public static function cexecute($in, $force = false)  
     226        public static function cexecute($in, $force = false, $options = array())  
    215227        { 
    216228                // assume no root 
     
    246258                        $out = array(); 
    247259                        $out['root'] = $root; 
    248                         $out['compiled'] = $less->parse(file_get_contents($root)); 
     260                        $code = file_get_contents($root); 
     261                        if (isset($options['prepend'])) 
     262                        { 
     263                          $code = $options['prepend'] . "\n" . $code; 
     264                        } 
     265                        $out['compiled'] = $less->parse($code); 
    249266                        $out['files'] = $less->allParsedFiles(); 
    250267                        $out['updated'] = time();