diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-17 10:48:12 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-17 10:48:12 -0800 |
commit | 75ba92e993d13bf3dffa56f06a72f07dad44b4a6 (patch) | |
tree | b06706105e21bffd69cef6dc6ba7699af71a6df8 | |
parent | dcb318ee438785239fad27ece96c3cf6dd7ce12e (diff) | |
parent | 8a59b873749a88b0f4ed9b80bc3237c88313302c (diff) | |
download | rails-75ba92e993d13bf3dffa56f06a72f07dad44b4a6.tar.gz rails-75ba92e993d13bf3dffa56f06a72f07dad44b4a6.tar.bz2 rails-75ba92e993d13bf3dffa56f06a72f07dad44b4a6.zip |
Merge pull request #8521 from schneems/schneems/html-routes
HTML formatting to Rails::InfoController#routes
-rw-r--r-- | railties/CHANGELOG.md | 4 | ||||
-rw-r--r-- | railties/lib/rails/info_controller.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/templates/rails/info/routes.html.erb | 75 | ||||
-rw-r--r-- | railties/test/rails_info_controller_test.rb | 2 |
4 files changed, 80 insertions, 4 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index ed5dfc6446..126a38a2d6 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* The `rails/info/routes` now correctly formats routing output as an html table. + + *Richard Schneeman* + * The `public/index.html` is no longer generated for new projects. Page is replaced by internal `welcome_controller` inside of railties. diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index e296637f39..ec7d5ed610 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -15,8 +15,7 @@ class Rails::InfoController < ActionController::Base # :nodoc: end def routes - inspector = ActionDispatch::Routing::RoutesInspector.new - @info = inspector.format(_routes.routes).join("\n") + @routes = ActionDispatch::Routing::RoutesInspector.new.collect_routes(_routes.routes) 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 890f6f5b03..e34c1c4135 100644 --- a/railties/lib/rails/templates/rails/info/routes.html.erb +++ b/railties/lib/rails/templates/rails/info/routes.html.erb @@ -6,4 +6,77 @@ Routes match in priority from top to bottom </p> -<p><pre><%= @info %></pre></p>
\ No newline at end of file +<style type='text/css'> + #route_table td {padding: 0 30px;} + #route_table {margin: 0 auto 0;} +</style> + +<table id='route_table' class='route_table'> + <thead> + <tr> + <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> + </tr> + </thead> + <tbody> + <% @routes.each do |route| %> + <tr class='route_row' data-helper='path'> + <td data-route-name='<%= route[:name] %>'> + <% if route[:name].present? %> + <%= route[:name] %><span class='helper'>_path</span> + <% end %> + </td> + <td data-route-verb='<%= route[:verb] %>'> + <%= route[:verb] %> + </td> + <td data-route-path='<%= route[:path] %>'> + <%= route[:path] %> + </td> + <td data-route-reqs='<%= route[:reqs] %>'> + <%= route[:reqs] %> + </td> + </tr> + <% end %> + </tbody> +</table> + +<script type='text/javascript'> + function each(elems, func) { + if (!elems instanceof Array) var elems = [elems]; + for(var i = elems.length; i--; ) { + func(elems[i]); + }; + } + + function setValOn(elems, val) { + each(elems, function(elem) { + elem.innerHTML = val; + }) + } + + function onClick(elems, func) { + each(elems, function(elem) { + elem.onclick = func; + }) + } + + // Enables functionality to toggle between `_path` and `_url` helper suffixes + function setupRouteToggleHelperLinks() { + var toggleLinks = document.querySelectorAll('#route_table [data-route-helper]'); + onClick(toggleLinks, function(){ + var helperTxt = this.getAttribute("data-route-helper"); + var helperElems = document.querySelectorAll('[data-route-name] span.helper'); + setValOn(helperElems, helperTxt); + }) + } + + setupRouteToggleHelperLinks(); + +</script> diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 08fcddd4bf..a9b237d0a5 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -50,7 +50,7 @@ class InfoControllerTest < ActionController::TestCase test "info controller renders with routes" do get :routes - assert_select 'pre' + assert_response :success end end |