Skip to content
This repository was archived by the owner on Jun 21, 2021. It is now read-only.

Commit c50b8b9

Browse files
committed
xhtml
1 parent 2cea6a6 commit c50b8b9

File tree

5 files changed

+58
-48
lines changed

5 files changed

+58
-48
lines changed

app/controllers/application_controller.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
33

44
protect_from_forgery
55

6-
after_action :set_content_type_to_xhtml, :tidy_response_body
6+
after_action :tidy_response_body
77
helper_method :logged_in?, :current_user
88
helper_method :authorized_to_show_user?, :authorized_to_show_user_best?
99

@@ -46,12 +46,6 @@ def authorize_to_show_user_best!(user)
4646
end
4747

4848
private
49-
def set_content_type_to_xhtml
50-
if request.format == :html
51-
response.content_type = "application/xhtml+xml"
52-
end
53-
end
54-
5549
def tidy_response_body
5650
if [:html, :xml, :rss, :atom].any? {|s| request.format == s }
5751
response.body = ActiveSupport::Multibyte::Unicode.tidy_bytes(response.body)

app/controllers/concerns/controller_error_handling.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,12 @@ module ControllerErrorHandling
2121
@message = t("error.not_found")
2222
render "shared/common_error", status: 404, formats: :html
2323
end
24+
25+
rescue_from ActionView::MissingTemplate do
26+
if request.format != :html
27+
@message = t("error.not_found")
28+
render "shared/common_error", status: 404, formats: :html
29+
end
30+
end
2431
end
2532
end

config/initializers/mime_types.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
# Add new mime types for use in respond_to blocks:
44
# Mime::Type.register "text/richtext", :rtf
55
# Mime::Type.register_alias "text/html", :iphone
6+
7+
Mime.__send__(:remove_const, "HTML")
8+
Mime::Type.register "application/xhtml+xml", :html

config/initializers/xhtml.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module AssignDefaultContentTypeAndCharsetXHTML
2+
private
3+
def assign_default_content_type_and_charset!(headers)
4+
@content_type = Mime::XHTML
5+
super(headers)
6+
end
7+
end
8+
ActionDispatch::Response.__send__(:include, AssignDefaultContentTypeAndCharsetXHTML)

config/routes.rb

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,47 @@
33

44
mount Api => "/api"
55

6-
constraints format: :html do
7-
# Internals / SessionsController
8-
get "/i/callback" => "sessions#create"
9-
get "/i/logout" => "sessions#destroy", as: "logout"
10-
11-
get "/i/user_jump_suggest" => "users#user_jump_suggest", as: "user_jump_suggest"
12-
13-
get "/i/:id" => "tweets#show", as: "tweet", constraints: { id: /\d+/ }
14-
get "/i/:id/import" => "tweets#import", as: "import", constraints: { id: /\d+/ }
15-
16-
get "/i/settings" => "settings#index", as: "settings"
17-
post "/i/settings/update" => "settings#update"
18-
get "/i/settings/confirm_deactivation" => "settings#confirm_deactivation"
19-
post "/i/settings/deactivate" => "settings#deactivate"
20-
21-
get "/i/best" => "tweets#all_best", as: "best"
22-
get "/i/recent" => "tweets#all_recent", as: "recent"
23-
get "/i/timeline" => "tweets#all_timeline", as: "timeline"
24-
get "/i/filter" => "tweets#filter", as: "filter"
25-
26-
get "/about/api" => "apidocs#index", as: "about_api"
27-
get "/about/api/:method/:namespace/:path" => "apidocs#endpoint", as: "about_api_endpoint", constraints: { namespace: /[\w\/]+/ }
28-
29-
# User pages
30-
scope "/:screen_name" do
31-
get "/" => "tweets#user_index", as: "user"
32-
get "/best" => "tweets#user_best", as: "user_best"
33-
get "/recent" => "tweets#user_recent", as: "user_recent"
34-
get "/timeline" => "tweets#user_timeline", as: "user_timeline"
35-
get "/discoveries" => "tweets#user_discoveries", as: "user_discoveries"
36-
get "/favorites" => "tweets#user_favorites", as: "user_favorites"
37-
get "/retweets" => "tweets#user_retweets", as: "user_retweets"
38-
get "/discovered_by/:source_screen_name" => "tweets#user_discovered_by", as: "user_discovered_by_user"
39-
40-
get "/discovered_by" => "users#discovered_by", as: "user_discovered_by"
41-
get "/discovered_users" => "users#discovered_users", as: "user_discovered_users"
42-
get "/stats" => "users#stats", as: "user_stats"
43-
end
44-
45-
# Twitter redirect
46-
get "/:screen_name/status(es)/:id" => redirect("/i/%{id}")
6+
# Internals / SessionsController
7+
get "/i/callback" => "sessions#create"
8+
get "/i/logout" => "sessions#destroy", as: "logout"
9+
10+
get "/i/user_jump_suggest" => "users#user_jump_suggest", as: "user_jump_suggest"
11+
12+
get "/i/:id" => "tweets#show", as: "tweet", constraints: { id: /\d+/ }
13+
get "/i/:id/import" => "tweets#import", as: "import", constraints: { id: /\d+/ }
14+
15+
get "/i/settings" => "settings#index", as: "settings"
16+
post "/i/settings/update" => "settings#update"
17+
get "/i/settings/confirm_deactivation" => "settings#confirm_deactivation"
18+
post "/i/settings/deactivate" => "settings#deactivate"
19+
20+
get "/i/best" => "tweets#all_best", as: "best"
21+
get "/i/recent" => "tweets#all_recent", as: "recent"
22+
get "/i/timeline" => "tweets#all_timeline", as: "timeline"
23+
get "/i/filter" => "tweets#filter", as: "filter"
24+
25+
get "/about/api" => "apidocs#index", as: "about_api"
26+
get "/about/api/:method/:namespace/:path" => "apidocs#endpoint", as: "about_api_endpoint", constraints: { namespace: /[\w\/]+/ }
27+
28+
# User pages
29+
scope "/:screen_name" do
30+
get "/" => "tweets#user_index", as: "user"
31+
get "/best" => "tweets#user_best", as: "user_best"
32+
get "/recent" => "tweets#user_recent", as: "user_recent"
33+
get "/timeline" => "tweets#user_timeline", as: "user_timeline"
34+
get "/discoveries" => "tweets#user_discoveries", as: "user_discoveries"
35+
get "/favorites" => "tweets#user_favorites", as: "user_favorites"
36+
get "/retweets" => "tweets#user_retweets", as: "user_retweets"
37+
get "/discovered_by/:source_screen_name" => "tweets#user_discovered_by", as: "user_discovered_by_user"
38+
39+
get "/discovered_by" => "users#discovered_by", as: "user_discovered_by"
40+
get "/discovered_users" => "users#discovered_users", as: "user_discovered_users"
41+
get "/stats" => "users#stats", as: "user_stats"
4742
end
4843

44+
# Twitter redirect
45+
get "/:screen_name/status(es)/:id" => redirect("/i/%{id}")
46+
4947
get "*unmatched_route" => "application#routing_error"
5048
end
5149

0 commit comments

Comments
 (0)