Permalink
Browse files

Changes and fixes for Kohana 3.2

  • Loading branch information...
1 parent b8df9fd commit ac7481780484c4dbe2e18468cb68f6b046941370 @LKay LKay committed Aug 2, 2011
Showing with 40 additions and 24 deletions.
  1. +3 −0 .gitmodules
  2. +14 −8 README.md
  3. BIN classes/less/.DS_Store
  4. +22 −16 classes/less/core.php
  5. +1 −0 vendor/lessphp
View
@@ -0,0 +1,3 @@
+[submodule "vendor/lessphp"]
+ path = vendor/lessphp
+ url = git://github.com/leafo/lessphp.git
View
@@ -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>
View
Binary file not shown.
View
@@ -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,24 +29,25 @@ public static function compile($array = array(), $media = 'screen')
// 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));
}
}
// all stylesheets are invalid
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 @@ protected static function _get_filename($file, $path)
// if the file exists no need to generate
if ( ! file_exists($filename))
{
- // create data holder
- $data = '';
-
- touch($filename, filemtime($file.'.less') - 3600);
+ touch($filename, filemtime($file) - 3600);
- lessc::ccompile($file.'.less', $filename);
+ lessc::ccompile($file, $filename);
}
return $filename;
@@ -116,7 +122,7 @@ protected static function _get_filename($file, $path)
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 @@ protected static function _generate_assets($filename, $files)
foreach($files as $file)
{
- $data .= file_get_contents($file.'.less');
+ $data .= file_get_contents($file);
}
echo $data;
@@ -196,7 +202,7 @@ protected static function _get_last_modified($files)
foreach ($files as $file)
{
- $modified = filemtime($file.'.less');
+ $modified = filemtime($file);
if ($modified !== false and $modified > $last_modified) $last_modified = $modified;
}
Submodule lessphp added at c26bc9

0 comments on commit ac74817

Please sign in to comment.