/**
* Less process file.
*
* @param string $source ("Example: MyPlugin.path/to/file.less")
* @param bool|false $force
* @throws \JBZoo\Less\Exception
* @return string
*/
public function process($source, $force = false)
{
$file = $this->_path->isVirtual($source) ? $this->_path->get($source) : $this->_path->get('root:' . $source);
try {
if ($force) {
$this->config('force', true);
}
$less = new Less($this->_config);
if (!FS::isFile($file)) {
return $source;
}
list($source, $isExpired) = $less->compile($file);
if ($isExpired) {
$cacheId = FS::firstLine($source);
$comment = '/* resource: ' . $this->_path->url($file) . ' */' . PHP_EOL;
$fileHead = implode('', [$cacheId, Str::low($comment)]);
$css = $this->_normalizeContent($source, $fileHead);
$this->_write($source, $css);
}
$source = $this->_path->url(FS::clean($source, '/'));
return $source;
} catch (InternalErrorException $e) {
throw new InternalErrorException($e->getMessage());
}
}