Created
September 29, 2010 13:05
-
-
Save samullen/602710 to your computer and use it in GitHub Desktop.
Rails to Static site generation and deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :buildout do | |
#----------------------------------------------------------------------------# | |
desc "Mirror the dynamic site into Rails.env/out" | |
task :mirror do | |
outdir = File.join(Rails.root, "out") | |
Dir.mkdir(outdir) unless (File.exist?(outdir) && File.directory?(outdir)) | |
Dir.chdir(outdir) do | |
`wget -m -nH http://localhost:3000` | |
end | |
Find.find(outdir) do |path| | |
filedir = File.dirname(path) | |
filename = File.basename(path) | |
if File.directory?(path) | |
Find.prune if File.basename(path)[0] == ?. | |
next | |
end | |
if path.match(/\?\d+$/) | |
File.unlink(path) | |
elsif File.extname(filename).empty? | |
File.rename(path, "#{filedir}/#{filename}.html") | |
end | |
end | |
`rsync -ruv --exclude=.svn/ --exclude=dispatch* --exclude=500.html --exclude=422.html public/ out/` | |
end | |
#----------------------------------------------------------------------------# | |
desc "Deploy static files to the remote host" | |
task :deploy => :environment do | |
outdir = File.join(Rails.root, "out") | |
Dir.chdir(outdir) do | |
`ncftpput -u #{Settings.ftp_uname} -p #{Settings.ftp_passwd} -R #{Settings.ftp_host} #{Settings.ftp_path} .` | |
end | |
end | |
#----------------------------------------------------------------------------# | |
desc "Create static site and deploy" | |
task :mirror_deploy => [:mirror, :deploy] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment