1
0
Fork 0
mirror of https://github.com/Oreolek/kohana-less.git synced 2024-04-25 05:39:19 +03:00

Changes and fixes for Kohana 3.2

This commit is contained in:
Karol Janyst 2011-08-02 11:03:30 +02:00
parent b8df9fd275
commit ac74817804
5 changed files with 40 additions and 24 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "vendor/lessphp"]
path = vendor/lessphp
url = git://github.com/leafo/lessphp.git

View file

@ -1,5 +1,5 @@
KO3 LESS Module v.1.1
=====================
KO3 LESS Module v.1.1.1
=======================
LESS Module is a port of Leaf Corcoran's [LESSPHP](http://leafo.net/lessphp) for Kohana 3
It adopts some of Alex Sancho's Kohana 2.3 Assets Module codes for CSS compression, credits goes to them
@ -13,12 +13,11 @@ To Use
3. Copy the less config file from /modules/less/config/less.php to your application's config directory
4. From your less.php config file, put the 'path' to where you want the CSS files compiled / compressed, the folder must be writable
5. You can set 'compress' to TRUE on your less.php config file if you want your CSS files to be combined in to one file and compressed (to lessen server calls)
6. Checkout how to use through the included sample-code folder, that folder is not part of the module
Sample Code
------------
Default less files extension is set into `Less::$extension` and is `.less`.
** MODPATH/baseModule/media/css/layout.less **
@ -60,27 +59,34 @@ Sample Code
'compress' => TRUE,
);
** APPPATH/classes/controller/sample.php **
** In your controller **
class Controller_Sample extends Controller_Template {
public $template = 'template';
public function action_index()
public function action_example1()
{
// no need to add .less extension
// you can put your less files anywhere
$less_files = array
(
MODPATH.'baseModule/media/css/layout',
MODPATH.'baseModule/media/css/layout.less',
APPPATH.'media/css/style',
);
$this->template->stylesheet = Less::compile($less_files);
}
public function action_example2()
{
// you can pass just single file
$this->template->stylesheet = Less::compile(APPPATH.'media/css/style');
}
}
** APPPATH/views/template.php **
** In your template **
<html>
<head>

BIN
classes/less/.DS_Store vendored

Binary file not shown.

View file

@ -2,16 +2,24 @@
class Less_Core
{
// Default less files extension
public static $ext = '.less';
/**
* Get the link tag of less paths
*
* @param array array of css paths
* @param mixed array of css paths or single path
* @param string value of media css type
* @param boolean allow compression
* @return string link tag pointing to the css paths
*/
public static function compile($array = array(), $media = 'screen')
public static function compile($array = NULL, $media = 'screen')
{
if (is_string($array))
{
$array = array($array);
}
// return comment if array is empty
if (empty($array)) return self::_html_comment('no less files');
@ -21,16 +29,17 @@ class Less_Core
// validate
foreach ($array as $file)
{
// remove extension if its present
$file = preg_replace('/\.less/', '', $file);
if (file_exists($file.'.less'))
if (file_exists($file))
{
array_push($stylesheets, $file);
}
elseif (file_exists($file.self::$ext))
{
array_push($stylesheets, $file.self::$ext);
}
else
{
array_push($assets, self::_html_comment('could not find '.Kohana::debug_path($file).'.less'));
array_push($assets, self::_html_comment('could not find '.Debug::path($file).self::$ext));
}
}
@ -38,7 +47,7 @@ class Less_Core
if ( ! count($stylesheets)) return self::_html_comment('all less files are invalid');
// get less config
$config = Kohana::config('less');
$config = Kohana::$config->load('less');
// if compression is allowed
if ($config['compress'])
@ -96,12 +105,9 @@ class Less_Core
// if the file exists no need to generate
if ( ! file_exists($filename))
{
// create data holder
$data = '';
touch($filename, filemtime($file) - 3600);
touch($filename, filemtime($file.'.less') - 3600);
lessc::ccompile($file.'.less', $filename);
lessc::ccompile($file, $filename);
}
return $filename;
@ -116,7 +122,7 @@ class Less_Core
protected static function _combine($files)
{
// get assets' css config
$config = Kohana::config('less');
$config = Kohana::$config->load('less');
// get the most recent modified time of any of the files
$last_modified = self::_get_last_modified($files);
@ -153,7 +159,7 @@ class Less_Core
foreach($files as $file)
{
$data .= file_get_contents($file.'.less');
$data .= file_get_contents($file);
}
echo $data;
@ -196,7 +202,7 @@ class Less_Core
foreach ($files as $file)
{
$modified = filemtime($file.'.less');
$modified = filemtime($file);
if ($modified !== false and $modified > $last_modified) $last_modified = $modified;
}

1
vendor/lessphp vendored Submodule

@ -0,0 +1 @@
Subproject commit c26bc93eb07014b422251a92d94fd40a915fd199