forked from diaspora/diaspora
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate error pages on assets:precompile
This allows us to reuse any CSS we have, unify their look and unify their look with the regular page design. This works by instantiating ActionView and rendering templates in a rake task. Inspired by the errgent gem.
- Loading branch information
Showing
19 changed files
with
193 additions
and
145 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
- content_for(:page_title) do | ||
The page you were looking for doesn't exist (404) | ||
|
||
#big-number.transparent | ||
404 | ||
%p | ||
These are not the kittens you're looking for. Move along. | ||
%p | ||
%a{href: "javascript:history.back()"} | ||
Go Back? |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- content_for(:page_title) do | ||
The change you wanted was rejected (422) | ||
|
||
.dialog | ||
%h1 | ||
The change you wanted was rejected. | ||
%p | ||
Maybe you tried to change something you didn't have access to. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
- content_for(:page_title) do | ||
We're sorry, but something went wrong (500) | ||
|
||
%header | ||
= image_tag "branding/white2x.png", id: "diaspora_logo" | ||
|
||
%h1 | ||
500: Internal server error. | ||
%h3 | ||
Our bad! Sorry about that. :( |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
!!! | ||
%html | ||
%head | ||
%title= page_title yield(:page_title) | ||
|
||
%link{rel: "shortcut icon", href: image_path("favicon.png")} | ||
%link{rel: "apple-touch-icon", href: image_path("apple-touch-icon.png")} | ||
= stylesheet_link_tag :error_pages, media: "all" | ||
= yield(:head) | ||
%body{id: "error_#{@code}"} | ||
= yield |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Inspired by https://github.com/route/errgent/blob/master/lib/errgent/renderer.rb | ||
class ErrorPageRenderer | ||
def initialize options={} | ||
@codes = options.fetch :codes, [404, 500] | ||
@output = options.fetch :output, "public/%s.html" | ||
@vars = options.fetch :vars, {} | ||
@template = options.fetch :template, "errors/error_%s" | ||
@layout = options.fetch :layout, "layouts/error_page" | ||
end | ||
|
||
def render | ||
@codes.each do |code| | ||
view = build_action_view | ||
view.assign @vars.merge(code: code) | ||
path = Rails.root.join(@output % code) | ||
File.write path, view.render(template: @template % code, layout: @layout) | ||
end | ||
end | ||
|
||
def helpers(&block) | ||
@helpers = block | ||
end | ||
|
||
private | ||
|
||
def build_action_view | ||
paths = ::ActionController::Base.view_paths | ||
::ActionView::Base.new(paths).tap do |view| | ||
view.class_eval do | ||
include Rails.application.helpers | ||
include Rails.application.routes.url_helpers | ||
end | ||
view.assets_manifest = build_manifest(Rails.application) | ||
view.class_eval(&@helpers) if @helpers | ||
end | ||
end | ||
|
||
# Internal API from the sprocket-rails railtie, if somebody finds a way to | ||
# call it, please replace it. Might need to be updated on sprocket-rails | ||
# updates. | ||
def build_manifest(app) | ||
config = app.config | ||
path = File.join(config.paths['public'].first, config.assets.prefix) | ||
Sprockets::Manifest.new(app.assets, path, config.assets.manifest) | ||
end | ||
end | ||
|
||
namespace :assets do | ||
desc "Generate error pages" | ||
task :generate_error_pages do | ||
renderer = ErrorPageRenderer.new codes: [404, 422, 500] | ||
renderer.render | ||
end | ||
|
||
# Augment precompile with error page generation | ||
task :precompile do | ||
Rake::Task['assets:generate_error_pages'].invoke | ||
end | ||
end |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.