Comments (1)
I found a way to do this in a derived class with an ugly hack. Here's my currently functional code.
// extension for import to use theme URLs function import(&$url, &$media) { $ret = parent::import($url, $media); if ($ret) { $url = $this->processURL($url); } return $ret; } function lib_url($arg) { return 'url('.$this->processURL($this->compileValue($arg), true).')'; } function processURL($url, $relative = false) { // nasty hack, because processURL entirely replaces the functionality // that $this->importDir was previously used for. We look to see if there // was a value for $this->importDir, and if so, we move it to a new variable // $this->baseUrlDir. Then we clear $this->importDir so that it doesn't get // in the way later. if ($this->importDir) { $this->baseUrlDir = $this->importDir; $this->importDir = null; } // remove quotes, if present if ($this->quoted($url)) $url = substr($url, 1, -1); // find the protocol, if any $protocol = ''; if (preg_match('~^([a-zA-Z]+)\:[\\/]?[\\/]?(.*)~', $url, $matches)) { // this URL has a protocol $protocol = isset($matches[1]) ? $matches[1] : ''; $path = isset($matches[2]) ? $matches[2] : ''; // TODO: do we need to do anything special with any protocols? switch ($protocol) { // the following cases should always return the input directly. We don't need to do anything special. case 'data': case 'http': case 'https': default: return $url; // return the original URL } } else { // No protocol. This is a relative URL of some sort. // normalize slashes $url = str_replace('\\', '/', $url); $docroot = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']); $base = str_replace('\\', '/', $this->baseUrlDir); // if the url starts with a slash, it is an absolute path from the document root if ($url{0} == '/') { return $url; } else // just a normal relative path { // convert to an absolute path $url = rtrim($base, '/').'/'.ltrim($url, '/'); if ($relative) { // a relative path is wanted, so reduce it to a path from the document root $url = str_replace($docroot, '', $url); if ($url{0} != '/') { $url = '/'.$url; } } return $url; } } return $url; }
With some small tweaks to the above I can add support for hierarchical themed URLs. This also shows how the processing can address some issues with images, so that the final file always contains the proper full path to the image (fixes some issues with importing files from another directory for example).
from lessphp.
Related Issues (20)
- parse error: failed at `$result: &;` (stdin) HOT 1
- Will the project uodated to teh newest less version? HOT 2
- @supports CSS Feature Queries not working HOT 3
- Both DOS and UNIX style line endings issue on Theme Check WordPress Plugin
- guarded recursion fails on exit
- setPreserveComments changes line endings
- Parse error with CSS Grid Layout and named grid lines/areas HOT 3
- lessphp fatal error: expected color value: /home/iler/public_html/wp-content/themes/CherryFramework-child2/bootstrap/less/bootstrap.less on line 63
- less parser fails with UIKIT 3 less files HOT 3
- less parser fails with less.js built-in function color() HOT 1
- recursive mixin not working in nested rule
- Background SVG animation breaks generation
- PHP Fatal error: Uncaught Exception: E_NOTICE in PHP 7.4 HOT 3
- Error parse: calc function HOT 1
- Deprecated Array and string offset access syntax with curly braces is deprecated HOT 5
- Imported files get optimized incorrectly. HOT 1
- Deprecated stuff under PHP 8.1 HOT 3
- each loop -> Uncaught Exception: parse error: failed at `); `
- Support for PHP 8.2 HOT 4
- Deprecated things under PHP 8.2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lessphp.