-
Notifications
You must be signed in to change notification settings - Fork 129
Improve display of 404 pages #572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
27 changes: 27 additions & 0 deletions
27
lib/generators/pageflow/error_pages/error_pages_generator.rb
This file contains hidden or 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,27 @@ | ||
require 'rails/generators' | ||
|
||
module Pageflow | ||
module Generators | ||
class ErrorPagesGenerator < Rails::Generators::Base | ||
desc 'Generate error pages.' | ||
|
||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
def create_not_found | ||
copy_file '404.html', 'public/pageflow/error_pages/404.html' | ||
end | ||
|
||
def copy_fonts | ||
directory 'fonts', 'public/pageflow/error_pages/fonts' | ||
end | ||
|
||
def copy_stylesheets | ||
directory 'stylesheets', 'public/pageflow/error_pages/stylesheets' | ||
end | ||
|
||
def copy_images | ||
directory 'images', 'public/pageflow/error_pages/images' | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or 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,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<title>Not Found (404)</title> | ||
<link rel="stylesheet" type="text/css" href="/pageflow/error_pages/stylesheets/main.css" /> | ||
</head> | ||
|
||
<body> | ||
<div> | ||
<h1>Not Found</h1> | ||
<p>The page you've requested cannot be found.</p> | ||
</div> | ||
</body> | ||
</html> |
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
40 changes: 40 additions & 0 deletions
40
lib/generators/pageflow/error_pages/templates/stylesheets/main.css
This file contains hidden or 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,40 @@ | ||
@font-face { | ||
font-family: SourceSansPro; | ||
font-weight: normal; | ||
font-style: normal; | ||
src: url(/pageflow/error_pages/fonts/sourcesanspro-regular-webfont.eot); | ||
src: url(/pageflow/error_pages/fonts/sourcesanspro-regular-webfont.eot?#iefix) format("embedded-opentype"), url(/pageflow/error_pages/fonts/sourcesanspro-regular-webfont.woff) format("woff"), url(/pageflow/error_pages/fonts/sourcesanspro-regular-webfont.ttf) format("truetype"), url(/pageflow/error_pages/fonts/sourcesanspro-regular-webfont.svg#SourceSansPro) format("svg"); | ||
} | ||
|
||
@font-face { | ||
font-family: SourceSansPro; | ||
font-weight: bold; | ||
font-style: normal; | ||
src: url(/pageflow/error_pages/fonts/sourcesanspro-bold-webfont.eot); | ||
src: url(/pageflow/error_pages/fonts/sourcesanspro-bold-webfont.eot?#iefix) format("embedded-opentype"), url(/pageflow/error_pages/fonts/sourcesanspro-bold-webfont.woff) format("woff"), url(/pageflow/error_pages/fonts/sourcesanspro-bold-webfont.ttf) format("truetype"), url(/pageflow/error_pages/fonts/sourcesanspro-bold-webfont.svg#SourceSansPro) format("svg"); | ||
} | ||
|
||
html { | ||
background-color: #252526; | ||
background-image: url('/pageflow/error_pages/images/bg.jpg'); | ||
background-repeat: no-repeat; | ||
background-position: center center; | ||
height: 100%; | ||
} | ||
|
||
body { | ||
font-size: 21px; | ||
color: #fff; | ||
font-family: "SourceSansPro"; | ||
} | ||
|
||
div { | ||
position: absolute; | ||
top: 30%; | ||
left: 30%; | ||
max-width: 500px; | ||
} | ||
|
||
a { | ||
color: #fff; | ||
} |
This file contains hidden or 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.
45 changes: 45 additions & 0 deletions
45
spec/generators/pageflow/error_pages/error_pages_generator_spec.rb
This file contains hidden or 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,45 @@ | ||
require 'spec_helper' | ||
require 'support/shared_contexts/generator' | ||
require 'generators/pageflow/error_pages/error_pages_generator' | ||
|
||
module Pageflow | ||
module Generators | ||
describe ErrorPagesGenerator, type: :generator do | ||
it "generates 'public/pageflow/error_pages/404.html'" do | ||
run_generator | ||
|
||
expect(file('public/pageflow/error_pages/404.html')).to exist | ||
end | ||
|
||
it 'copies the fonts' do | ||
run_generator | ||
|
||
%w( | ||
sourcesanspro-bold-webfont.eot | ||
sourcesanspro-bold-webfont.svg | ||
sourcesanspro-bold-webfont.ttf | ||
sourcesanspro-bold-webfont.woff | ||
|
||
sourcesanspro-regular-webfont.eot | ||
sourcesanspro-regular-webfont.svg | ||
sourcesanspro-regular-webfont.ttf | ||
sourcesanspro-regular-webfont.woff | ||
).each do |font_file| | ||
expect(file("public/pageflow/error_pages/fonts/#{font_file}")).to exist | ||
end | ||
end | ||
|
||
it 'copies the stylesheets' do | ||
run_generator | ||
|
||
expect(file('public/pageflow/error_pages/stylesheets/main.css')).to exist | ||
end | ||
|
||
it 'copies the images' do | ||
run_generator | ||
|
||
expect(file('public/pageflow/error_pages/images/bg.jpg')).to exist | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [106/100]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still unsure if we should have a test for this? The line itself is covered. We could add an expection to the
EntriesController#show
spec that some text from the generated file shows up. For the rescue clause below, I see no way to get test coverage. A test could temporarily rename the404.html
file in the dummy app. But I'm not sure it's worth it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth it because the
head :not_found
in ApplicationController is part of our code. I added 527f703 to test this. It might not look pretty but it is effective. I added the safeguard since the test could fail for other reasons and leave the dummy app in an unclean state.An alternative could be to not bother with file-level stuff (which technically doesn't belong in a controller test anyway) but stub out the call to
render
and raiseActionView::MissingTemplate
from the test. But then you're testing Rails framework detail which might change at some point...Not sure what we should prefer here. But I do think a test has value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as testing response content, that has little additional value to me over the status code. Also it makes the test brittle in case someone wants to put in new text in this file.