colorized_routes 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 722e690feaacf939e73025914b27154d57537e7a
4
- data.tar.gz: 077478d32aa46d6c83b4219e370aeb84520d35b8
3
+ metadata.gz: f700a2be72843f531c93b73dbe5b48012c95cb95
4
+ data.tar.gz: b5c544d55c9c1a93195f763e147687d057ca416a
5
5
  SHA512:
6
- metadata.gz: 146f7378ea7d3083b43b5e7e67d0621ec897abdbfe5de6ef0877147fe10ec8772599f0cf53d0b3e28f6b85135228595d54fc3b1ab49e05de0a1551b617ba296d
7
- data.tar.gz: b8aa8b5ba3b54230f078c3af5365a905d12c69ae4eab261bc7dcc99c05addf5b6e969d733895d7e24be5ae647e47e6a99b18308b4606993065c5bb948734ccc9
6
+ metadata.gz: a819ac8d67cf7f44e9ee0ae80fa27d16388f6e1a191a63ac648f763defdb1d757d710e634e1c7bf684d339e40f327bbc0ea03e3bdc4f9c082d76689a49184d8e
7
+ data.tar.gz: b0174284bff2ba85442584f9f8e85bba492613a708e1dc00ecdafe6fa65aa1379c7aa98a470c87277b98d3f22ed79a531e59a4673a025c501de743c65f0be78c
data/README.md CHANGED
@@ -36,4 +36,4 @@ rake routes
36
36
  <img src="https://imgur.com/BeKHDbB.png" title="Example output" alt="Example output" />
37
37
 
38
38
  ####colorized rake routes output:
39
- <img src="https://imgur.com/xlpTPtB.png" title="Example output" alt="Example output" />
39
+ <img src="https://imgur.com/T7Aw1kA.png" title="Example output" alt="Example output" />
@@ -0,0 +1,45 @@
1
+ #module ColorizedRoutes
2
+ class Controller
3
+ # The controller will have many routes
4
+
5
+ def initialize routes, name
6
+ if name.include? "/"
7
+ parts = name.split("/")
8
+ @name = parts.last
9
+ @namespaces = parts.take(parts.size - 1)
10
+ else
11
+ @name = name
12
+ @namespaces = []
13
+ end
14
+ @routes = routes
15
+ end
16
+
17
+ def display widths
18
+ space_counter = 0
19
+ if @namespaces.any?
20
+ @namespaces.each do |ns|
21
+ unless space_counter == 0
22
+ print "#{Array(1..space_counter).map{|s| " "}.join}"
23
+ end
24
+ print "Namespace: ".light_white
25
+ puts " #{ns} ".light_white.on_light_red.bold
26
+ space_counter += 1
27
+ end
28
+ end
29
+ unless space_counter == 0
30
+ print "#{Array(1..space_counter).map{|s| " "}.join}"
31
+ end
32
+ print "Controller: ".light_white
33
+ if @namespaces.any?
34
+ print " #{@name} ".light_white.on_blue.bold
35
+ print " => ".light_white
36
+ puts " #{[@namespaces.join("/"),@name].join("/")} ".light_white.on_blue.bold
37
+ else
38
+ puts " #{@name} ".light_white.on_blue.bold
39
+ end
40
+ @routes.each {|r| r.display(widths)}
41
+
42
+ puts ""
43
+ end
44
+ end
45
+ #end
@@ -1,10 +1,14 @@
1
1
  desc 'Makes routes a little more pretty.'
2
2
 
3
+
3
4
  task :routes do
4
- puts " ".light_white.on_blue
5
- puts " COLORIZED ROUTES ".light_white.on_blue
6
- puts " github: https://github.com/joshtate04/colorized_routes ".light_white.on_blue
7
- puts " ".light_white.on_blue
5
+ require 'colorized_routes/controller'
6
+ require 'colorized_routes/route'
7
+ puts " ".light_white.on_blue
8
+ puts " COLORIZED ROUTES ".light_white.on_blue
9
+ puts " github: https://github.com/joshtate04/colorized_routes ".light_white.on_blue
10
+ puts " ".light_white.on_blue
11
+ puts ""
8
12
 
9
13
 
10
14
  Rake::Task['routes'].clear
@@ -12,44 +16,28 @@ task :routes do
12
16
  all_routes = Rails.application.routes.routes.to_a
13
17
  all_routes.reject! { |route| route.verb.nil? || route.path.spec.to_s == '/assets' }
14
18
  all_routes.select! { |route| ENV['CONTROLLER'].nil? || route.defaults[:controller].to_s == ENV['CONTROLLER'] }
15
- print "\r"
16
- puts " ".black.on_black
17
- max_widths = {
18
- names: (all_routes.map { |route| route.name.to_s.length }.max),
19
- verbs: (6),
20
- paths: (all_routes.map { |route| route.path.spec.to_s.gsub(" ","").length }.max),
21
- controllers: (all_routes.map { |route| route.defaults[:controller].to_s.length }.max),
22
- actions: (all_routes.map { |route| route.defaults[:action].to_s.length }.max)
23
- }
24
-
25
- all_routes.group_by {|route| route.defaults[:controller]}.each_value do |group|
26
- print "Controller: ".light_white
27
- puts " #{group.first.defaults[:controller].to_s} ".colorize(color: :light_white).colorize(background: :blue).colorize(mode: :bold)
28
- group.each do |route|
29
- # VERBS (GET/POST/DELETE/PATCH/ETC)
30
- print "#{route.verb.inspect.gsub(/^.{2}|.{2}$/, "").center(max_widths[:verbs])}".light_red
31
- print " | ".light_white
32
- # PATHS
33
- path = route.path.spec.to_s.gsub("(.:format)","")
34
- print "#{path.ljust(max_widths[:paths]).split('/').map{|p| p.light_blue}.join('/'.green)}"
35
-
36
- print " | ".light_white
37
19
 
38
- # PATH NAMES
39
- print "#{route.name.to_s.ljust(max_widths[:names])}".yellow
40
- print " | ".light_white
41
20
 
42
- # CONTROLLER ACTIONS
43
- print "#{route.defaults[:action].to_s}".light_green
21
+ controllers = []
22
+ widths = nil
44
23
 
45
- puts ""
24
+ all_routes.group_by {|route| route.defaults[:controller]}.each_value do |group|
25
+ routes = []
26
+ group.each do |route|
27
+ routes.push Route.new(
28
+ route.verb.inspect.gsub(/^.{2}|.{2}$/, ""),
29
+ route.path.spec.to_s.gsub("(.:format)",""),
30
+ route.name.to_s,
31
+ route.defaults[:action].to_s
32
+ )
46
33
  end
47
-
48
- puts ""
34
+ widths = Route.max_widths(routes,widths)
35
+ controllers.push(Controller.new(routes,group.first.defaults[:controller].to_s))
49
36
  end
50
- end
51
37
 
52
- #task :colorized_routes => :environment do
38
+ controllers.each {|c| c.display(widths)}
39
+ end
53
40
 
41
+ task :colorized_routes => :environment do
54
42
 
55
- #end
43
+ end
@@ -0,0 +1,50 @@
1
+ #module ColorizedRoutes
2
+ class Route
3
+ # The route will hold all the information for the path, action name, etc
4
+
5
+ def initialize verb, path, prefix, action
6
+ @verb = verb
7
+ @path = path
8
+ @prefix = prefix
9
+ @action = action
10
+ end
11
+
12
+ def display widths
13
+ print "#{@verb.center(widths[:verb])}".light_red
14
+ print " | ".light_white
15
+ print "#{@path.ljust(widths[:path]).split('/').map{|p| p.light_blue}.join('/'.green)}"
16
+ print " | ".light_white
17
+ print "#{@prefix.ljust(widths[:prefix])}".yellow
18
+ print " | ".light_white
19
+ print "#{@action}\n".light_green
20
+ end
21
+
22
+ def self.max_widths routes, existing_widths = nil
23
+ types = [:verb,:path,:prefix,:action]
24
+ widths = existing_widths.nil? ? Hash[types.map{|t| [t,0]}] : existing_widths
25
+
26
+ routes.each do |route|
27
+ types.each do |type|
28
+ widths[type] = widths[type] < route.send(type).length ? route.send(type).length : widths[type]
29
+ end
30
+ end
31
+ widths
32
+ end
33
+
34
+ def verb
35
+ @verb
36
+ end
37
+
38
+ def path
39
+ @path
40
+ end
41
+
42
+ def prefix
43
+ @prefix
44
+ end
45
+
46
+ def action
47
+ @action
48
+ end
49
+ end
50
+ #end
@@ -1,3 +1,3 @@
1
1
  module ColorizedRoutes
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorized_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Tate
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-06 00:00:00.000000000 Z
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,8 +72,10 @@ files:
72
72
  - bin/setup
73
73
  - colorized_routes.gemspec
74
74
  - lib/colorized_routes.rb
75
+ - lib/colorized_routes/controller.rb
75
76
  - lib/colorized_routes/rails/tasks/colorized_routes.rake
76
77
  - lib/colorized_routes/railtie.rb
78
+ - lib/colorized_routes/route.rb
77
79
  - lib/colorized_routes/version.rb
78
80
  homepage: http://github.com/joshtate04/colorized_routes
79
81
  licenses: