Merge pull request #49240 from deepakmahakale/notes-ui
Add an internal route for bin/rails notes
This commit is contained in:
commit
c666dac546
@ -143,6 +143,7 @@ def self.complete(_state)
|
||||
app.routes.prepend do
|
||||
get "/rails/info/properties" => "rails/info#properties", internal: true
|
||||
get "/rails/info/routes" => "rails/info#routes", internal: true
|
||||
get "/rails/info/notes" => "rails/info#notes", internal: true
|
||||
get "/rails/info" => "rails/info#index", internal: true
|
||||
end
|
||||
|
||||
|
@ -32,6 +32,14 @@ def routes
|
||||
end
|
||||
end
|
||||
|
||||
def notes
|
||||
@annotations = Rails::SourceAnnotationExtractor.new(
|
||||
Rails::SourceAnnotationExtractor::Annotation.tags.join("|")
|
||||
).find(
|
||||
Rails::SourceAnnotationExtractor::Annotation.directories
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
def matching_routes(query:, exact_match:)
|
||||
return [] if query.blank?
|
||||
|
65
railties/lib/rails/templates/rails/info/notes.html.erb
Normal file
65
railties/lib/rails/templates/rails/info/notes.html.erb
Normal file
@ -0,0 +1,65 @@
|
||||
<style>
|
||||
h2, p {
|
||||
padding-left: 30px;
|
||||
}
|
||||
table {
|
||||
margin: 0;
|
||||
border-collapse: collapse;
|
||||
word-wrap:break-word;
|
||||
table-layout: fixed;
|
||||
width:100%;
|
||||
}
|
||||
table thead tr {
|
||||
border-bottom: 2px solid #ddd;
|
||||
}
|
||||
table th {
|
||||
padding-left: 30px;
|
||||
text-align: left;
|
||||
}
|
||||
table thead th.tag, table thead th.line-no {
|
||||
width: 10%;
|
||||
}
|
||||
table tbody tr {
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
table tbody tr:nth-child(odd) {
|
||||
background: #f2f2f2;
|
||||
}
|
||||
table td {
|
||||
padding: 4px 30px;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
table tbody tr:nth-child(odd) {
|
||||
background: #282828;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<h2>
|
||||
Notes
|
||||
</h2>
|
||||
|
||||
<table id="route_table" class="table">
|
||||
<thead>
|
||||
<th>File Name</th>
|
||||
<th class="line-no">Line No.</th>
|
||||
<th class="tag">Tag</th>
|
||||
<th>Description</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @annotations.each do |file, annotations| %>
|
||||
<% annotations.each.with_index do |annotation, index| %>
|
||||
<tr>
|
||||
<% if index == 0 %>
|
||||
<th rowspan="<%= annotations.size %>">
|
||||
<%= file %>
|
||||
</th>
|
||||
<% end %>
|
||||
<td class="line-no"><%= annotation.line %></td>
|
||||
<td class="tag"><%= annotation.tag %></td>
|
||||
<td><%= annotation.text %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
@ -19,6 +19,7 @@ def setup
|
||||
end
|
||||
get "/rails/info/properties" => "rails/info#properties"
|
||||
get "/rails/info/routes" => "rails/info#routes"
|
||||
get "/rails/info/notes" => "rails/info#notes"
|
||||
post "/rails/:test/properties" => "rails/info#properties"
|
||||
put "/rails/:test/named_properties" => "rails/info#properties", as: "named_rails_info_properties"
|
||||
end
|
||||
@ -118,10 +119,11 @@ def fuzzy_results
|
||||
assert exact_results.size == 0, "should not case-insensitive match HTTP Verb methods"
|
||||
|
||||
get :routes, params: { query: "GET" }
|
||||
assert exact_results.size == 3, "should match complete HTTP Verb methods"
|
||||
assert exact_results.size == 4, "should match complete HTTP Verb methods"
|
||||
assert exact_results.include? "/test/nested_route(.:format)"
|
||||
assert exact_results.include? "/rails/info/properties(.:format)"
|
||||
assert exact_results.include? "/rails/info/routes(.:format)"
|
||||
assert exact_results.include? "/rails/info/notes(.:format)"
|
||||
end
|
||||
|
||||
test "info controller search returns exact matches for route Controller#Action(s)" do
|
||||
@ -140,9 +142,10 @@ def fuzzy_results
|
||||
assert exact_results.size == 0, "should not match unnamed routes"
|
||||
|
||||
get :routes, params: { query: "rails_info" }
|
||||
assert fuzzy_results.size == 3, "should match incomplete route names"
|
||||
assert fuzzy_results.size == 4, "should match incomplete route names"
|
||||
assert fuzzy_results.include? "/rails/info/properties(.:format)"
|
||||
assert fuzzy_results.include? "/rails/info/routes(.:format)"
|
||||
assert fuzzy_results.include? "/rails/info/notes(.:format)"
|
||||
assert fuzzy_results.include? "/rails/:test/named_properties(.:format)"
|
||||
|
||||
get :routes, params: { query: "/rails/info/routes" }
|
||||
|
Loading…
Reference in New Issue
Block a user