Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format routes as html on debug page #8543

Merged
merged 1 commit into from Dec 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -87,7 +87,7 @@ def formatted_routes(exception)
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
Expand Down
Expand Up @@ -20,4 +20,6 @@
Routes match in priority from top to bottom
</p>

<p><pre><%= @routes %></pre></p>
<%= render layout: "routes/route_wrapper" do %>
<%= render partial: "routes/route", collection: @routes %>
<% end %>
@@ -0,0 +1,16 @@
<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>
@@ -0,0 +1,56 @@
<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>
<%= yield %>
</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>
1 change: 1 addition & 0 deletions railties/lib/rails/info_controller.rb
Expand Up @@ -2,6 +2,7 @@

class Rails::InfoController < ActionController::Base # :nodoc:
self.view_paths = File.expand_path('../templates', __FILE__)
prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
layout 'application'

before_filter :require_local!
Expand Down
78 changes: 4 additions & 74 deletions railties/lib/rails/templates/rails/info/routes.html.erb
Expand Up @@ -6,77 +6,7 @@
Routes match in priority from top to bottom
</p>

<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>
<%# actionpack/lib/action_dispatch/middleware/templates %>
<%= render layout: "routes/route_wrapper" do %>
<%= render partial: "routes/route", collection: @routes %>
<% end %>