aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/inspector.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2013-02-18 16:03:28 -0800
committerXavier Noria <fxn@hashref.com>2013-02-18 16:03:28 -0800
commit8fd17e0c4120f762f87b88d0ccc7c75e2ae2e3ed (patch)
treece5922903e2b5752fd4ad0468550af2204a3572e /actionpack/lib/action_dispatch/routing/inspector.rb
parenta2322a5026641c8eb25a6c179ac1225d2abb128a (diff)
parenta6277629faf48469ac5ea4f6899b44a213d88c9f (diff)
downloadrails-8fd17e0c4120f762f87b88d0ccc7c75e2ae2e3ed.tar.gz
rails-8fd17e0c4120f762f87b88d0ccc7c75e2ae2e3ed.tar.bz2
rails-8fd17e0c4120f762f87b88d0ccc7c75e2ae2e3ed.zip
Merge pull request #9318 from steveklabnik/router_headings
Add headings to rake routes table
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/inspector.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/inspector.rb22
1 files changed, 19 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/routing/inspector.rb b/actionpack/lib/action_dispatch/routing/inspector.rb
index bc6dd7145c..82dd05a802 100644
--- a/actionpack/lib/action_dispatch/routing/inspector.rb
+++ b/actionpack/lib/action_dispatch/routing/inspector.rb
@@ -90,6 +90,8 @@ module ActionDispatch
routes_to_display = filter_routes(filter)
routes = collect_routes(routes_to_display)
+
+ formatter.header routes
formatter.section routes
@engines.each do |name, engine_routes|
@@ -155,16 +157,30 @@ module ActionDispatch
@buffer << draw_section(routes)
end
+ def header(routes)
+ @buffer << draw_header(routes)
+ end
+
private
def draw_section(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
+ name_width, verb_width, path_width = widths(routes)
routes.map do |r|
"#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
end
end
+
+ def draw_header(routes)
+ name_width, verb_width, path_width = widths(routes)
+
+ "#{"Prefix".rjust(name_width)} #{"Verb".ljust(verb_width)} #{"URI Pattern".ljust(path_width)} Controller#Action"
+ end
+
+ def widths(routes)
+ [routes.map { |r| r[:name].length }.max,
+ routes.map { |r| r[:verb].length }.max,
+ routes.map { |r| r[:path].length }.max]
+ end
end
class HtmlTableFormatter