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

@import resources from the classpath #28

Open
fleaflicker opened this issue May 30, 2012 · 5 comments
Open

@import resources from the classpath #28

fleaflicker opened this issue May 30, 2012 · 5 comments

Comments

@fleaflicker
Copy link

I cannot @import a file from a different folder (but on the classpath).

How does the LessEngine load files for @import?

Example:

@import "test.less"

where test.less isn't in the same folder but its parent is added to the java classpath?

@asual
Copy link
Owner

asual commented May 31, 2012

Have you tried @import "../test.less"? For classpath imports we use @import "classpath:META-INF/less/import.less".

@fleaflicker
Copy link
Author

Yes, using the notation @import "classpath:..."; does work

But I cannot use that notation because I'm trying to use the same .less file in production (compiled with asual engine) and in development (using the traditional less.js browser mode).

Is there any way the asual engine to do this automatically behind the scenes? First try to import relative to working directory, then check the classpath if unable to find the file.

@asual
Copy link
Owner

asual commented Jun 1, 2012

It will be great if you can do this with relative paths. I will check if a classpath fallback is possible.

@fleaflicker
Copy link
Author

Thanks.

Something as simple as wrapping the call in a try-catch block and then checking the classpath (both with the "classpath:" notation and without) should work.

@rkrzewski
Copy link

This can be implemented using the changes introduced with #32

You need to override the default resource loading configuration by adding a variant of ClasspathResourceLoader that will check if the resource is present on the classpath even if no 'classpath:' prefix was given in the @include directive:

import com.asual.lesscss.loader.ClasspathResourceLoader;

class ClasspathFallbackResourceLoader
    extends ClasspathResourceLoader {
    ClasspathFallbackResourceLoader(ClassLoader cl) {
        super(cl);
    }

    @Override
    protected String getSchema() {
        return "";
    }
}

then you can combine it with regular ClasspathResourceLoader using ChainedResourceLoader and pass it to LessEngine.init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants