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 search paths #181

Closed
bringking opened this issue Jan 5, 2014 · 2 comments
Closed

@import search paths #181

bringking opened this issue Jan 5, 2014 · 2 comments

Comments

@bringking
Copy link

Does less4j support adding non-relative search paths for import statements? For example, the less.js Node compiler "lessc" supports this with the --include-path option.

@SomMeri
Copy link
Owner

SomMeri commented Jan 5, 2014

There is not such direct option, but there is a solution.

You can new LessSource type (maybe from FileSource) which would search for files in both current directory and in custom non-relative paths.

Using custom less source:

//create demo less file and compiler
File inputLessFile = createFile("sampleInput.less", "* { margin: 1 1 1 1; }");
LessCompiler compiler = new ThreadUnsafeLessCompiler();

//use custom less source
CompilationResult compilationResult = compiler.compile(new CustomFileSource(inputLessFile));

//print compiled css
System.out.println(compilationResult.getCss());

Either constructor or relativeSource method of your custom less source will contain something like this:

this.inputFile = new File(parent.inputFile.getParentFile(), filename);
if (!inputFile.exists()) {
  this.inputFile = new File(CUSTOM_PATH, filename);
}

Note: import-once feature uses LessSource.equals to check for multiple imports of the same file. If you are using it, your custom LessSource should implement it equals and hashCode.

@SomMeri
Copy link
Owner

SomMeri commented Jan 6, 2014

Closing this as "answered". If you disagree, please re-open the issue again.

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