Skip to content

Instantly share code, notes, and snippets.

@WattsInABox
Last active July 5, 2024 09:36

Revisions

  1. WattsInABox revised this gist Feb 7, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion generate_static_error_pages.rake
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ namespace :static do

    desc 'Stop Rails server'
    task :stop_rails_server do
    `cat tmp/pids/server | xargs -I {} kill {}`
    `cat tmp/pids/server.pid | xargs -I {} kill {}`
    end

    desc 'Start a server using heel on port 8000 that will server our static site'
  2. WattsInABox revised this gist Feb 7, 2014. 1 changed file with 18 additions and 4 deletions.
    22 changes: 18 additions & 4 deletions generate_static_error_pages.rake
    Original file line number Diff line number Diff line change
    @@ -5,28 +5,42 @@ namespace :static do
    task :generate => [
    'assets:clean',
    'assets:precompile',
    :start_rails_server,
    :stop_rails_server
    :start_rails_server
    ] do
    Dir.mkdir 'out' unless File.exist? 'out'
    Dir.chdir 'out' do
    `wget -mnH 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,
    :stop_rails_server
    :start_rails_server
    ] do
    Dir.mkdir 'out_error' unless File.exist? 'out_error'
    Dir.chdir 'out_error' do
    `wget -mnH 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

    desc 'Start a Rails server in the static Rails.env on port 3000'
  3. WattsInABox revised this gist Jan 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion generate_static_error_pages.rake
    Original file line number Diff line number Diff line change
    @@ -50,6 +50,6 @@ namespace :static do

    desc 'Stop the static server that is running using heel'
    task :stop_static_server do
    `heel --kill`
    `heel --kill --port 8000`
    end
    end
  4. WattsInABox revised this gist Jan 25, 2014. 1 changed file with 23 additions and 10 deletions.
    33 changes: 23 additions & 10 deletions generate_static_error_pages.rake
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    # lib/tasks/generate_static_error_pages.rb
    # Original idea from http://blog.atlashost.eu/post/ruby-on-rails-a-static-site-generator.html
    namespace :static do
    @@ -11,26 +10,40 @@ namespace :static do
    ] do
    Dir.mkdir 'out' unless File.exist? 'out'
    Dir.chdir 'out' do
    `wget -mnH http://localhost:3001/`
    `wget -mnH http://localhost:3000/`
    end
    `rsync -ruv --exclude=.svn/ public/ out/`
    end

    desc 'Start a Rails server in the static Rails.env on port 3001'
    desc 'only generates the static error page we need for Heroku'
    task :generate_error_page => [
    'assets:clean',
    'assets:precompile',
    :start_rails_server,
    :stop_rails_server
    ] do
    Dir.mkdir 'out_error' unless File.exist? 'out_error'
    Dir.chdir 'out_error' do
    `wget -mnH http://localhost:3000/exceptions/400.html`
    end
    `rsync -ruv --exclude=.svn/ public/ out_error/`
    end

    desc 'Start a Rails server in the static Rails.env on port 3000'
    task :start_rails_server do
    # run on 3001 in case we're already running a server on 3000
    `RAILS_ENV=static rails s -p 3001 -d`
    `RAILS_ENV=static rails s -p 3000 -d`
    end

    desc 'Stop any process running on port 3001'
    desc 'Stop Rails server'
    task :stop_rails_server do
    # hopefully it is the Rails server that is runing in the static Rails.env
    `lsof -i :3001 | awk '{print $2}' | grep -v PID | xargs -I {} kill {}`
    `cat tmp/pids/server | xargs -I {} kill {}`
    end

    desc 'Start a server using heel on port 8000 that will server our static site'
    task :start_static_server do
    Dir.chdir 'out' do
    task :start_static_server, :directory do |t, args|
    directory = args[:directory] || 'out'

    Dir.chdir directory do
    `heel --daemonize --port 8000`
    end
    end
  5. WattsInABox revised this gist Jan 25, 2014. 2 changed files with 44 additions and 2 deletions.
    2 changes: 2 additions & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    # Ignore static version of the site (used to upload error pages to S3 for Heroku errors)
    /out
    44 changes: 42 additions & 2 deletions generate_static_error_pages.rake
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,42 @@
    # Ignore static version of the site (used to upload error pages to S3 for Heroku errors)
    /out

    # lib/tasks/generate_static_error_pages.rb
    # 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,
    :stop_rails_server
    ] do
    Dir.mkdir 'out' unless File.exist? 'out'
    Dir.chdir 'out' do
    `wget -mnH http://localhost:3001/`
    end
    `rsync -ruv --exclude=.svn/ public/ out/`
    end

    desc 'Start a Rails server in the static Rails.env on port 3001'
    task :start_rails_server do
    # run on 3001 in case we're already running a server on 3000
    `RAILS_ENV=static rails s -p 3001 -d`
    end

    desc 'Stop any process running on port 3001'
    task :stop_rails_server do
    # hopefully it is the Rails server that is runing in the static Rails.env
    `lsof -i :3001 | awk '{print $2}' | grep -v PID | xargs -I {} kill {}`
    end

    desc 'Start a server using heel on port 8000 that will server our static site'
    task :start_static_server do
    Dir.chdir 'out' do
    `heel --daemonize --port 8000`
    end
    end

    desc 'Stop the static server that is running using heel'
    task :stop_static_server do
    `heel --kill`
    end
    end
  6. WattsInABox revised this gist Jan 25, 2014. 2 changed files with 2 additions and 43 deletions.
    2 changes: 0 additions & 2 deletions .gitignor
    Original file line number Diff line number Diff line change
    @@ -1,2 +0,0 @@
    # Ignore static version of the site (used to upload error pages to S3 for Heroku errors)
    /out
    43 changes: 2 additions & 41 deletions generate_static_error_pages.rake
    Original file line number Diff line number Diff line change
    @@ -1,41 +1,2 @@
    # lib/tasks/generate_static_error_pages.rb
    # 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,
    :stop_rails_server
    ] do
    Dir.mkdir 'out' unless File.exist? 'out'
    Dir.chdir 'out' do
    `wget -mnH http://localhost:3001/`
    end
    `rsync -ruv --exclude=.svn/ public/ out/`
    end

    desc 'Start a Rails server in the static Rails.env on port 3001'
    task :start_rails_server do
    # run on 3001 in case we're already running a server on 3000
    `RAILS_ENV=static rails s -p 3001 -d`
    end

    desc 'Stop any process running on port 3001'
    task :stop_rails_server do
    # hopefully it is the Rails server that is runing in the static Rails.env
    `lsof -i :3001 | awk '{print $2}' | grep -v PID | xargs -I {} kill {}`
    end

    desc 'Start a server using heel on port 8000 that will server our static site'
    task :start_static_server do
    Dir.chdir 'out' do
    `heel --daemonize --port 8000`
    end
    end

    desc 'Stop the static server that is running using heel'
    task :stop_static_server do
    `heel --kill`
    end
    end
    # Ignore static version of the site (used to upload error pages to S3 for Heroku errors)
    /out
  7. WattsInABox renamed this gist Jan 25, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. WattsInABox revised this gist Jan 25, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    f
  9. WattsInABox created this gist Jan 25, 2014.
    2 changes: 2 additions & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    # Ignore static version of the site (used to upload error pages to S3 for Heroku errors)
    /out
    3 changes: 3 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    group :development do
    gem 'heel' # used to server the static site from the /out directory
    end
    10 changes: 10 additions & 0 deletions database.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # config/database.yml
    development: &development
    adapter: postgresql
    database: workherder_development
    host: localhost
    username: postgres
    password:

    static:
    <<: *development
    41 changes: 41 additions & 0 deletions generate_static_error_pages.rake
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    # lib/tasks/generate_static_error_pages.rb
    # 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,
    :stop_rails_server
    ] do
    Dir.mkdir 'out' unless File.exist? 'out'
    Dir.chdir 'out' do
    `wget -mnH http://localhost:3001/`
    end
    `rsync -ruv --exclude=.svn/ public/ out/`
    end

    desc 'Start a Rails server in the static Rails.env on port 3001'
    task :start_rails_server do
    # run on 3001 in case we're already running a server on 3000
    `RAILS_ENV=static rails s -p 3001 -d`
    end

    desc 'Stop any process running on port 3001'
    task :stop_rails_server do
    # hopefully it is the Rails server that is runing in the static Rails.env
    `lsof -i :3001 | awk '{print $2}' | grep -v PID | xargs -I {} kill {}`
    end

    desc 'Start a server using heel on port 8000 that will server our static site'
    task :start_static_server do
    Dir.chdir 'out' do
    `heel --daemonize --port 8000`
    end
    end

    desc 'Stop the static server that is running using heel'
    task :stop_static_server do
    `heel --kill`
    end
    end
    1 change: 1 addition & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    f
    15 changes: 15 additions & 0 deletions static.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # config/environments/static.rb
    require File.expand_path('../development', __FILE__)
    # environment for serving static pages like error pages to upload to S3
    Workherder::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