Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to define base path for resources #325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/CSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ protected function importFiles($source, $content)

// get the path for the file that will be imported
$path = $match[2];
$path = dirname($source).'/'.$path;
$path = $this->resourcesBasePath . dirname($source).'/'.$path;

// only replace the import with the content if we're able to get
// the content of the file, and it's relatively small
Expand Down
23 changes: 22 additions & 1 deletion src/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ abstract class Minify
*/
public $extracted = array();

/**
* Path from where resources like images, fonts etc. can be imported.
* Minify will be default look for resources based on its path defined in CSS,
* if your structure of files is different because of different folder structure,
* you can specify base directory.
* @var string
*/
protected $resourcesBasePath = "";

/**
* Init the minify class - optionally, code may be passed along already.
*/
Expand Down Expand Up @@ -105,7 +114,7 @@ public function add($data /* $data = null, ... */)
* @param string|string[] $data
*
* @return static
*
*
* @throws IOException
*/
public function addFile($data /* $data = null, ... */)
Expand Down Expand Up @@ -192,6 +201,18 @@ public function cache(CacheItemInterface $item)
return $item;
}

/**
* Path from where resources like images, fonts etc. can be imported.
* Minify will be default look for resources based on its path defined in CSS,
* if your structure of files is different because of different folder structure,
* you can specify base directory.
* @var string
*/
public function setResourcesBasePath(string $path)
{
$this->resourcesBasePath = $path;
}

/**
* Minify the data.
*
Expand Down