Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

fix for ['parser']['cache_dir'] and ['css'] #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/View/Helper/LessHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @author Òscar Casajuana <[email protected]>
* @license Apache-2.0
* @copyright Òscar Casajuana 2013-2015
* @copyright Òscar Casajuana 2013-2017
*/
namespace Less\View\Helper;

Expand Down Expand Up @@ -147,14 +147,16 @@ public function less($less = 'styles.less', array $options = [], array $modifyVa
}

try {
$css = $this->compile($less, $options['cache'], $options['parser'], $modifyVars);
$cache_dir = isset($options['parser']['cache_dir']) ?$options['parser']['cache_dir']:"";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad indentation there + missing spaces in concatenation. BTW, this will be better inside a custom function, so we can properly test the cache behavior.

$css = $cache_dir . $this->compile($less, $options['cache'], $options['parser'], $modifyVars);
if (isset($options['tag']) && !$options['tag']) {
return $css;
}
if (!$options['cache']) {
return $this->Html->formatTemplate('style', ['content' => $css]);
}
return $this->Html->css($css);

return $this->Html->css($css,$options['css']);
} catch (\Exception $e) {
// env must be development in order to see errors on-screen
if (Configure::read('debug')) {
Expand Down Expand Up @@ -211,8 +213,14 @@ protected function compile(array $input, $cache, array $options = [], array $mod
$parse = $this->prepareInputFilesForParsing($input);

if ($cache) {
$options += ['cache_dir' => $this->cssPath];
return \Less_Cache::Get($parse, $options, $modifyVars);
if( !isset($options['cache_dir'])){
$options['cache_dir'] =$this->cssPath;
} else if( substr( $options['cache_dir'], 0, 1 ) =='/'){
$options['cache_dir'] = WWW_ROOT . $options['cache_dir'];
} else {
$options['cache_dir'] = trim($this->cssPath, '/') . $options['cache_dir'];
}
return \Less_Cache::Get($parse, $options, $modifyVars);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are spaces + tabs in many of these lines. Also, the spaces of the if are not properly set and you should avoid using else if. Instead use elseif.

It's also recommendable not to use else. Better define the variable before as a fallback.

}

$lessc = new \Less_Parser($options);
Expand Down Expand Up @@ -307,6 +315,7 @@ protected function setOptions(array $options)
]);
// @codeCoverageIgnoreEnd


if (empty($options['parser'])) {
$options['parser'] = [];
}
Expand All @@ -327,7 +336,10 @@ protected function setOptions(array $options)
if (!isset($options['cache'])) {
$options['cache'] = true;
}

if (empty($options['css'])) {
$options['css'] = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a tab here too.

}

return $options;
}

Expand Down