lessphp
lessphp copied to clipboard
Added support for fetching remote files in "@import" (supports HTTP and HTTPS).
Ex: @import 'http://cdn.mysite.com/less_repo/myfile.less';
The file name must end in ".less" if it needs to be parsed. Opposed to local imports, extensionless remote imports will be ignored and left untouched to the parsed output.
It's a cool feature, but I'm not entirely sure this belongs are part of lessphp core.
Well, please let me explain my scenario:
In my organization we have a central repository with CSS and LESS files among others. Several apps link with these files to make their own styles, but keeping the overall organization image. This makes sense because the shared LESS files contains variables such as corporate colors, etc.
Of course we don't consider the shared LESS files "private", as a normal source file could be. After all a LESS file doesn't contain any sensible data that should be hidden from the client. I don't see any security concerns there.
As you see it's perfectly logic for us to have this feature in a LESS processor, so I sincerely hope you decide to incorporate it.
Cheers.
2012/6/10 leaf < [email protected]
It's a cool feature, but I'm not entirely sure this belongs are part of lessphp core.
Reply to this email directly or view it on GitHub: https://github.com/leafo/lessphp/pull/240#issuecomment-6230835
Hi!
I was about to open an issue when I saw this PR. I'm having a similar problem, but my LESS files are stored in database.
So I'm thinking: maybe the best way to do this is to offer the possibility to register a callback. This callback would be called for each import. It would be given a parameter corresponding to the name to import, and would be expected to return the content of the corresponding LESS file. So the user would be able to implement any "fetch system". If no callback is given, the default behavior would be as it is now: searching the file around the current file, or in the directories specified by the user.
Does it make sense? What do you think?
Well, having the LESS files in a database sounds quite strange to me. Anyway, if you need it, it shouldn't be difficult to implement I think. Your approach looks good.
Why don't you fork the code and try it?
I think I'll try.
I believe the only file_get_contents() call (outside compileFile()) is done in tryImports().
That would be the right place to start: https://github.com/leafo/lessphp/blob/master/lessc.inc.php#L120
So I just need to add a little bit of logic to use a callback here, instead of calling file_get_contents().
And of course a public method to register the callback.
Am I right? Did I miss something?
It looks good to me, but I'm not really sure as that code is from Leafo. Give it a try...
any movement on this?