less-rb allows you to compile Less CSS files from Ruby.
To install:
gem install less-rb
To use:
require 'less-rb'
Less::Parser.compile("body { background: darken(#CCC, 10%) }")
These bindings also integrate with Tilt and Sprockets, so work seamlessly with Rails.
Node.js needs to be installed, and in the path.
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.
less-rb exposes the less.Parser
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 AST !
tree = parser.parse(".class {width: 1+1}") # => Less::Tree
tree.to_css #=> .class {\n width: 2;\n}\n
tree.to_css(:compress => true) #=> .class{width:2;}
There's a shortcut for this whole routine:
Less::Parser.compile(css, options)
This library was ported from less.rb also using the Apache License. It was created by Alex MacCaw (@maccman).