This repository has been archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
fix for ['parser']['cache_dir'] and ['css'] #16
Open
dwilbanks
wants to merge
1
commit into
elboletaire:master
Choose a base branch
from
dwilbanks:develop-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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']:""; | ||
$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')) { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 It's also recommendable not to use |
||
} | ||
|
||
$lessc = new \Less_Parser($options); | ||
|
@@ -307,6 +315,7 @@ protected function setOptions(array $options) | |
]); | ||
// @codeCoverageIgnoreEnd | ||
|
||
|
||
if (empty($options['parser'])) { | ||
$options['parser'] = []; | ||
} | ||
|
@@ -327,7 +336,10 @@ protected function setOptions(array $options) | |
if (!isset($options['cache'])) { | ||
$options['cache'] = true; | ||
} | ||
|
||
if (empty($options['css'])) { | ||
$options['css'] = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a tab here too. |
||
} | ||
|
||
return $options; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.