Permalink
Browse files

Release 1.0.0

  • Loading branch information...
1 parent 38711c0 commit e7146f2fd4734c35133ed92ac33ad205e3636c22 @nicooga committed Oct 23, 2012
View
8 README.md
@@ -7,6 +7,10 @@ ColorRoutes is just a little library bundled with the necessary code to turn the
Have fun with it!
-# DEMO!
+# DEMO
-<img src="https://github.com/nicooga/color_routes/raw/master/doc/demo.png" title="Example output" alt="Example output" />
+rake routes normal output:
+<img src="https://github.com/nicooga/color_routes/raw/master/doc/demo1.png" title="Example output" alt="Example output" />
+
+rake color_routes output:
+<img src="https://github.com/nicooga/color_routes/raw/master/doc/demo2.png" title="Example output" alt="Example output" />
View
11 color_routes.gemspec
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
s.rubygems_version = '1.3.5'
s.name = 'color_routes'
- s.version = '0.0.2'
- s.date = '2012-01-22'
+ s.version = '1.0.0'
+ s.date = '2012-10-23'
s.rubyforge_project = 'color_routes'
s.summary = "Colorize rake routes output for rails."
@@ -19,17 +19,16 @@ Gem::Specification.new do |s|
s.require_paths = %w[lib]
s.rdoc_options = ["--charset=UTF-8"]
- s.extra_rdoc_files = %w[README.md LICENSE doc/demo.png]
-
- s.add_dependency('tablizer', ["~> 1.0.2"])
+ s.extra_rdoc_files = %w[README.md LICENSE doc/demo1.png doc/demo2.png]
# = MANIFEST =
s.files = %w[
LICENSE
README.md
Rakefile
color_routes.gemspec
- doc/demo.png
+ doc/demo1.png
+ doc/demo2.png
lib/color_routes.rb
lib/color_routes/rails/tasks/color_routes.rake
]
View
BIN doc/demo.png
Deleted file not rendered
View
BIN doc/demo1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN doc/demo2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2 lib/color_routes.rb
@@ -1,5 +1,5 @@
module ColorRoutes
- VERSION="0.0.2"
+ VERSION="1.0.0"
module Rails
class Railtie < ::Rails::Railtie
View
74 lib/color_routes/rails/tasks/color_routes.rake
@@ -1,54 +1,36 @@
-desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
-task :color_routes => :environment do
- require 'tablizer'
- Rails.application.reload_routes!
- all_routes = Rails.application.routes.routes
+desc 'Pretty version on rails rake routes.'
- if ENV['CONTROLLER']
- all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] }
- end
-
- routes = all_routes.collect do |route|
- reqs = route.requirements.dup
- reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
- {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
- end
-
- # Skip the route if it's internal info route
- routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} }
+EMK="\033[1;30m"
+EMR="\033[1;31m"
+EMG="\033[1;32m"
+EMY="\033[1;33m"
+EMB="\033[1;34m"
+EMM="\033[1;35m"
+EMC="\033[1;36m"
+EMW="\033[1;37m"
+NOCOLOR = "\033[0m"
- route_rows = routes.map do |r|
- [
- r[:name].presence || "-",
- r[:verb].presence || "-",
- r[:path].presence || "-",
- r[:reqs]
- ]
- end
+task :color_routes => :environment do
+ Rails.application.reload_routes!
+ all_routes = Rails.application.routes.routes.to_a
+ all_routes.reject! {|route| route.verb == nil or route.path.spec.to_s == '/assets'}
- route_rows.group_by { |table| table[3][:controller] }.each do |controller, route_table|
- puts((controller ? controller.camelize : "No Specific Controller").color(:red))
+ names_max_width = all_routes.map {|route| route.name.to_s.length}.max
+ verbs_max_width = 6
+ paths_max_width = all_routes.map {|route| route.path.spec.to_s.length}.max
+ controllers_max_width = all_routes.map {|route| route.defaults[:controller].length}.max
+ actions_max_width = all_routes.map {|route| route.defaults[:action].length}.max
- table = Tablizer::Table.new [], :header => true
+ all_routes.group_by {|route| route.defaults[:controller]}.each_value do |group|
+ puts EMK + "\nCONTROLLER: " + EMW + group.first.defaults[:controller] + NOCOLOR
+ group.each do |route|
+ name = EMC + route.name.to_s.rjust(names_max_width) + NOCOLOR
+ verb = EMY + route.verb.inspect.gsub(/^.{2}|.{2}$/,"").center(verbs_max_width) + NOCOLOR
+ path = EMR + route.path.spec.to_s.ljust(paths_max_width).gsub(/(\.?:[^\(\)\/]+)/){EMB + $1 + EMR} + NOCOLOR
+ action = EMW + route.defaults[:action].ljust(actions_max_width) + NOCOLOR
- table[0, 0] = "Name"
- table[1, 0] = "Verb"
- table[2, 0] = "Path"
- table[3, 0] = "Requirements"
-
- route_table.each_with_index do |row, row_index|
- name = row[0]
- verb = row[1].color(:red)
- path = row[2].gsub(/(:[^\(\)\/]+)/) do $1.color(:cyan) end
- path = path.gsub(/([\/\.\(\)])/) do $1.color(:brown) end
- reqs = "{".color(:blue) + " #{row[3].map { |k, v| "#{k.inspect.color(:magenta)} #{"=>".color(:blue)} #{v.inspect.color(:gray)}" }.sort.reverse.join(", ") }" + " }".color(:blue)
-
- table[0, row_index+1] = name
- table[1, row_index+1] = verb
- table[2, row_index+1] = path
- table[3, row_index+1] = reqs
+ puts "|#{name}|#{verb}|#{path}|#{action}"
end
-
- puts table
end
+
end

0 comments on commit e7146f2

Please sign in to comment.