namespace :static do
desc "Generate static pages for home controller"
task :generate => :environment do
methods = HomeController.new.methods - ApplicationController.new.methods - ['index']
methods.each do |action|
system "rm #{RAILS_ROOT}/public/#{action}.html"
system "wget http://#{SERVER_HOST}/#{action}.html -O #{RAILS_ROOT}/public/_#{action}.html -o /dev/null"
system "mv #{RAILS_ROOT}/public/_#{action}.html #{RAILS_ROOT}/public/#{action}.html"
p "#{action}.html"
end
end
end
Refactorings
No refactoring yet !
andyjeffries
July 22, 2009, July 22, 2009 12:18, permalink
I've only refactored out the wget/system calls and it's untested - but something like that should work...
require 'net/http'
namespace :static do
desc "Generate static pages for home controller"
task :generate => :environment do
methods = HomeController.new.methods - ApplicationController.new.methods - ['index']
methods.each do |action|
File.unlink "#{RAILS_ROOT}/public/#{action}.html"
File.open("#{RAILS_ROOT}/public/#{action}.html", "w") do |f|
res = Net::HTTP.start(SERVER_HOST, 80) {|http| http.get("/#{action}.html") }
f << res.body
end
p "#{action}.html"
end
end
end
I would like to make this without "wget", but don't know how to get response