lessphp icon indicating copy to clipboard operation
lessphp copied to clipboard

Added support for fetching remote files in "@import" (supports HTTP and HTTPS).

Open afolgado opened this issue 13 years ago • 7 comments

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.

afolgado avatar Jun 05 '12 07:06 afolgado

It's a cool feature, but I'm not entirely sure this belongs are part of lessphp core.

leafo avatar Jun 10 '12 18:06 leafo

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

afolgado avatar Jun 10 '12 20:06 afolgado

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?

dsferruzza avatar Nov 28 '13 13:11 dsferruzza

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?

afolgado avatar Nov 28 '13 13:11 afolgado

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?

dsferruzza avatar Nov 28 '13 14:11 dsferruzza

It looks good to me, but I'm not really sure as that code is from Leafo. Give it a try...

afolgado avatar Nov 28 '13 14:11 afolgado

any movement on this?

tjwebb avatar Mar 03 '15 21:03 tjwebb