Created
June 23, 2011 00:06
-
-
Save sc0ttman/1041602 to your computer and use it in GitHub Desktop.
Export static pages
This file contains hidden or 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 :static do | |
desc 'Generate static html files of all views in the pages folder' | |
#usage: rake static:generate | |
task :generate do | |
# note: add these gems to your gemfile: | |
# gem "nokogiri" | |
# gem "rest-open-uri","1.0.0" | |
puts "generating..." | |
views = Dir.new("#{::Rails.root.to_s}/app/views/pages").entries | |
views.each do |view| | |
url = view.gsub(".html.erb","") | |
unless (url == "." || url == ".." || url[0,1]=="_") | |
puts url | |
File.open("#{::Rails.root.to_s}/public/static_files/#{url}.html", "w") { |f| f.write Nokogiri::HTML(open("http://localhost:3000/#{url}")) } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basically, I needed a way to generate static HTML files from the pages controller. I couldn't get
`````` ActionDispatch::Integration::Session.new(Rails.application)
stuff to work, so I just used nokogiri on my development server. Also, the only route I had was:
match ':action' => 'pages#:action.html' ```