diff options
author | nullkal <nullkal@nil.nu> | 2017-09-26 18:55:33 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-09-26 11:55:33 +0200 |
commit | b32a1d575469aeb3d74da93d861b77df55715e1b (patch) | |
tree | 9d6c4018bccbdf201a8a605e25e47f9d3a78ccec | |
parent | 9d53a38a44f3a7b7685dbaa0bc9e607928d8043e (diff) |
Refactor 500 file generation for future extension (#5105)
-rw-r--r-- | lib/tasks/assets.rake | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 2ef72fdef..92d5aea80 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -1,18 +1,22 @@ # frozen_string_literal: true +def render_static_page(action, dest:, **opts) + I18n.with_locale(ENV['DEFAULT_LOCALE'] || I18n.default_locale) do + html = ApplicationController.render(action, opts) + File.write(dest, html) + end +end + namespace :assets do - desc 'Generate 500.html' - task :generate_500 do - I18n.with_locale(ENV['DEFAULT_LOCALE'] || I18n.default_locale) do - html = ApplicationController.render('errors/500', layout: 'error') - File.write(Rails.root.join('public', '500.html'), html) - end + desc 'Generate static pages' + task :generate_static_pages do + render_static_page 'errors/500', layout: 'error', dest: Rails.root.join('public', '500.html') end end if Rake::Task.task_defined?('assets:precompile') Rake::Task['assets:precompile'].enhance do Webpacker::Manifest.load - Rake::Task['assets:generate_500'].invoke + Rake::Task['assets:generate_static_pages'].invoke end end |