Refactor 500 file generation for future extension (#5105)
This commit is contained in:
		@@ -1,18 +1,22 @@
 | 
				
			|||||||
# frozen_string_literal: true
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace :assets do
 | 
					def render_static_page(action, dest:, **opts)
 | 
				
			||||||
  desc 'Generate 500.html'
 | 
					 | 
				
			||||||
  task :generate_500 do
 | 
					 | 
				
			||||||
  I18n.with_locale(ENV['DEFAULT_LOCALE'] || I18n.default_locale) do
 | 
					  I18n.with_locale(ENV['DEFAULT_LOCALE'] || I18n.default_locale) do
 | 
				
			||||||
      html = ApplicationController.render('errors/500', layout: 'error')
 | 
					    html = ApplicationController.render(action, opts)
 | 
				
			||||||
      File.write(Rails.root.join('public', '500.html'), html)
 | 
					    File.write(dest, html)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace :assets do
 | 
				
			||||||
 | 
					  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
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if Rake::Task.task_defined?('assets:precompile')
 | 
					if Rake::Task.task_defined?('assets:precompile')
 | 
				
			||||||
  Rake::Task['assets:precompile'].enhance do
 | 
					  Rake::Task['assets:precompile'].enhance do
 | 
				
			||||||
    Webpacker::Manifest.load
 | 
					    Webpacker::Manifest.load
 | 
				
			||||||
    Rake::Task['assets:generate_500'].invoke
 | 
					    Rake::Task['assets:generate_static_pages'].invoke
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user