less-execjs
less-execjs allows you to compile Less CSS files from Ruby.
To install:
gem install less-execjs
To use:
require 'less-execjs'
Less::Parser.compile("body { background: darken(#CCC, 10%) }")
These bindings also integrate with Tilt and Sprockets, so work seamlessly with Rails.
Requirements
Node.js needs to be installed, and in the path.
About
These are Ruby bindings for the next generation LESS, which is implemented in JavaScript.
These are separate from the official bindings, as they've been ported to ExecJS. This means you don't have to re-compile v8 every deploy.
For more information, visit http://lesscss.org.
Usage
less-execjs exposes the less.render constructor to ruby code via Less::Parser. You can instate it
context free:
parser = Less::Parser.new
or with configuration options:
parser = Less::Parser.new :paths => ['./lib', 'other/lib'], :filename => 'mystyles.less'
Once you have a parser instantiated, you can parse code to get your CSS
result = parser.parse(".class {width: 1+1}") # => Less::Result
result.to_css #=> .class {\n width: 2;\n}\n
parser.parse(".class {width: 1+1}", :compress => true).to_css #=> .class{width:2;}
There's a shortcut for this whole routine:
Less::Parser.compile(css, )
Custom functions
You can load in custom functions for less by supplying the :custom_functions option with a path to a JS file. Your JS file must export a function with the signature of registerCustomFunctions(less, functionRegistry) which you can then use to add the custom functions to the less compiler using functionRegistry.add[Multiple].
Credits
This library was ported from less.rb also using the Apache License. It was created by Alex MacCaw (@maccman).