Skip to content

Instantly share code, notes, and snippets.

@mysteriouspants
Created September 21, 2012 15:45
Show Gist options
  • Save mysteriouspants/3762257 to your computer and use it in GitHub Desktop.
Save mysteriouspants/3762257 to your computer and use it in GitHub Desktop.
My blog's Rakefile
HOOLIGAN_STYLES={
'themes/hooligan/stylesheets/_sass/style.scss' => 'themes/hooligan/stylesheets/css/style.css'
}
module Rake
class Task
def has_dependency? task, inspected_tasks=[]
task= Rake::Task[task] if task.class != Rake::Task
return true if self == task
return false if inspected_tasks.include? self
inspected_tasks<< self
return prerequisite_tasks.collect{|_task|
_task.has_dependency? task, inspected_tasks
}.include? true
end
end
end
# prod is defined as being uploaded to the server
def is_prod?
Rake.application.top_level_tasks.collect{|s|
Rake::Task[s].has_dependency?(:upload)
}.include?(true) or ENV['MINIFY'] == 'true'
end
desc 'Regenerate theme CSS files'
task :hooligan do
HOOLIGAN_STYLES.each do |sass,css|
system "sass #{'-t compressed' if is_prod?} --compass #{sass} #{css}"
end
end
desc 'Build that stuff'
task :build => :hooligan do
system "ruhoh compile"
cp 'media/favicon.ico', 'compiled/favicon.ico'
end
desc 'Upload this stuff to da servah'
task :upload do
system "rsync -avzh --delete --chmod=o=rx,g=rwx,u=rwx compiled/ fsdev.net:~/nserror.me/www/"
end
desc 'Spin up a local server to do some rapid edit/preview junk'
task :preview => :hooligan do
pids=[
Process.spawn("rackup -p 4000"),
Process.spawn("sass --compass --watch #{HOOLIGAN_STYLES.collect{|k,v|"#{k}:#{v}"}.join(' ')}")
]
trap("INT") {
pids.each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
pids.each { |pid| Process.wait(pid) }
end
task :default => [:build,:upload]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment