kriansa / fuel-less

Less implementation for FuelPHP using lessphp and nodejs. Unmaintained.
MIT License
28 stars 7 forks source link

Dealing with includes / @import #4

Closed 3en closed 12 years ago

3en commented 12 years ago

Hello,

Good job with the package! I was just wondering is there a way to deal with LESS includes / @imports. At the moment if an less import is modified the parent LESS file isn't complied to CSS.

kriansa commented 12 years ago

That's a good idea, I'll see what I can do this weekend.

s4wny commented 12 years ago

Quick fix that I made for my self. Maybe works for you too. The problem is that this may recompile code even if it isn't necessarily.

Line 65

// Compile only if source is newer than compiled file
if ( ! is_file($compiled_css) or $this->shouldRecompile($compiled_css, \Config::get('asset.less_source_dir')))

Add somewhere in the class

/**
 * Checks if any file in the asset/less_source_dir is newer then the compiled file.
 *
 * I created this functions because I import files within my .less file. And then I
 * updated an imported .less file the main .less file won't be recompiled cuz this script
 * just chekcs the main .less files modification date.
 *
 * Note: This function works for my situation there I just use one .less file
 * that import others .less files. 
 *
 * If you use many .less files this file may recompile files that dosen't need too be recompiled.
 *
 * @author Sony?
 */
private function shouldRecompile($compiled_css, $dir)
{
    foreach(glob($dir . '*') as $file)
    {
        if(is_dir($file)) {
            if($this->shouldRecompile($compiled_css, $dir . $file . '/')) {
                return true;
            }
        }
        else {
            if(filemtime($file) > filemtime($compiled_css)) {
                return true;
            }
        }
    }

    return false;
}
kriansa commented 12 years ago

Hey @s4wny , take a look at the new 2.0 branch.

https://github.com/kriansa/fuel-less/tree/2.0/master