colrou 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4c7367465b841f2060d90d41d9c8493c68ee82b95ffdcb4b67292e0323d7efc
4
- data.tar.gz: 7f78fe6baa21b74f75560c4e914cf809725f21c84a956e44267037dab21fa5e6
3
+ metadata.gz: 117b780b16ccd0157f77379e590164cd39c78ff94238863a3c7df37cba684ac0
4
+ data.tar.gz: 13219de4be890fd29b35bf7fca053c19d7be1d2049cadbf14acd2d73740d9e52
5
5
  SHA512:
6
- metadata.gz: 694ed42e1c1c0718192bc36ca74babbb00aac6b272cbd4b555bf16332baba1f2489d15f3eda65b38a3b9c4a4eddb971bffde2a0367ee4057599d33f0de6d9cec
7
- data.tar.gz: 8bf01225cb8d917d024f5551e0fb3baaeab5628148535eac0bacc2f75d20ea14c832d3dcd36ca23ef869ea6658e44cd1dd2020178a0c4e86ee446982748c85d9
6
+ metadata.gz: 55a25cdd099d84b86781caff4c3ed7229bdd95eaee14b069dd7c3e552e6cbd356ef77bc30913756201321457f5075c5b5606738773202bf357454c04725c4bbf
7
+ data.tar.gz: 6978e7a6767208f56e027cd31d2aae00dfb66e2f5fde7e1f059cc9e0e54cc6ea8072f5236a5b007a01edebf03fb7b6a1faee257f475ab0075ea25cf67a806141
data/README.md CHANGED
@@ -1,39 +1,57 @@
1
+ ![Gem Version](https://img.shields.io/gem/v/colrou.svg) ![License](https://img.shields.io/github/license/evaneykelen/colrou.svg)
2
+ ![Last Commit](https://img.shields.io/github/last-commit/evaneykelen/colrou.svg)
3
+
1
4
  # Colrou
2
5
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/colrou`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+ Colrou reformats output of `rails routes`. The name is a portmanteau of "colorized routes".
7
+
8
+ ## Example
4
9
 
5
- TODO: Delete this and the text above, and describe your gem
10
+ ![Example](https://user-images.githubusercontent.com/11846/54473866-ccc02600-47dd-11e9-9093-8ba1d9fe7d44.png)
6
11
 
7
12
  ## Installation
8
13
 
9
- Add this line to your application's Gemfile:
14
+ `gem install colrou`
10
15
 
11
- ```ruby
12
- gem 'colrou'
13
- ```
16
+ The `colrou` command operates on the output of the `rails routes` command.
17
+
18
+ It performs two operations:
14
19
 
15
- And then execute:
20
+ - HTTP verbs and path parameters are colorized
21
+ - Line breaks are inserted between controllers
16
22
 
17
- $ bundle
23
+ ## Usage examples
18
24
 
19
- Or install it yourself as:
25
+ `$ rails routes | colrou`
20
26
 
21
- $ gem install colrou
27
+ `$ rails routes -g posts | colrou`
22
28
 
23
- ## Usage
24
29
 
25
- TODO: Write usage instructions here
30
+ ## Color configuration
26
31
 
27
- ## Development
32
+ Place a file called `.colrou.yml` in your home directory (e.g. `~` on Unix) to configure output colors:
28
33
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+ See [here](https://misc.flogisoft.com/bash/tip_colors_and_formatting) for a nice overview of shell color codes.
32
47
 
33
- ## Contributing
48
+ ## Tip
34
49
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/colrou.
50
+ Add the following lines to e.g. `~/.bash_profile` (the location depends on your shell and OS):
36
51
 
37
- ## License
52
+ ```
53
+ alias rr='rails routes'
54
+ alias cr='colrou'
55
+ ```
38
56
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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
- VERBS_AND_COLORS = [
31
- { verb: "DELETE", color: RED },
32
- { verb: "GET", color: GREEN },
33
- { verb: "PATCH", color: PURPLE },
34
- { verb: "POST", color: YELLOW },
35
- { verb: "PUT", color: PURPLE }
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
- VERBS_AND_COLORS.each do |verb_and_color|
40
- verb = verb_and_color[: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
- "/#{CYAN}#{$~[:parameter].slice(1..-1)}#{RESET_COLOR}"
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
@@ -1,3 +1,3 @@
1
1
  module Colrou
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
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.1.1
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-03-16 00:00:00.000000000 Z
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