color_routes 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.md +69 -0
- data/Rakefile +150 -0
- data/color_routes.gemspec +34 -0
- data/lib/color_routes.rb +11 -0
- data/lib/color_routes/rails/tasks/color_routes.rake +61 -0
- data/lib/color_routes/string_ansi.rb +41 -0
- metadata +72 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) Nicolas Oga
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
RakeGem
|
2
|
+
=======
|
3
|
+
|
4
|
+
# DESCRIPTION
|
5
|
+
|
6
|
+
Ever wanted to manage your RubyGem in a sane way without having to resort to
|
7
|
+
external dependencies like Jeweler or Hoe? Ever thought that Rake and a hand
|
8
|
+
crafted gemspec should be enough to deal with these problems? If so, then
|
9
|
+
RakeGem is here to make your life awesome!
|
10
|
+
|
11
|
+
RakeGem is not a library. It is just a few simple file templates that you can
|
12
|
+
copy into your project and easily customize to match your specific needs. It
|
13
|
+
ships with a few Rake tasks to help you keep your gemspec up-to-date, build
|
14
|
+
a gem, and release your library and gem to the world.
|
15
|
+
|
16
|
+
RakeGem assumes you are using Git. This makes the Rake tasks easy to write. If
|
17
|
+
you are using something else, you should be able to get RakeGem up and running
|
18
|
+
with your system without too much editing.
|
19
|
+
|
20
|
+
The RakeGem tasks were inspired by the
|
21
|
+
[Sinatra](http://github.com/sinatra/sinatra) project.
|
22
|
+
|
23
|
+
# INSTALLATION
|
24
|
+
|
25
|
+
Take a look at `Rakefile` and `NAME.gemspec`. For new projects, you can start
|
26
|
+
with these files and edit a few lines to make them fit into your library. If
|
27
|
+
you have an existing project, you'll probably want to take the RakeGem
|
28
|
+
versions and copy any custom stuff from your existing Rakefile and gemspec
|
29
|
+
into them. As long as you're careful, the rake tasks should keep working.
|
30
|
+
|
31
|
+
# ASSUMPTIONS
|
32
|
+
|
33
|
+
RakeGem makes a few assumptions. You will either need to satisfy these
|
34
|
+
assumptions or modify the rake tasks to work with your setup.
|
35
|
+
|
36
|
+
You should have a file named `lib/NAME.rb` (where NAME is the name of your
|
37
|
+
library) that contains a version line. It should look something like this:
|
38
|
+
|
39
|
+
module NAME
|
40
|
+
VERSION = '0.1.0'
|
41
|
+
end
|
42
|
+
|
43
|
+
It is important that you use the constant `VERSION` and that it appear on a
|
44
|
+
line by itself.
|
45
|
+
|
46
|
+
# UPDATING THE VERSION
|
47
|
+
|
48
|
+
In order to make a new release, you'll want to update the version. With
|
49
|
+
RakeGem, you only need to do that in the `lib/NAME.rb` file. Everything else
|
50
|
+
will use this find the canonical version of the library.
|
51
|
+
|
52
|
+
# TASKS
|
53
|
+
|
54
|
+
RakeGem provides three rake tasks:
|
55
|
+
|
56
|
+
`rake gemspec` will update your gemspec with the latest version (taken from
|
57
|
+
the `lib/NAME.rb` file) and file list (as reported by `git ls-files`).
|
58
|
+
|
59
|
+
`rake build` will update your gemspec, build your gemspec into a gem, and
|
60
|
+
place it in the `pkg` directory.
|
61
|
+
|
62
|
+
`rake release` will update your gemspec, build your gem, make a commit with
|
63
|
+
the message `Release 0.1.0` (with the correct version, obviously), tag the
|
64
|
+
commit with `v0.1.0` (again with the correct version), and push the `master`
|
65
|
+
branch and new tag to `origin`.
|
66
|
+
|
67
|
+
Keep in mind that these are just simple Rake tasks and you can edit them
|
68
|
+
however you please. Don't want to auto-commit or auto-push? Just delete those
|
69
|
+
lines. You can bend RakeGem to your own needs. That's the whole point!
|
data/Rakefile
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
#############################################################################
|
6
|
+
#
|
7
|
+
# Helper functions
|
8
|
+
#
|
9
|
+
#############################################################################
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
17
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def date
|
21
|
+
Date.today.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def rubyforge_project
|
25
|
+
name
|
26
|
+
end
|
27
|
+
|
28
|
+
def gemspec_file
|
29
|
+
"#{name}.gemspec"
|
30
|
+
end
|
31
|
+
|
32
|
+
def gem_file
|
33
|
+
"#{name}-#{version}.gem"
|
34
|
+
end
|
35
|
+
|
36
|
+
def replace_header(head, header_name)
|
37
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
38
|
+
end
|
39
|
+
|
40
|
+
#############################################################################
|
41
|
+
#
|
42
|
+
# Standard tasks
|
43
|
+
#
|
44
|
+
#############################################################################
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/testtask'
|
49
|
+
Rake::TestTask.new(:test) do |test|
|
50
|
+
test.libs << 'lib' << 'test'
|
51
|
+
test.pattern = 'test/**/test_*.rb'
|
52
|
+
test.verbose = true
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Generate RCov test coverage and open in your browser"
|
56
|
+
task :coverage do
|
57
|
+
require 'rcov'
|
58
|
+
sh "rm -fr coverage"
|
59
|
+
sh "rcov test/test_*.rb"
|
60
|
+
sh "open coverage/index.html"
|
61
|
+
end
|
62
|
+
|
63
|
+
require 'rdoc/task'
|
64
|
+
Rake::RDocTask.new do |rdoc|
|
65
|
+
rdoc.rdoc_dir = 'rdoc'
|
66
|
+
rdoc.title = "#{name} #{version}"
|
67
|
+
rdoc.rdoc_files.include('README*')
|
68
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Open an irb session preloaded with this library"
|
72
|
+
task :console do
|
73
|
+
sh "irb -rubygems -r ./lib/#{name}.rb"
|
74
|
+
end
|
75
|
+
|
76
|
+
#############################################################################
|
77
|
+
#
|
78
|
+
# Custom tasks (add your own tasks here)
|
79
|
+
#
|
80
|
+
#############################################################################
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
#############################################################################
|
85
|
+
#
|
86
|
+
# Packaging tasks
|
87
|
+
#
|
88
|
+
#############################################################################
|
89
|
+
|
90
|
+
desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
|
91
|
+
task :release => :build do
|
92
|
+
unless `git branch` =~ /^\* master$/
|
93
|
+
puts "You must be on the master branch to release!"
|
94
|
+
exit!
|
95
|
+
end
|
96
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
97
|
+
sh "git tag v#{version}"
|
98
|
+
sh "git push origin master"
|
99
|
+
sh "git push origin v#{version}"
|
100
|
+
sh "gem push pkg/#{name}-#{version}.gem"
|
101
|
+
end
|
102
|
+
|
103
|
+
desc "Build #{gem_file} into the pkg directory"
|
104
|
+
task :build => :gemspec do
|
105
|
+
sh "mkdir -p pkg"
|
106
|
+
sh "gem build #{gemspec_file}"
|
107
|
+
sh "mv #{gem_file} pkg"
|
108
|
+
end
|
109
|
+
|
110
|
+
desc "Generate #{gemspec_file}"
|
111
|
+
task :gemspec => :validate do
|
112
|
+
# read spec file and split out manifest section
|
113
|
+
spec = File.read(gemspec_file)
|
114
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
115
|
+
|
116
|
+
# replace name version and date
|
117
|
+
replace_header(head, :name)
|
118
|
+
replace_header(head, :version)
|
119
|
+
replace_header(head, :date)
|
120
|
+
#comment this out if your rubyforge_project has a different name
|
121
|
+
replace_header(head, :rubyforge_project)
|
122
|
+
|
123
|
+
# determine file list from git ls-files
|
124
|
+
files = `git ls-files`.
|
125
|
+
split("\n").
|
126
|
+
sort.
|
127
|
+
reject { |file| file =~ /^\./ }.
|
128
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
129
|
+
map { |file| " #{file}" }.
|
130
|
+
join("\n")
|
131
|
+
|
132
|
+
# piece file back together and write
|
133
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
134
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
135
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
136
|
+
puts "Updated #{gemspec_file}"
|
137
|
+
end
|
138
|
+
|
139
|
+
desc "Validate #{gemspec_file}"
|
140
|
+
task :validate do
|
141
|
+
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
142
|
+
unless libfiles.empty?
|
143
|
+
puts "Directory `lib` should only contain a `#{name}.rb` file and a `#{name}` dir."
|
144
|
+
exit!
|
145
|
+
end
|
146
|
+
unless Dir['VERSION*'].empty?
|
147
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
148
|
+
exit!
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
|
+
s.rubygems_version = '1.3.5'
|
5
|
+
|
6
|
+
s.name = 'color_routes'
|
7
|
+
s.version = '0.0.2'
|
8
|
+
s.date = '2012-01-13'
|
9
|
+
s.rubyforge_project = 'color_routes'
|
10
|
+
|
11
|
+
s.summary = "Colorize rake routes output for rails."
|
12
|
+
s.description = "Colorize rake routes output for rails."
|
13
|
+
|
14
|
+
s.authors = ["Nicolas Oga"]
|
15
|
+
s.email = '2112.oga@gmail.com'
|
16
|
+
s.homepage = 'http://nicooga.github.com/NAME'
|
17
|
+
|
18
|
+
s.require_paths = %w[lib]
|
19
|
+
|
20
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
21
|
+
s.extra_rdoc_files = %w[README.md LICENSE]
|
22
|
+
|
23
|
+
# = MANIFEST =
|
24
|
+
s.files = %w[
|
25
|
+
LICENSE
|
26
|
+
README.md
|
27
|
+
Rakefile
|
28
|
+
color_routes.gemspec
|
29
|
+
lib/color_routes.rb
|
30
|
+
lib/color_routes/rails/tasks/color_routes.rake
|
31
|
+
lib/color_routes/string_ansi.rb
|
32
|
+
]
|
33
|
+
# = MANIFEST =
|
34
|
+
end
|
data/lib/color_routes.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
|
2
|
+
task :color_routes => :environment do
|
3
|
+
|
4
|
+
Rails.application.reload_routes!
|
5
|
+
all_routes = Rails.application.routes.routes
|
6
|
+
|
7
|
+
if ENV['CONTROLLER']
|
8
|
+
all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] }
|
9
|
+
end
|
10
|
+
|
11
|
+
routes = all_routes.collect do |route|
|
12
|
+
reqs = route.requirements.dup
|
13
|
+
reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
|
14
|
+
{:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
|
15
|
+
end
|
16
|
+
|
17
|
+
# Skip the route if it's internal info route
|
18
|
+
routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} }
|
19
|
+
|
20
|
+
route_rows = routes.map do |r|
|
21
|
+
[
|
22
|
+
r[:name].presence || "-",
|
23
|
+
r[:verb].presence || "-",
|
24
|
+
r[:path].presence || "-",
|
25
|
+
r[:reqs]
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
# concede ruby strings ANSI superpowers!
|
30
|
+
require 'color_routes/string_ansi'
|
31
|
+
|
32
|
+
# TODO: Extract table creation to a separate class.
|
33
|
+
route_rows.group_by { |table| table[3][:controller] }.each do |controller, route_table|
|
34
|
+
puts((controller ? controller.camelize : "No Specific Controller").color(:red))
|
35
|
+
|
36
|
+
route_table.map! do |row|
|
37
|
+
name = row[0]
|
38
|
+
verb = row[1].color(:red)
|
39
|
+
path = row[2].gsub(/(:[^\(\)\/]+)/) do $1.color(:cyan) end
|
40
|
+
path = path.gsub(/([\/\.\(\)])/) do $1.color(:brown) end
|
41
|
+
reqs = "{".color(:blue) + " #{row[3].map { |k, v| "#{k.inspect.color(:magenta)} #{"=>".color(:blue)} #{v.inspect.color(:white)}" }.sort.reverse.join(", ") }" + " }".color(:blue)
|
42
|
+
[name, verb, path, reqs]
|
43
|
+
end
|
44
|
+
|
45
|
+
widths = [
|
46
|
+
route_table.map{ |r| r[0].ansi_length }.max,
|
47
|
+
route_table.map{ |r| r[1].ansi_length }.max,
|
48
|
+
route_table.map{ |r| r[2].ansi_length }.max,
|
49
|
+
route_table.map{ |r| r[3].ansi_length }.max
|
50
|
+
]
|
51
|
+
widths.map! do |w| w < 6 ? 6 : w end
|
52
|
+
|
53
|
+
puts "+#{'-'*(widths[0]+2)}+#{'-'*(widths[1]+2)}+#{'-'*(widths[2]+2)}+#{'-'*(widths[3]-4)}+"
|
54
|
+
route_table.each do |r|
|
55
|
+
puts "| #{r[0].ansi_rjust(widths[0])} | #{r[1].ansi_ljust(widths[1])} | #{r[2].ansi_ljust(widths[2])} | #{r[3].ansi_ljust(widths[3])} |"
|
56
|
+
end
|
57
|
+
puts "+#{'-'*(widths[0]+2)}+#{'-'*(widths[1]+2)}+#{'-'*(widths[2]+2)}+#{'-'*(widths[3]-4)}+"
|
58
|
+
|
59
|
+
puts
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ColorRoutes
|
2
|
+
|
3
|
+
# Some extensions to String to deal with ANSI colors.
|
4
|
+
module StringANSI
|
5
|
+
|
6
|
+
COLORS = {
|
7
|
+
:black => 30,
|
8
|
+
:red => 31,
|
9
|
+
:green => 32,
|
10
|
+
:brown => 33,
|
11
|
+
:blue => 34,
|
12
|
+
:magenta => 35,
|
13
|
+
:cyan => 36,
|
14
|
+
:gray => 37
|
15
|
+
}
|
16
|
+
|
17
|
+
def color(color)
|
18
|
+
code = "\033[#{COLORS[color]}m"
|
19
|
+
end_code = "\033[0m"
|
20
|
+
"#{code}#{self}#{end_code}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def ansi_length
|
24
|
+
gsub(/\033\[\d+m/, "").length
|
25
|
+
end
|
26
|
+
|
27
|
+
def ansi_ljust(n)
|
28
|
+
ljust(n + length - ansi_length)
|
29
|
+
end
|
30
|
+
|
31
|
+
def ansi_rjust(n)
|
32
|
+
rjust(n + length - ansi_length)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
class String
|
40
|
+
include ColorRoutes::StringANSI
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: color_routes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nicolas Oga
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-13 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Colorize rake routes output for rails.
|
22
|
+
email: 2112.oga@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.md
|
29
|
+
- LICENSE
|
30
|
+
files:
|
31
|
+
- LICENSE
|
32
|
+
- README.md
|
33
|
+
- Rakefile
|
34
|
+
- color_routes.gemspec
|
35
|
+
- lib/color_routes.rb
|
36
|
+
- lib/color_routes/rails/tasks/color_routes.rake
|
37
|
+
- lib/color_routes/string_ansi.rb
|
38
|
+
homepage: http://nicooga.github.com/NAME
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: color_routes
|
67
|
+
rubygems_version: 1.8.10
|
68
|
+
signing_key:
|
69
|
+
specification_version: 2
|
70
|
+
summary: Colorize rake routes output for rails.
|
71
|
+
test_files: []
|
72
|
+
|