Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
Created October 17, 2012 03:30
Show Gist options
  • Save snipsnipsnip/3903553 to your computer and use it in GitHub Desktop.
Save snipsnipsnip/3903553 to your computer and use it in GitHub Desktop.
Desugaring rakefile (.sass => .css, .coffee => .js, .slim => .html)
require 'tilt'
require 'slim'
require 'sass'
require 'rake/clean'
@tilts = {}
def tilt_rule(to, from, options={})
@tilts[from] = to
rule to => from do |task|
template = Tilt.new(task.source)
template.options.merge(options)
result = template.render
open(task.name, 'wb') {|f| f << result }
end
end
def desugared_files
@desugared_files ||= FileList.new do |list|
@tilts.each {|from, to| list.include FileList["**/*#{from}"].ext(to) }
end
end
tilt_rule '.html', '.slim', {:format => :html5, :pretty => true}
tilt_rule '.css', '.sass'
tilt_rule '.js', '.coffee'
CLEAN.include desugared_files
desc "desugar all files (#{@tilts.map {|k,v| "#{k}=>#{v}" }.join(',')})"
task 'desugar' => desugared_files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment