From 37d9c44b6d15cc0b02f327fe51687db7d0443bb8 Mon Sep 17 00:00:00 2001 From: schneems Date: Mon, 17 Dec 2012 14:26:46 -0600 Subject: Format routes as html on debug page When someone gets a routing exception, the routes are rendered (starting in Rails 4.0). This PR brings parity between the html routes in the `rails/info/routes` path and when rendered from an exception. This is the continuation of #8521 which brought html formatted routes. In addition to bringing parity to the two views, we're keeping our views DRY by rendering off of the same partials. In this case Railties depends on partials provided by ActionDispatch. I'm open to alternative implementations. Ideally both views will use the same code so any improvements or updates to it will be reproduced on both.
![](http://f.cl.ly/items/3O1D0K1v0j0i343O3T3T/Screen%20Shot%202012-12-17%20at%203.07.20%20PM.png) --- .../action_dispatch/middleware/debug_exceptions.rb | 2 +- .../middleware/templates/rescues/routing_error.erb | 4 +- .../middleware/templates/routes/_route.html.erb | 16 +++++++ .../templates/routes/_route_wrapper.html.erb | 56 ++++++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 actionpack/lib/action_dispatch/middleware/templates/routes/_route.html.erb create mode 100644 actionpack/lib/action_dispatch/middleware/templates/routes/_route_wrapper.html.erb (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index f356c2a85c..1dc51d62e0 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -87,7 +87,7 @@ module ActionDispatch return false unless @routes_app.respond_to?(:routes) if exception.is_a?(ActionController::RoutingError) || exception.is_a?(ActionView::Template::Error) inspector = ActionDispatch::Routing::RoutesInspector.new - inspector.format(@routes_app.routes.routes).join("\n") + inspector.collect_routes(@routes_app.routes.routes) end end end diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb index a357a7ba11..6c903d6a17 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.erb @@ -20,4 +20,6 @@ Routes match in priority from top to bottom

-

<%= @routes %>

+<%= render layout: "routes/route_wrapper" do %> + <%= render partial: "routes/route", collection: @routes %> +<% end %> diff --git a/actionpack/lib/action_dispatch/middleware/templates/routes/_route.html.erb b/actionpack/lib/action_dispatch/middleware/templates/routes/_route.html.erb new file mode 100644 index 0000000000..400ae97d22 --- /dev/null +++ b/actionpack/lib/action_dispatch/middleware/templates/routes/_route.html.erb @@ -0,0 +1,16 @@ + + + <% if route[:name].present? %> + <%= route[:name] %>_path + <% end %> + + + <%= route[:verb] %> + + + <%= route[:path] %> + + + <%= route[:reqs] %> + + diff --git a/actionpack/lib/action_dispatch/middleware/templates/routes/_route_wrapper.html.erb b/actionpack/lib/action_dispatch/middleware/templates/routes/_route_wrapper.html.erb new file mode 100644 index 0000000000..9bf5c96c95 --- /dev/null +++ b/actionpack/lib/action_dispatch/middleware/templates/routes/_route_wrapper.html.erb @@ -0,0 +1,56 @@ + + + + + + + + + + + + + <%= yield %> + +
Helper
+ <%= link_to "Path", "#", 'data-route-helper' => '_path', + title: "Returns a relative path (without the http or domain)" %> / + <%= link_to "Url", "#", 'data-route-helper' => '_url', + title: "Returns an absolute url (with the http and domain)" %> +
HTTP VerbPathController#Action
+ + -- cgit v1.2.3 From 0a6d8fbe1738984a9cae2168b97461b2ccf64c49 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sat, 1 Dec 2012 18:26:47 +0300 Subject: handle protocol option in stylesheet_link_tag and javascript_include_tag closes #8388 --- actionpack/CHANGELOG.md | 4 ++++ .../lib/action_view/helpers/asset_tag_helper.rb | 8 ++++++-- actionpack/test/template/asset_tag_helper_test.rb | 24 +++++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index c3df2ebc0c..d213ab057c 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* Handle `:protocol` option in `stylesheet_link_tag` and `javascript_include_tag` + + *Vasiliy Ermolovich* + * Clear url helper methods when routes are reloaded. *Andrew White* * Fix a bug in `ActionDispatch::Request#raw_post` that caused `env['rack.input']` diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index cf2a117966..11743e36f2 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -53,9 +53,11 @@ module ActionView # def javascript_include_tag(*sources) options = sources.extract_options!.stringify_keys + path_options = options.extract!('protocol').symbolize_keys + sources.uniq.map { |source| tag_options = { - "src" => path_to_javascript(source) + "src" => path_to_javascript(source, path_options) }.merge(options) content_tag(:script, "", tag_options) }.join("\n").html_safe @@ -89,11 +91,13 @@ module ActionView # def stylesheet_link_tag(*sources) options = sources.extract_options!.stringify_keys + path_options = options.extract!('protocol').symbolize_keys + sources.uniq.map { |source| tag_options = { "rel" => "stylesheet", "media" => "screen", - "href" => path_to_stylesheet(source) + "href" => path_to_stylesheet(source, path_options) }.merge(options) tag(:link, tag_options) }.join("\n").html_safe diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index eb1a54a81f..82c9d383ac 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -358,6 +358,17 @@ class AssetTagHelperTest < ActionView::TestCase assert javascript_include_tag("prototype").html_safe? end + def test_javascript_include_tag_relative_protocol + @controller.config.asset_host = "assets.example.com" + assert_dom_equal %(), javascript_include_tag('prototype', protocol: :relative) + end + + def test_javascript_include_tag_default_protocol + @controller.config.asset_host = "assets.example.com" + @controller.config.default_asset_host_protocol = :relative + assert_dom_equal %(), javascript_include_tag('prototype') + end + def test_stylesheet_path StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -398,7 +409,18 @@ class AssetTagHelperTest < ActionView::TestCase end def test_stylesheet_link_tag_should_not_output_the_same_asset_twice - assert_dom_equal %(\n), stylesheet_link_tag('wellington', 'wellington', 'amsterdam') + assert_dom_equal %(\n), stylesheet_link_tag('wellington', 'wellington', 'amsterdam') + end + + def test_stylesheet_link_tag_with_relative_protocol + @controller.config.asset_host = "assets.example.com" + assert_dom_equal %(), stylesheet_link_tag('wellington', protocol: :relative) + end + + def test_stylesheet_link_tag_with_default_protocol + @controller.config.asset_host = "assets.example.com" + @controller.config.default_asset_host_protocol = :relative + assert_dom_equal %(), stylesheet_link_tag('wellington') end def test_image_path -- cgit v1.2.3 From c3e573db54c55c4e4ac694940c6d2f5b42b6155b Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 17 Dec 2012 21:51:43 -0200 Subject: Minor js review [ci skip] Remove/add ; where necessary, fix indentation. --- .../middleware/templates/routes/_route_wrapper.html.erb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/middleware/templates/routes/_route_wrapper.html.erb b/actionpack/lib/action_dispatch/middleware/templates/routes/_route_wrapper.html.erb index 9bf5c96c95..dc17cb77ef 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/routes/_route_wrapper.html.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/routes/_route_wrapper.html.erb @@ -24,22 +24,22 @@