Skip to content

Instantly share code, notes, and snippets.

@route
Created May 5, 2012 10:45
Show Gist options
  • Save route/2601441 to your computer and use it in GitHub Desktop.
Save route/2601441 to your computer and use it in GitHub Desktop.
Static page generator
namespace :app do
namespace :error_pages do
desc "Generates static pages 500, 403, 404, 422"
task :generate => :environment do
av = ActionView::Base.new
av.class_eval do
include ApplicationHelper
include Rails.application.routes.url_helpers
end
file = Rails.root.join("app", "views", "layouts", "error_page.html.haml")
[500, 403, 404, 422].each do |code|
puts "Generate public/#{code}.html"
page = File.join(Rails.public_path, "#{code}.html")
File.open(page, "w") do |output|
output.write av.render(file: file, locals: {code: code})
end
end
end
end
end
@rimidl
Copy link

rimidl commented May 5, 2012

Прикольно придумал!

Только, есть мнение по улучшению кода ;)

 namespace :app do
  namespace :error_pages do
    desc "Generates static pages 500, 404, 422"
    task :generate => :environment do
     av = ActionView::Base.new
      av.class_eval do
        include ApplicationHelper
        include Rails.application.routes.url_helpers
      end

      file = Rails.root.join("app", "views", "layouts", "error_page.html.haml")

      [500, 403, 404, 422].each do |code|
        puts "Generate public/#{code}.html"
        File.open(File.join(Rails.public_path, "#{code}.html"), "w") do |output|
          output.write av.render(file: file, locals: {code: code})
        end
      end

    end
  end
end

@route
Copy link
Author

route commented May 5, 2012

+1, updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment