diff options
-rw-r--r-- | actionpack/lib/action_dispatch/routing/inspector.rb | 31 | ||||
-rw-r--r-- | railties/lib/rails/info_controller.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/templates/rails/info/routes.html.erb | 27 |
3 files changed, 9 insertions, 51 deletions
diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb index 63d394be75..8d7461ecc3 100644 --- a/actionpack/lib/action_dispatch/routing/inspector.rb +++ b/actionpack/lib/action_dispatch/routing/inspector.rb @@ -67,19 +67,15 @@ module ActionDispatch @engines = Hash.new end - def format(all_routes, filter = nil, format = :txt) + def format(all_routes, filter = nil) if filter all_routes = all_routes.select{ |route| route.defaults[:controller] == filter } end routes = collect_routes(all_routes) - routes = formatted_routes(routes, format) + formatted_routes_for_engines(format) - if format == :html - routes.join('') - else - routes - end + formatted_routes(routes) + + formatted_routes_for_engines end def collect_routes(routes) @@ -105,32 +101,19 @@ module ActionDispatch end end - def formatted_routes_for_engines(format) + def formatted_routes_for_engines @engines.map do |name, routes| - ["\nRoutes for #{name}:"] + formatted_routes(routes, format) + ["\nRoutes for #{name}:"] + formatted_routes(routes) end.flatten end - def formatted_routes(routes, format) + def formatted_routes(routes) name_width = routes.map{ |r| r[:name].length }.max verb_width = routes.map{ |r| r[:verb].length }.max path_width = routes.map{ |r| r[:path].length }.max routes.map do |r| - if format == :txt - "#{r[:name].rjust(name_width)} " + - "#{r[:verb].ljust(verb_width)} " + - "#{r[:path].ljust(path_width)} " + - "#{r[:reqs]}" - elsif format == :html - route = r - "<tr class='route-row' data-helper='path' #{[:name, :verb, :path, :reqs].each {|key| "data-#{key}='#{route[key]}'"} } >" + - "<td class='route-name'>#{route[:name] + "<span class='helper'>_path</span>" if route[:name].present?}</td>" + - "<td class='route-verb'>#{route[:verb]}</td>" + - "<td class='route-path'>#{route[:path]}</td>" + - "<td class='route-reqs'>#{route[:reqs]}</td>" + - "</tr>" - end + "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" end end end diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index 8ffb56a522..fe1e25d88c 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -16,7 +16,7 @@ class Rails::InfoController < ActionController::Base def routes inspector = ActionDispatch::Routing::RoutesInspector.new - @info = inspector.format(_routes.routes, nil, :html) + @info = inspector.format(_routes.routes).join("\n") end protected diff --git a/railties/lib/rails/templates/rails/info/routes.html.erb b/railties/lib/rails/templates/rails/info/routes.html.erb index 8a7e4d37a0..890f6f5b03 100644 --- a/railties/lib/rails/templates/rails/info/routes.html.erb +++ b/railties/lib/rails/templates/rails/info/routes.html.erb @@ -1,7 +1,3 @@ -<style> -.route-row td {padding: 0 30px;} -.routeTable {margin: 0 auto 0;} -</style> <h2> Routes </h2> @@ -10,25 +6,4 @@ Routes match in priority from top to bottom </p> -<table id='routeTable' class='routeTable'> - <th>Helper<br /> - <%= 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)" %> - </th> - <th>HTTP Verb</th> - <th>Path</th> - <th>Controller#Action</th> - <%= @info.html_safe %> -</table> - -<script type='text/javascript'> - $(document).ready(function (){ - $("#routeTable [data-route-helper]").on('click', function(){ - routeHelper = $(this).data("route-helper"); - $('.route-name span.helper').html("_" + routeHelper); - return false; - }) - }) -</script>
\ No newline at end of file +<p><pre><%= @info %></pre></p>
\ No newline at end of file |