mirror of
https://github.com/Oreolek/kohana-less.git
synced 2024-05-04 01:59:20 +03:00
Changes and fixes for Kohana 3.2
This commit is contained in:
parent
b8df9fd275
commit
ac74817804
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "vendor/lessphp"]
|
||||||
|
path = vendor/lessphp
|
||||||
|
url = git://github.com/leafo/lessphp.git
|
22
README.md
22
README.md
|
@ -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
|
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
|
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
|
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
|
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)
|
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
|
Sample Code
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
Default less files extension is set into `Less::$extension` and is `.less`.
|
||||||
|
|
||||||
|
|
||||||
** MODPATH/baseModule/media/css/layout.less **
|
** MODPATH/baseModule/media/css/layout.less **
|
||||||
|
@ -60,27 +59,34 @@ Sample Code
|
||||||
'compress' => TRUE,
|
'compress' => TRUE,
|
||||||
);
|
);
|
||||||
|
|
||||||
** APPPATH/classes/controller/sample.php **
|
** In your controller **
|
||||||
|
|
||||||
class Controller_Sample extends Controller_Template {
|
class Controller_Sample extends Controller_Template {
|
||||||
|
|
||||||
public $template = 'template';
|
public $template = 'template';
|
||||||
|
|
||||||
public function action_index()
|
public function action_example1()
|
||||||
{
|
{
|
||||||
// no need to add .less extension
|
// no need to add .less extension
|
||||||
// you can put your less files anywhere
|
// you can put your less files anywhere
|
||||||
$less_files = array
|
$less_files = array
|
||||||
(
|
(
|
||||||
MODPATH.'baseModule/media/css/layout',
|
MODPATH.'baseModule/media/css/layout.less',
|
||||||
APPPATH.'media/css/style',
|
APPPATH.'media/css/style',
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->template->stylesheet = Less::compile($less_files);
|
$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>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
|
BIN
classes/less/.DS_Store
vendored
BIN
classes/less/.DS_Store
vendored
Binary file not shown.
|
@ -2,16 +2,24 @@
|
||||||
|
|
||||||
class Less_Core
|
class Less_Core
|
||||||
{
|
{
|
||||||
|
// Default less files extension
|
||||||
|
public static $ext = '.less';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the link tag of less paths
|
* 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 string value of media css type
|
||||||
* @param boolean allow compression
|
* @param boolean allow compression
|
||||||
* @return string link tag pointing to the css paths
|
* @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
|
// return comment if array is empty
|
||||||
if (empty($array)) return self::_html_comment('no less files');
|
if (empty($array)) return self::_html_comment('no less files');
|
||||||
|
|
||||||
|
@ -21,16 +29,17 @@ class Less_Core
|
||||||
// validate
|
// validate
|
||||||
foreach ($array as $file)
|
foreach ($array as $file)
|
||||||
{
|
{
|
||||||
// remove extension if its present
|
if (file_exists($file))
|
||||||
$file = preg_replace('/\.less/', '', $file);
|
|
||||||
|
|
||||||
if (file_exists($file.'.less'))
|
|
||||||
{
|
{
|
||||||
array_push($stylesheets, $file);
|
array_push($stylesheets, $file);
|
||||||
}
|
}
|
||||||
|
elseif (file_exists($file.self::$ext))
|
||||||
|
{
|
||||||
|
array_push($stylesheets, $file.self::$ext);
|
||||||
|
}
|
||||||
else
|
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');
|
if ( ! count($stylesheets)) return self::_html_comment('all less files are invalid');
|
||||||
|
|
||||||
// get less config
|
// get less config
|
||||||
$config = Kohana::config('less');
|
$config = Kohana::$config->load('less');
|
||||||
|
|
||||||
// if compression is allowed
|
// if compression is allowed
|
||||||
if ($config['compress'])
|
if ($config['compress'])
|
||||||
|
@ -96,12 +105,9 @@ class Less_Core
|
||||||
// if the file exists no need to generate
|
// if the file exists no need to generate
|
||||||
if ( ! file_exists($filename))
|
if ( ! file_exists($filename))
|
||||||
{
|
{
|
||||||
// create data holder
|
touch($filename, filemtime($file) - 3600);
|
||||||
$data = '';
|
|
||||||
|
|
||||||
touch($filename, filemtime($file.'.less') - 3600);
|
lessc::ccompile($file, $filename);
|
||||||
|
|
||||||
lessc::ccompile($file.'.less', $filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $filename;
|
return $filename;
|
||||||
|
@ -116,7 +122,7 @@ class Less_Core
|
||||||
protected static function _combine($files)
|
protected static function _combine($files)
|
||||||
{
|
{
|
||||||
// get assets' css config
|
// get assets' css config
|
||||||
$config = Kohana::config('less');
|
$config = Kohana::$config->load('less');
|
||||||
|
|
||||||
// get the most recent modified time of any of the files
|
// get the most recent modified time of any of the files
|
||||||
$last_modified = self::_get_last_modified($files);
|
$last_modified = self::_get_last_modified($files);
|
||||||
|
@ -153,7 +159,7 @@ class Less_Core
|
||||||
|
|
||||||
foreach($files as $file)
|
foreach($files as $file)
|
||||||
{
|
{
|
||||||
$data .= file_get_contents($file.'.less');
|
$data .= file_get_contents($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $data;
|
echo $data;
|
||||||
|
@ -196,7 +202,7 @@ class Less_Core
|
||||||
|
|
||||||
foreach ($files as $file)
|
foreach ($files as $file)
|
||||||
{
|
{
|
||||||
$modified = filemtime($file.'.less');
|
$modified = filemtime($file);
|
||||||
if ($modified !== false and $modified > $last_modified) $last_modified = $modified;
|
if ($modified !== false and $modified > $last_modified) $last_modified = $modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
vendor/lessphp
vendored
Submodule
1
vendor/lessphp
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit c26bc93eb07014b422251a92d94fd40a915fd199
|
Loading…
Reference in a new issue