-
-
Save westonganger/b225e4a7c8c3498cb71dcd645fb5fe38 to your computer and use it in GitHub Desktop.
Generate Static HTML Website Using Ruby on Rails
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
# config/environments/static.rb | |
require File.expand_path('../development', __FILE__) | |
# environment for serving static pages like error pages to upload to S3 | |
MyApp::Application.configure do | |
config.serve_static_assets = true | |
# Compress JavaScripts and CSS | |
config.assets.compress = true | |
# Don't fallback to assets pipeline if a precompiled asset is missed | |
config.assets.compile = false | |
# Generate digests for assets URLs | |
config.assets.digest = true | |
end |
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
wget_cmd = "wget -mnH --no-parent -e robots=off --adjust-extension --convert-links" | |
# Original idea from http://blog.atlashost.eu/post/ruby-on-rails-a-static-site-generator.html | |
namespace :static do | |
desc 'Generate static site in ./out/ directory' | |
task :generate => [ | |
'assets:clean', | |
'assets:precompile', | |
:start_rails_server | |
] do | |
Dir.mkdir 'out' unless File.exist? 'out' | |
Dir.chdir 'out' do | |
`#{wget_cmd} http://localhost:3000/` | |
end | |
`rsync -ruv --exclude=.svn/ public/ out/` | |
# stop the server when we're done | |
Rake::Task['static:stop_rails_server'].reenable | |
Rake::Task['static:stop_rails_server'].invoke | |
# don't need to keep assets since we deploy to Heroku | |
Rake::Task['assets:clobber'].reenable | |
Rake::Task['assets:clobber'].invoke | |
end | |
desc 'only generates the static error page we need for Heroku' | |
task :generate_error_page => [ | |
'assets:clean', | |
'assets:precompile', | |
:start_rails_server | |
] do | |
Dir.mkdir 'out_error' unless File.exist? 'out_error' | |
Dir.chdir 'out_error' do | |
`#{wget_cmd} http://localhost:3000/exceptions/400.html` | |
end | |
`rsync -ruv --exclude=.svn/ public/ out_error/` | |
# stop the server when we're done | |
Rake::Task['static:stop_rails_server'].reenable | |
Rake::Task['static:stop_rails_server'].invoke | |
# don't need to keep assets since we deploy to Heroku | |
Rake::Task['assets:clobber'].reenable | |
Rake::Task['assets:clobber'].invoke | |
end | |
end |
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
# config/database.yml | |
development: &development | |
adapter: postgresql | |
database: my_app_development | |
host: localhost | |
username: postgres | |
password: | |
static: | |
<<: *development |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment