routes_page 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '09e9a33baf3700143864498f3511398803f5a959c6547273d67478d11361c79d'
4
+ data.tar.gz: 3bcfdc805bc2dcafeeebf14dcf2170aba17b3e0647ada0e978491c65947e6cac
5
+ SHA512:
6
+ metadata.gz: 7ca5106bc32fefa7d0ea813524a22fc4ddc69e620435977fe029a2072ebab7282752df05933c9e83e607eb9d631ef3487446c508e6200d9a02bec31c8550f537
7
+ data.tar.gz: e06b48de29b7825a67e0aa8276577a9f3ec39661d002f325ccf75dd08dbe2b090203ca0c146f962a0522c14967a175ddc3c612f7a2c049004ba9e32acf7e49c6
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Jason Heylon
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # RoutesPage
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'routes_page'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install routes_page
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RoutesPage'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/routes_page .js
2
+ //= link_directory ../stylesheets/routes_page .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,20 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
16
+
17
+ body {
18
+ background-color: #FFF;
19
+ color: #333;
20
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ h3{
7
+ text-align: center;
8
+ }
9
+
10
+ .routes-title{
11
+ text-align: center;
12
+ background-color: #333;
13
+ color: #fff;
14
+ }
15
+
16
+ .routes-table{
17
+ border-spacing: 0;
18
+ width: 100%;
19
+ line-height: 25px;
20
+ text-align: left;
21
+ }
22
+
23
+ .routes-table thead th{
24
+ border-bottom: 3px solid #e1e1e1;
25
+ }
26
+
27
+ .routes-table tbody tr:nth-child(even) {
28
+ background: #DDD
29
+ }
30
+
31
+ .routes-table tbody tr:nth-child(odd) {
32
+ background: #FFF
33
+ }
@@ -0,0 +1,5 @@
1
+ module RoutesPage
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require_dependency "routes_page/application_controller"
2
+
3
+ module RoutesPage
4
+ class RoutesController < ApplicationController
5
+ def index
6
+ @routes = RoutesPage.format_routes
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module RoutesPage
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module RoutesPage
2
+ module RoutesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module RoutesPage
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module RoutesPage
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module RoutesPage
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Routes page</title>
5
+ <%= stylesheet_link_tag "routes_page/application", media: "all" %>
6
+ <%= javascript_include_tag "routes_page/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,81 @@
1
+ <h3>
2
+ List of Routes
3
+ </h3>
4
+
5
+ <div class="routes">
6
+ <div class="routes-title rails-route">
7
+ Rails routes
8
+ </div>
9
+ <table class="routes-table">
10
+ <thead>
11
+ <tr>
12
+ <th>name</th>
13
+ <th>verb</th>
14
+ <th>path</th>
15
+ <th>controller#actin</th>
16
+ </tr>
17
+ </thead>
18
+ <tobdy>
19
+ <% @routes[:rails_routes].each do |route| %>
20
+ <tr class="route">
21
+ <td>
22
+ <% if route[:name].present? %>
23
+ <%= route[:name] %>_path
24
+ <% end %>
25
+ </td>
26
+ <td>
27
+ <%= route[:verb] %>
28
+ </td>
29
+ <td>
30
+ <%= route[:path] %>
31
+ </td>
32
+ <td>
33
+ <%= route[:reqs] %>
34
+ </td>
35
+ </tr>
36
+ <% end %>
37
+ </tobdy>
38
+ </table>
39
+ </div>
40
+
41
+ <br>
42
+ <% if @routes[:grape_routes].any? %>
43
+ <div class="routes">
44
+ <div class="routes-title rails-route">
45
+ Grape routes
46
+ </div>
47
+ <table class="routes-table">
48
+ <thead>
49
+ <tr>
50
+ <th>namespace</th>
51
+ <th>version</th>
52
+ <th>verb</th>
53
+ <th>path</th>
54
+ <th>params</th>
55
+ </tr>
56
+ </thead>
57
+ <tobdy>
58
+ <% @routes[:grape_routes].each do |route| %>
59
+ <tr class="route">
60
+ <td>
61
+ <%= route[:namespace] %>
62
+ </td>
63
+ <td>
64
+ <%= route[:version] %>
65
+ </td>
66
+ <td>
67
+ <%= route[:verb] %>
68
+ </td>
69
+ <td>
70
+ <%= route[:path] %>
71
+ </td>
72
+ <td>
73
+ <%= route[:params] %>
74
+ </td>
75
+ </tr>
76
+ <% end %>
77
+ </tobdy>
78
+ </table>
79
+ </div>
80
+
81
+ <% end %>
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ # RoutesPage::Engine.routes.draw do
2
+ # root to: 'routes#index'
3
+ # end
4
+ #
5
+ #
6
+
7
+ Rails.application.routes.draw do
8
+ mount RoutesPage::Engine => "rails/routes_page"
9
+ get "rails/routes_page" => "routes_page/routes#index"
10
+ end
@@ -0,0 +1,5 @@
1
+ module RoutesPage
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace RoutesPage
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module RoutesPage
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,53 @@
1
+ require "routes_page/engine"
2
+
3
+ module RoutesPage
4
+ require 'action_dispatch/routing/inspector'
5
+ RAILS_ROUTE_INSPECTOR = ActionDispatch::Routing::RoutesInspector.new([])
6
+
7
+ def self.format_routes(routes = all_routes)
8
+ routes_formated = RAILS_ROUTE_INSPECTOR.send :collect_routes, routes
9
+
10
+ grape_routes_formated = format_grape_routes(find_grape_routes(routes))
11
+ {
12
+ rails_routes: routes_formated,
13
+ grape_routes: grape_routes_formated
14
+ }
15
+ end
16
+
17
+ def self.format_grape_routes(grape_routes)
18
+ return [] if grape_routes.empty?
19
+
20
+ grape_routes_formated = []
21
+ grape_routes.each do |grape_route|
22
+ grape_routes_formated += grape_route.routes.collect do |gr|
23
+ {
24
+ namespace: gr.namespace,
25
+ verb: gr.options[:method],
26
+ path: gr.pattern.path,
27
+ params: gr.params,
28
+ version: gr.version
29
+ }
30
+ end
31
+ end
32
+ grape_routes_formated
33
+ end
34
+
35
+ def self.find_grape_routes(routes)
36
+ route_wrappers = routes.collect { |route| ActionDispatch::Routing::RouteWrapper.new(route) }
37
+ # grape rails route in array
38
+ routes_with_grape = route_wrappers.select {|r| (r.app.app.superclass rescue nil).to_s == 'Grape::API' }
39
+ return [] if routes_with_grape.empty?
40
+
41
+ routes_with_grape.collect { |r| r.app.app }
42
+ end
43
+
44
+ def self.all_routes
45
+ Rails.application.reload_routes!
46
+ Rails.application.routes.routes
47
+ end
48
+
49
+ def self.enable_grape_routes!
50
+ @enable_grape = true
51
+ end
52
+
53
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :routes_page do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: routes_page
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Heylon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: grape
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.0.1
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: byebug
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '9.1'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '9.1'
75
+ - !ruby/object:Gem::Dependency
76
+ name: capybara
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.16'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.16.1
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '2.16'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.16.1
95
+ description: Simple web page for rails routes and grape routes display
96
+ email:
97
+ - jasonheylon@gmail.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - MIT-LICENSE
103
+ - README.md
104
+ - Rakefile
105
+ - app/assets/config/routes_page_manifest.js
106
+ - app/assets/javascripts/routes_page/application.js
107
+ - app/assets/javascripts/routes_page/routes.js
108
+ - app/assets/stylesheets/routes_page/application.css
109
+ - app/assets/stylesheets/routes_page/routes.css
110
+ - app/controllers/routes_page/application_controller.rb
111
+ - app/controllers/routes_page/routes_controller.rb
112
+ - app/helpers/routes_page/application_helper.rb
113
+ - app/helpers/routes_page/routes_helper.rb
114
+ - app/jobs/routes_page/application_job.rb
115
+ - app/mailers/routes_page/application_mailer.rb
116
+ - app/models/routes_page/application_record.rb
117
+ - app/views/layouts/routes_page/application.html.erb
118
+ - app/views/routes_page/routes/index.html.erb
119
+ - config/routes.rb
120
+ - lib/routes_page.rb
121
+ - lib/routes_page/engine.rb
122
+ - lib/routes_page/version.rb
123
+ - lib/tasks/routes_page_tasks.rake
124
+ homepage: https://github.com/JasonHeylon/routes_page
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.7.3
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Simple web page for rails routes and grape routes display
148
+ test_files: []