Skip to content

Instantly share code, notes, and snippets.

@samullen
Created September 29, 2010 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samullen/602710 to your computer and use it in GitHub Desktop.
Save samullen/602710 to your computer and use it in GitHub Desktop.
Rails to Static site generation and deployment
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