aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2012-12-13 08:30:51 -0800
committerSteve Klabnik <steve@steveklabnik.com>2012-12-13 08:30:51 -0800
commitae68fc3864e99ab43c18fd12577744e1583f6b64 (patch)
tree5e99366d7f1f930d563f6c58b481e29f6376aa07 /actionpack
parent0262a18c7b0ab6f60fee842b3007388f9ffeb0fa (diff)
parent08d7b186fde6ec1e7779349a6ff00e34b30f294d (diff)
downloadrails-ae68fc3864e99ab43c18fd12577744e1583f6b64.tar.gz
rails-ae68fc3864e99ab43c18fd12577744e1583f6b64.tar.bz2
rails-ae68fc3864e99ab43c18fd12577744e1583f6b64.zip
Merge pull request #8499 from schneems/schneems/html-route-inspector
Output routes in :html format
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/inspector.rb31
1 files changed, 24 insertions, 7 deletions
diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb
index 8d7461ecc3..63d394be75 100644
--- a/actionpack/lib/action_dispatch/routing/inspector.rb
+++ b/actionpack/lib/action_dispatch/routing/inspector.rb
@@ -67,15 +67,19 @@ module ActionDispatch
@engines = Hash.new
end
- def format(all_routes, filter = nil)
+ def format(all_routes, filter = nil, format = :txt)
if filter
all_routes = all_routes.select{ |route| route.defaults[:controller] == filter }
end
routes = collect_routes(all_routes)
- formatted_routes(routes) +
- formatted_routes_for_engines
+ routes = formatted_routes(routes, format) + formatted_routes_for_engines(format)
+ if format == :html
+ routes.join('')
+ else
+ routes
+ end
end
def collect_routes(routes)
@@ -101,19 +105,32 @@ module ActionDispatch
end
end
- def formatted_routes_for_engines
+ def formatted_routes_for_engines(format)
@engines.map do |name, routes|
- ["\nRoutes for #{name}:"] + formatted_routes(routes)
+ ["\nRoutes for #{name}:"] + formatted_routes(routes, format)
end.flatten
end
- def formatted_routes(routes)
+ def formatted_routes(routes, format)
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|
- "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
+ 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
end
end
end