colrou 0.1.1 → 0.2.1
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 +4 -4
- data/README.md +37 -19
- data/lib/colrou/parse.rb +32 -13
- data/lib/colrou/version.rb +1 -1
- metadata +2 -3
- data/CHANGELOG.md +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 117b780b16ccd0157f77379e590164cd39c78ff94238863a3c7df37cba684ac0
|
4
|
+
data.tar.gz: 13219de4be890fd29b35bf7fca053c19d7be1d2049cadbf14acd2d73740d9e52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55a25cdd099d84b86781caff4c3ed7229bdd95eaee14b069dd7c3e552e6cbd356ef77bc30913756201321457f5075c5b5606738773202bf357454c04725c4bbf
|
7
|
+
data.tar.gz: 6978e7a6767208f56e027cd31d2aae00dfb66e2f5fde7e1f059cc9e0e54cc6ea8072f5236a5b007a01edebf03fb7b6a1faee257f475ab0075ea25cf67a806141
|
data/README.md
CHANGED
@@ -1,39 +1,57 @@
|
|
1
|
+
 
|
2
|
+

|
3
|
+
|
1
4
|
# Colrou
|
2
5
|
|
3
|
-
|
6
|
+
Colrou reformats output of `rails routes`. The name is a portmanteau of "colorized routes".
|
7
|
+
|
8
|
+
## Example
|
4
9
|
|
5
|
-
|
10
|
+

|
6
11
|
|
7
12
|
## Installation
|
8
13
|
|
9
|
-
|
14
|
+
`gem install colrou`
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
16
|
+
The `colrou` command operates on the output of the `rails routes` command.
|
17
|
+
|
18
|
+
It performs two operations:
|
14
19
|
|
15
|
-
|
20
|
+
- HTTP verbs and path parameters are colorized
|
21
|
+
- Line breaks are inserted between controllers
|
16
22
|
|
17
|
-
|
23
|
+
## Usage examples
|
18
24
|
|
19
|
-
|
25
|
+
`$ rails routes | colrou`
|
20
26
|
|
21
|
-
|
27
|
+
`$ rails routes -g posts | colrou`
|
22
28
|
|
23
|
-
## Usage
|
24
29
|
|
25
|
-
|
30
|
+
## Color configuration
|
26
31
|
|
27
|
-
|
32
|
+
Place a file called `.colrou.yml` in your home directory (e.g. `~` on Unix) to configure output colors:
|
28
33
|
|
29
|
-
|
34
|
+
```
|
35
|
+
http_verb_colors:
|
36
|
+
delete: "\e[91m"
|
37
|
+
get: "\e[92m"
|
38
|
+
patch: "\e[95m"
|
39
|
+
post: "\e[93m"
|
40
|
+
put: "\e[95m"
|
41
|
+
misc_colors:
|
42
|
+
reset: "\e[0m"
|
43
|
+
param: "\e[96m"
|
44
|
+
```
|
30
45
|
|
31
|
-
|
46
|
+
See [here](https://misc.flogisoft.com/bash/tip_colors_and_formatting) for a nice overview of shell color codes.
|
32
47
|
|
33
|
-
##
|
48
|
+
## Tip
|
34
49
|
|
35
|
-
|
50
|
+
Add the following lines to e.g. `~/.bash_profile` (the location depends on your shell and OS):
|
36
51
|
|
37
|
-
|
52
|
+
```
|
53
|
+
alias rr='rails routes'
|
54
|
+
alias cr='colrou'
|
55
|
+
```
|
38
56
|
|
39
|
-
|
57
|
+
You now only have to type `$ rr | cr` to colorize your routes.
|
data/lib/colrou/parse.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module Colrou
|
2
4
|
class Parse
|
3
5
|
def self.rails_routes
|
@@ -27,26 +29,30 @@ $ rails routes -g posts | colrou
|
|
27
29
|
CYAN = "\e[96m"
|
28
30
|
RESET_COLOR = "\e[0m"
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
COLORS = {
|
33
|
+
http_verb_colors: {
|
34
|
+
delete: RED,
|
35
|
+
get: GREEN,
|
36
|
+
patch: PURPLE,
|
37
|
+
post: YELLOW,
|
38
|
+
put: PURPLE
|
39
|
+
},
|
40
|
+
misc_colors: {
|
41
|
+
reset: RESET_COLOR,
|
42
|
+
param: CYAN
|
43
|
+
}
|
44
|
+
}
|
37
45
|
|
38
46
|
def self.colorize_verbs(line)
|
39
|
-
|
40
|
-
verb
|
41
|
-
color = verb_and_color[:color]
|
42
|
-
line.gsub!(/#{verb}/, "#{color}#{verb}#{RESET_COLOR}")
|
47
|
+
COLORS[:http_verb_colors].each do |verb, color|
|
48
|
+
line.gsub!(/#{verb.upcase}/, "#{color}#{verb.upcase}#{COLORS[:misc_colors][:reset]}")
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
46
52
|
# Uses https://ruby-doc.org/core-1.9.3/Regexp.html#class-Regexp-label-Capturing
|
47
53
|
def self.colorize_parameters(line)
|
48
54
|
line.gsub!(/(?<parameter>\/:\w+)/) do
|
49
|
-
"/#{
|
55
|
+
"/#{COLORS[:misc_colors][:param]}#{$~[:parameter].slice(1..-1)}#{COLORS[:misc_colors][:reset]}"
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
@@ -56,7 +62,20 @@ $ rails routes -g posts | colrou
|
|
56
62
|
controller_action.split("#")[0] # Get "controller" from "controller#action"
|
57
63
|
end
|
58
64
|
|
65
|
+
def self.prepare_colors
|
66
|
+
config_file = File.join(Dir.home, ".colrou.yml")
|
67
|
+
return unless File.file?(config_file)
|
68
|
+
config = YAML.load_file(File.join(Dir.home, ".colrou.yml"))
|
69
|
+
config["http_verb_colors"].each do |verb, color|
|
70
|
+
COLORS[:http_verb_colors][verb.to_sym] = color
|
71
|
+
end
|
72
|
+
config["misc_colors"].each do |attrib, color|
|
73
|
+
COLORS[:misc_colors][attrib.to_sym] = color
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
59
77
|
def self.parse
|
78
|
+
prepare_colors
|
60
79
|
prev_controller_name = nil
|
61
80
|
begin
|
62
81
|
while input = ARGF.gets
|
@@ -77,7 +96,7 @@ $ rails routes -g posts | colrou
|
|
77
96
|
end
|
78
97
|
end
|
79
98
|
rescue
|
80
|
-
puts "Invalid input"
|
99
|
+
puts "Invalid input (#{$!})"
|
81
100
|
end
|
82
101
|
end
|
83
102
|
end
|
data/lib/colrou/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colrou
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik van Eykelen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,7 +47,6 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
-
- CHANGELOG.md
|
51
50
|
- Gemfile
|
52
51
|
- Gemfile.lock
|
53
52
|
- LICENSE.txt
|
data/CHANGELOG.md
DELETED
File without changes
|