Skip to content

Instantly share code, notes, and snippets.

@pfig
Created March 3, 2012 23:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfig/1969062 to your computer and use it in GitHub Desktop.
Save pfig/1969062 to your computer and use it in GitHub Desktop.
Rake task to compile Less to CSS
require 'rubygems'
require 'less'
require 'rake'
SOURCE = "."
LESS = File.join( SOURCE, "path", "to", "less", "files" )
CONFIG = {
'less' => File.join( LESS, "less" ),
'css' => File.join( LESS, "css" ),
'input' => "style.less",
'output' => "style.css"
}
desc "Compile Less"
task :lessc do
less = CONFIG['less']
input = File.join( less, CONFIG['input'] )
output = File.join( CONFIG['css'], CONFIG['output'] )
source = File.open( input, "r" ).read
parser = Less::Parser.new( :paths => [less] )
tree = parser.parse( source )
File.open( output, "w+" ) do |f|
f.puts tree.to_css( :compress => true )
end
end # task :lessc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment