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

compile function returns base filename, not relative #15

Open
dwilbanks opened this issue Jan 4, 2017 · 6 comments
Open

compile function returns base filename, not relative #15

dwilbanks opened this issue Jan 4, 2017 · 6 comments
Labels

Comments

@dwilbanks
Copy link

dwilbanks commented Jan 4, 2017

When using an optional $options['cache_dir'] parameter the CSS file that gets created will be created in that directory instead of the CSS directory.

However the \Less_Cache::Get function returns the basename() of the generated file.

The result of this problem is that the filename that gets passed to $this->Html->css a basename() and the filename that gets generated by \Less_Cache::Get is inside the ['cache_dir'] directory.

There are 3 scenarios.

  1. No $options['parser']['cache_dir']
  2. $options['parser']['cache_dir'] that begins with / relative to WWW_ROOT
  3. $options['parser']['cache_dir'] that does not begin with / relative to /css

The $this->compile() function looks like this:

if ($cache) {
   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);
}

Inside the $this->less() function looks like this:

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

I'm not really sure of what is the issue 😅

@dwilbanks
Copy link
Author

dwilbanks commented Jan 4, 2017

I'll give you a very simple example using the LessHelper is it's published.

$lessOptions['parser']['cache_dir']='lesscache/';
$lessOptions['parser']['sourceMap'] =false;		
$lessHTML = $this->Less->less("less/lessmain.less",$lessOptions);
$this->append('css_first', $lessHTML);

Generates the code:

<link rel="stylesheet" href="/css/lessphp_b2937d7179c3575767343f1956dab99c07d0a826.css"/>

It should generate:

<link rel="stylesheet" href="/css/lesscache/lessphp_b2937d7179c3575767343f1956dab99c07d0a826.css"/>

Changing the ['cache_dir'] value to root relative generates the exact same HTML
$lessOptions['parser']['cache_dir']='/lesscache/';

@elboletaire
Copy link
Owner

elboletaire commented Jan 4, 2017

Ok, now I see. I'll try to fix it if I find a moment 😃

@elboletaire elboletaire added the bug label Jan 4, 2017
@elboletaire
Copy link
Owner

BTW, as in the other issue, I'm open to PRs. If you wanna fix it, I'll gladly merge the fix 😄.

Just remember to add a test for that case if possible (if you don't know how to do it you can leave that part to me).

@dwilbanks
Copy link
Author

the code I submitted works with:

  1. $lessOptions['parser']['cache_dir']='lesscache/';
  2. $lessOptions['parser']['cache_dir']='/lesscache/';
  3. // $lessOptions['parser']['cache_dir']=

I'm new to git, I still need to figure out how a PR works, when I do, I'll be happy to do it.

@elboletaire
Copy link
Owner

elboletaire commented Jan 4, 2017

I'll try to explain it in 'easy' steps:

  • Fork the repo
  • Clone your fork with git clone [email protected]......
  • Create a new branch for the changes you wanna make based on branch develop (first checkout develop, then create a branch from there).
  • Do/commit your changes
  • Push

When you push your changes, access your fork in github and github will say something about the PR. Just follow its instructions then.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants