roborourke / wp-less

Provides a LESS compiler compatible with wp_enqueue_style() for rapid CSS development in themes and plugins.
MIT License
217 stars 55 forks source link

lessphp 0.3.7 and above has a new PHP api #21

Closed scottsweb closed 11 years ago

scottsweb commented 12 years ago

The latest versions of lessphp requires a change to wp-less. From line 125 I have made the following changes:

// automatically regenerate files if source's modified time has changed or vars have changed
try {

    // load the cache
    $cache_path = "{$css_path}.cache";

    if (file_exists($cache_path))
        $full_cache = unserialize( file_get_contents( $cache_path ) );

    // If the root path in the cache is wrong then regenerate
    if ( ! isset( $full_cache[ 'less' ][ 'root' ] ) || ! file_exists( $full_cache[ 'less' ][ 'root' ] ) )
        $full_cache = array( 'vars' => $vars, 'less' => $less_path );

    // *** different approach to setting variables from php and compiling from cache ***
    $less = new lessc();
    $less->setVariables($vars);
    $less_cache = $less->cachedCompile($full_cache['less']);

    if ( ! is_array( $full_cache ) || $less_cache[ 'updated' ] > $full_cache['less']['updated'] || $vars !== $full_cache[ 'vars' ] ) {      
        file_put_contents( $cache_path, serialize( array( 'vars' => $vars, 'less' => $less_cache ) ) );
        file_put_contents( $css_path, $less_cache['compiled']);
    }
}

I would not necessarily make the changes yet though as lessphp 0.3.8 is not working particularly well for me at the moment and has introduced a heap of new bugs.

It might also be worth looking at the new output formatting (http://leafo.net/lessphp/docs/#output_formatting) options in order to compress the compiled CSS further.

roborourke commented 12 years ago

Thanks for letting me know and fort the code Scott.

I'll wait for another point release or two or perhaps make a branch for the updated lessphp.

tomjn commented 11 years ago

0.3.8 is out!

roborourke commented 11 years ago

Latest update uses 0.3.8 and adds a few extra functions