Skip to content

Instantly share code, notes, and snippets.

@mniebling mniebling/Rakefile
Last active Aug 29, 2015

What would you like to do?
Rake task to compile LESS to CSS (Heavily commented)
# Include Ruby modules
require 'rubygems'
require 'less'
require 'rake'
# The base path for the website
# Other options
# The folder where all the LESS files are located
:less_folder => File.join( SITE_ROOT, "web", "less" ),
# The main less file should use @imports to pull in any others
# b/c the compile_less task only takes one input file
:less_file => File.join( SITE_ROOT, "web", "less", "~main.less" ),
# The site's compiled CSS file
:css_file => File.join( SITE_ROOT, "web", "compiled.css")
# Tasks
# --------------------
desc "Compile LESS master to CSS output file"
task :compile_less do
puts "\n"
print "Compiling LESS... "
# Set up the parser & do the compilation
source = CONFIG[:less_file], "r" ).read
parser = :paths => [CONFIG[:less_folder]] )
tree = parser.parse( source )
# Write the parsed stuff to the output CSS file CONFIG[:css_file], "w+" ) do |f|
# :compress => true removes spaces/breaks
f.puts tree.to_css( :compress => false )
puts "done!"
puts "\n"
end # task :compile_less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.