asual / lesscss-engine

LESS Engine - A Java wrapper for less.js
http://www.asual.com/lesscss
Apache License 2.0
221 stars 66 forks source link

@import in relation to JSF #21

Open dabloem opened 12 years ago

dabloem commented 12 years ago

Hi, this is not really an issue/bug. But rather a question how to proceed.

I created a resourceHandler for JSF 2 to process/serve less files. The LessResource is accountable for serving up the compiled less resource. When using the @import directive, the engine is unable to find the file. This sounds logical, how could the LessEngine know where to find the imported resource? The error is the following: com.asual.lesscss.LessException: org.mozilla.javascript.EcmaError: TypeError: Cannot call method "replace" of undefined (/../META-INF/less.js#2517) at com.asual.lesscss.LessEngine.parseLessException(LessEngine.java:188)

Question, what is the best approach to include an imported file.

Regards, Duncan

asual commented 12 years ago

It should be able to resolve a relative path or a classpath resource. There are various related changes in the current development version so it will be good if you can build the 1.1.5-SNAPSHOT locally and try it. You can also check the tests for a reference.

alexo commented 12 years ago

I'm not sure how this can be solved in lesscss-engine context, but I can describe the solution I use in wro4j which provides a class called LessCssProcessor (similar to lesscss-engine). In order to solve the @import directive, before the LessCssProcessor is applied, another preProcessor is used (called CssImportPreProcessor) which is responsible for @import statement handling. As a result, the LessCssProcessor is applied on the entire lesscss content, rather than just on the resource containing the @import statement.

Not sure if this helps you, but at least you can try a similar approach.

Cheers, Alex

dabloem commented 12 years ago

@asual , I built the app with latest 1.1.5-snapshot. The error changed a bit. as shown: org.mozilla.javascript.WrappedException: Wrapped java.io.FileNotFoundException: File not found: setting.less (/j../META-INF/less.js#2426) at com.asual.lesscss.LessEngine.parseLessException(LessEngine.java:188) The setting.less file was placed at WEB-INF/setting.less

@alexo , thanks for the suggestion. I was thinking of a similar solution. I will take a look at it and post my findings...

asual commented 12 years ago

Are you testing this against two files which are both located in WEB-INF? In general it should work but probably JSF introduces something specific. It seems that I can only fix this if I have a sample project or test case. Alternatively you can try putting a print() tracing in the engine.js function and see if it can show you where the engine is actually looking for the file.

tine2k commented 12 years ago

Hey Duncan, I am looking for exactly that: an integration of LessCss in JSF. Can you provide the sourcecode of your Resourcehandler somehow? Thanks Martin

asual commented 12 years ago

Duncan's code is already on GitHub: https://github.com/dabloem/jsf-less-resourcehandler

I'm using this project with JSF but I configure it as a separate servlet: https://github.com/asual/lesscss-servlet

NikNik77771 commented 12 years ago

Finally is problem of imports resolved?

rkrzewski commented 11 years ago

I believe the server side includes for JSF can be easily implemented using the changes introduced by my earlier contribution: https://github.com/asual/lesscss-engine/pull/32

What's need to be done: