betterroutes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/tasks/betterroutes.rake +56 -0
  2. metadata +73 -0
@@ -0,0 +1,56 @@
1
+ desc 'Better Routes -- A colorized version of Rake Routes'
2
+ require 'colorize'
3
+
4
+ task :broutes => :environment do
5
+
6
+ path_length = 0
7
+ verb_length = 0
8
+ name_length = 0
9
+ ca_length = 0
10
+ exclude = ['/assets', '/rails/info/properties']
11
+
12
+ # Determine column widths
13
+ Twotp::Application.routes.routes.each do |route|
14
+ path_length = route.path.gsub('(.:format)', '').length if route.path.gsub('(.:format)', '').length > path_length
15
+ verb_length = route.verb.length if route.verb.length > verb_length
16
+ name_length = route.name.to_s.length if route.name.to_s.length > name_length
17
+
18
+ if route.defaults != nil
19
+ controller_width = route.defaults[:controller].to_s.length
20
+ action_width = route.defaults[:action].to_s.length
21
+ ca_length = controller_width + action_width if (controller_width + action_width) > ca_length
22
+ end
23
+ end
24
+
25
+ # Header
26
+ output = "--PATH" << ("-" * (path_length - 5))
27
+ output << "|-METHOD" << ("-" * (verb_length - 5))
28
+ output << "|-NAME" << ("-" * (name_length - 3))
29
+ output << "|-CONTROLLER / ACTION" << ("-" * (ca_length - 4))
30
+ header = output.blue
31
+ puts header
32
+
33
+ # Routes
34
+ Twotp::Application.routes.routes.each do |route|
35
+
36
+ # Exclusion list
37
+ unless exclude.include? route.path.gsub('(.:format)', '')
38
+ output = "#{route.path.gsub('(.:format)', '')}".yellow
39
+ output << " " * (path_length - route.path.gsub('(.:format)', '').length)
40
+ output << " |".blue
41
+ output << " #{route.verb}".magenta
42
+ output << " " * (verb_length - route.verb.length)
43
+ output << " | ".blue
44
+ output << "#{route.name}".white
45
+ output << " " * (name_length - route.name.to_s.length)
46
+ output << " | ".blue
47
+ output << "C: ".red
48
+ output << route.defaults[:controller].to_s.green
49
+ output << ", A: ".red
50
+ output << route.defaults[:action].to_s.green
51
+ puts output
52
+ end
53
+ end
54
+ puts header
55
+
56
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: betterroutes
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Caedmon Judd
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-10-11 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: colorize
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ description: A better colorized, formatted visualization of the Rake routes listing.
33
+ email: caedmon@statebuilt.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files: []
39
+
40
+ files:
41
+ - lib/tasks/betterroutes.rake
42
+ has_rdoc: true
43
+ homepage:
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.6
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Better Rake routes listing in full color
72
+ test_files: []
73
+