Thursday,
5 Nov 2009
LESS for Java
LESS is a cool project that has been around for a while and extends CSS with a few nice features like variables, mixins, operations and nested rules. The best thing about it is the syntax that feels very natural and easy to learn. I was eager to play with LESS but the main stopper for me was the fact that it is written in Ruby and I'm mostly involved in pure Java projects. It seems that my desire to try it was really strong because I sat down and lost almost a weekend in learning how JRuby works and finally produced a working prototype that only requires the Java 5 Virtual Machine. Over the last two months I was able to totally reorganize, extend and test the code base and I'm now finally glad to release it officially.
LESS for Java is a set of 2 modules that primarily target Maven 2 compatible projects but can also be used in any Java enabled environment:
- LESS Engine contains the original LESS codebase and provides a straightforward access to the underlying API. It has been designed as a core module that can be used various scenarios.
- LESS Servlet automatically compiles and serves LESS sources but also supports other resources like image and script files. It optimizes the server response by adding appropriate headers and applying the YUI Compressor for both CSS and JavaScript requests.
Both modules are already available on the official Maven 2 repository and you can start playing with them immediately. The current 1.2.11 version matches the snapshot of the original LESS distribution that has been used. The project has been successfully utilized on this website as well as in a bigger project built around Spring MVC and JSF. The source is available on GitHub where we're planning to put all our new open source stuff. Comments and feedback are welcome.
Comments:
The initialization of the JRuby engine is slow but after that you can compile CSS at fairly good speed. Have you tried that? I'm also processing files at runtime and I have put various optimization efforts in the LESS Servlet module. You can get some more info from this thread.
It's great to see the dependency on the original Ruby project rather than trying to write it from scratch ... makes it a lot easier.
Be well.