bri 0.4.1 → 0.4.2

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: 9c9a3a5911ab72b9546ab330dd5ee4513526deaecb4e508b818cef6f28b03283
4
- data.tar.gz: 52dd0d1b13b6e74b54efebb4364ff56619776db6a8348f6ca8ab8aab67231fbf
3
+ metadata.gz: 2a207a768943836bb63dea1964e177e4eef7dbfa7e07c26b76fa3cf254c1db86
4
+ data.tar.gz: 6bb5e69bdb8bd7050e179cf51d49084facd31b8a900b06ddcacc030503718fee
5
5
  SHA512:
6
- metadata.gz: 548798d2184a8c2f6543d7164fafcee5ee2699ffee6547aa16a982387aea81307755c5b9bef95cf667b3d80614f3d2bf8f18a21fe727c14f593a1207f6163f02
7
- data.tar.gz: 1836149121859a7d8b66a19dbbd5c0b18b536c3c4af440b6e7c1c5bac298fd40903ecd240a6cdb9bf46fb8f02914378bbf0ecb68fe024b030c0fc5d848496f3a
6
+ metadata.gz: 4388dd1a1a040b7f51d49ddc67131d3f0865e39a3120e9816373490bddb408aa26b40b32a946b3246dacdb98113503165a9cdee368d248d07602dccd6bb685cc
7
+ data.tar.gz: 68b5edcf218e9c63545e253ce697851d0653f9c50104656962552566e8674ffe9848eff6c42e4dfbfe55b6b2ab6d9aa53323a48d43d8ba29a948fefce2cb7abf
data/Changelog CHANGED
@@ -1,3 +1,12 @@
1
+ 0.4.2
2
+ - Fix broken --list-names option
3
+ - Fix broken multiple choice display
4
+ - Remove comma separators from method lists in order to ease copy and paste
5
+ actions
6
+ - List multiple choices one per line for easier visual searching
7
+ - More internal cleanups
8
+ - Add caveat to the readme
9
+
1
10
  0.4.1
2
11
  - Modernize and refactor code
3
12
  - Show extends of classes in rendered documentation
@@ -1,11 +1,21 @@
1
1
  = What is this ?
2
- During the days of Ruby 1.8, the ri command was slow. I mean really slow. Glacially. Starting a web browser and looking up a class or method description on ruby-doc.org often felt faster.
2
+ During the days of Ruby 1.8, the ri command was slow. I mean really slow.
3
+ Glacially. Starting a web browser and looking up a class or method description
4
+ on ruby-doc.org often felt faster.
3
5
 
4
- Then Mauricio Fernandez produced fastri and qri that produced results a whole lot faster than the native ri tool. Unfortunately, Mauricio seems to have lost interest and didn't port fastri to ruby 1.9. There are patches porting fastri to 1.9.1, but they are iffy and don't work well with 1.9.2 and the new rdoc cache format.
6
+ Then Mauricio Fernandez produced fastri and qri that produced results a whole
7
+ lot faster than the native ri tool. Unfortunately, Mauricio seems to have lost
8
+ interest and didn't port fastri to ruby 1.9. There are patches porting fastri
9
+ to 1.9.1, but they are iffy and don't work well with 1.9.2 and the new rdoc
10
+ cache format.
5
11
 
6
- Now with ruby 1.9 and the rdoc 2.x/3.x gem ri is very responsive. However the output format looks like darkfish without the HTML and uses up a lot of space. And subjectively, it's ugly.
12
+ With ruby 1.9 and rdoc 2.x/3.x ri became very responsive. However the output
13
+ format looks like darkfish without the HTML and uses up a lot of space.
7
14
 
8
- This is where bri comes in: it tries to emulate fastri/qris output format and lookup patterns while using the new rdoc 2.x/3.x infrastructure.
15
+ And subjectively, it's ugly.
16
+
17
+ This is where bri comes in: it tries to emulate fastri/qris output format and
18
+ lookup patterns while using the more current rdoc infrastructure.
9
19
 
10
20
  To compare, do 'ri Array' and 'bri Array' and see which appeals more to you.
11
21
 
@@ -29,6 +39,12 @@ Bri is a Beautiful RI formatter.
29
39
  # the given search term, and finally looking for the term
30
40
  # anywhere in the method name
31
41
 
42
+ = Caveats
43
+ I'm reviving this project that has been left rotting for nearly 8 years.
44
+ Due to bitrot, changes in rdoc internals and trying to understand my code
45
+ from back then, some unexpected hickups may arise. All bug reports with
46
+ references to problematic ri class or method docs are welcome.
47
+
32
48
  = Requirements
33
49
  * Ruby 2.6 or later
34
50
  * rdoc 6.1 or later
data/TODO CHANGED
@@ -7,3 +7,5 @@
7
7
  highlight these (e.g. Object#send and Object.new)
8
8
  - Add display of in_files
9
9
  - Add display of module constant aliases
10
+ - Rewrite the search code into something understandable and maintainable
11
+ (sleep deprivation is one hell of a drug)
data/lib/bri.rb CHANGED
@@ -1,40 +1,16 @@
1
- $: << File.dirname( __FILE__ )
2
1
  require 'erb'
3
2
  require 'term/ansicolor'
4
3
 
5
-
6
- require 'bri/renderer'
7
- require 'bri/mall'
8
- require 'bri/matcher'
9
- require 'bri/templates'
10
- require 'bri/search'
11
- require 'bri/match'
4
+ require_relative 'bri/renderer'
5
+ require_relative 'bri/mall'
6
+ require_relative 'bri/matcher'
7
+ require_relative 'bri/templates'
8
+ require_relative 'bri/search'
9
+ require_relative 'bri/match'
12
10
 
13
11
  module Bri
14
12
  DEFAULT_WIDTH = 72
15
13
 
16
- def self.format_elements( array )
17
- rows = []
18
- row = []
19
- row_length = 0
20
-
21
- array.each do |element|
22
- element_length_with_separator = element.length + 2
23
-
24
- if row_length + element_length_with_separator >= Bri.width
25
- rows << row
26
- row = []
27
- row_length = 0
28
- end
29
-
30
- row << element
31
- row_length += element_length_with_separator
32
- end
33
-
34
- rows << row
35
- rows
36
- end
37
-
38
14
  def self.ri( query )
39
15
  results = Bri::Matcher.new( query ).find
40
16
 
@@ -43,6 +19,7 @@ module Bri
43
19
  elsif results.size == 1
44
20
  results.first.to_s
45
21
  else
22
+ qualified_methods = results.map(&:full_name).sort
46
23
  ERB.new( Bri::Templates::MULTIPLE_CHOICES, nil, '<>' ).result( binding )
47
24
  end
48
25
  end
@@ -13,17 +13,17 @@ module Bri
13
13
  end
14
14
 
15
15
  def class_methods
16
- stores.flat_map do |store|
17
- store.class_methods.map do |klass, methods|
18
- methods.map { |method| "#{klass}.#{method}" }
16
+ stores.each_with_object( [] ) do |store, result|
17
+ store.class_methods.each do |klass, methods|
18
+ methods.each { |method| result << "#{klass}.#{method}" }
19
19
  end
20
20
  end.uniq
21
21
  end
22
22
 
23
23
  def instance_methods
24
- stores.flat_map do |store|
25
- store.instance_methods.map do |klass, methods|
26
- methods.map { |method| "#{klass}##{method}" }
24
+ stores.each_with_object( [] ) do |store, result|
25
+ store.instance_methods.each do |klass, methods|
26
+ methods.each { |method| result << "#{klass}##{method}" }
27
27
  end
28
28
  end.uniq
29
29
  end
@@ -1,3 +1,3 @@
1
- require 'bri/match/base'
2
- require 'bri/match/class'
3
- require 'bri/match/method'
1
+ require_relative 'match/base'
2
+ require_relative 'match/class'
3
+ require_relative 'match/method'
@@ -2,6 +2,8 @@ require 'strscan'
2
2
 
3
3
  module Bri
4
4
  module Renderer
5
+ Color = ::Term::ANSIColor
6
+
5
7
  INDENT = ' ' * 2
6
8
  INDENT_WIDTH = 2
7
9
  LOWER_ALPHABET = ('a'..'z').to_a.map { |char| "#{char}." }.freeze
@@ -100,41 +102,44 @@ module Bri
100
102
  end
101
103
 
102
104
  def self.replace_markup( text )
103
- text.gsub!( /(?<!\\)<(?:tt|code)>/, Term::ANSIColor.cyan )
104
- text.gsub!( /(?<!\\)<\/(?:tt|code)>/, Term::ANSIColor.reset )
105
+ text.gsub!( /(?<!\\)<(?:tt|code)>/, Color.cyan )
106
+ text.gsub!( /(?<!\\)<\/(?:tt|code)>/, Color.reset )
105
107
 
106
- text.gsub!( /(?<!\\)<b>/, Term::ANSIColor.bold )
107
- text.gsub!( /(?<!\\)<\/b>/, Term::ANSIColor.reset )
108
+ text.gsub!( /(?<!\\)<b>/, Color.bold )
109
+ text.gsub!( /(?<!\\)<\/b>/, Color.reset )
108
110
 
109
- text.gsub!( /(?<!\\)<(?:em|i)>/, Term::ANSIColor.yellow )
110
- text.gsub!( /(?<!\\)<\/(?:em|i)>/, Term::ANSIColor.reset )
111
+ text.gsub!( /(?<!\\)<(?:em|i)>/, Color.yellow )
112
+ text.gsub!( /(?<!\\)<\/(?:em|i)>/, Color.reset )
111
113
 
112
- text.gsub!( "<h>", Term::ANSIColor.green )
113
- text.gsub!( "</h>", Term::ANSIColor.reset )
114
+ text.gsub!( "<h>", Color.green )
115
+ text.gsub!( "</h>", Color.reset )
114
116
 
115
117
  text.gsub!( "\\<", "<" )
116
118
 
119
+ text.gsub!( /(#\s*=>)(.*)/,
120
+ "#{Color.dark}\\1#{Color.reset}#{Color.bold}\\2#{Color.reset}" )
121
+
117
122
  text.gsub!( /(^|\s)\*(.*?[a-zA-Z0-9]+.*?)\*/,
118
- "\\1#{Term::ANSIColor.bold}\\2#{Term::ANSIColor.reset}" )
123
+ "\\1#{Color.bold}\\2#{Color.reset}" )
119
124
  text.gsub!( /(^|\s)\+(.*?[a-zA-Z0-9]+.*?)\+/,
120
- "\\1#{Term::ANSIColor.cyan}\\2#{Term::ANSIColor.reset}" )
125
+ "\\1#{Color.cyan}\\2#{Color.reset}" )
121
126
  text.gsub!( /(^|\s)_(.*?[a-zA-Z0-9]+.*?)_/,
122
- "\\1#{Term::ANSIColor.yellow}\\2#{Term::ANSIColor.reset}" )
127
+ "\\1#{Color.yellow}\\2#{Color.reset}" )
123
128
 
124
129
  text.gsub!( %r{\b((?:https?|ftp)://[-\w.?%&=/]+)\b},
125
- "#{Term::ANSIColor.underline}\\1#{Term::ANSIColor.reset}" )
130
+ "#{Color.underline}\\1#{Color.reset}" )
126
131
 
127
132
  text.gsub!( %r{\b(mailto:[-\w.%]+@[-\w.]+)\b},
128
- "#{Term::ANSIColor.underline}\\1#{Term::ANSIColor.reset}" )
133
+ "#{Color.underline}\\1#{Color.reset}" )
129
134
 
130
135
  text.gsub!( %r{\b((?<!:\/\/)www.[-\w.?%&=]+)\b},
131
- "#{Term::ANSIColor.underline}\\1#{Term::ANSIColor.reset}" )
136
+ "#{Color.underline}\\1#{Color.reset}" )
132
137
 
133
138
  text.gsub!( %r{\blink:(.*?)(\s|$)},
134
- "#{Term::ANSIColor.underline}\\1#{Term::ANSIColor.reset}\\2" )
139
+ "#{Color.underline}\\1#{Color.reset}\\2" )
135
140
 
136
141
  text.gsub!( %r{\{(.*?)\}\[(.*?)\]}, "\\1 (\\2)" )
137
- text.gsub!( %r{\[(#{Regexp.escape( Term::ANSIColor.underline )}.*?#{Regexp.escape( Term::ANSIColor.reset )})\]},
142
+ text.gsub!( %r{\[(#{Regexp.escape( Color.underline )}.*?#{Regexp.escape( Color.reset )})\]},
138
143
  " (\\1)" )
139
144
  text
140
145
  end
@@ -144,7 +149,7 @@ module Bri
144
149
  end
145
150
 
146
151
  def self.wrap_list( array, width = Bri.width )
147
- indent( wrap_to_width( array.join(", "), width ) )
152
+ indent( wrap_to_width( array.join(" "), width ) )
148
153
  end
149
154
 
150
155
  def self.wrap_to_width( styled_text, width )
@@ -1,5 +1,5 @@
1
- require 'bri/search/base'
2
- require 'bri/search/class'
3
- require 'bri/search/method'
4
- require 'bri/search/class_method'
5
- require 'bri/search/instance_method'
1
+ require_relative 'search/base'
2
+ require_relative 'search/class'
3
+ require_relative 'search/method'
4
+ require_relative 'search/class_method'
5
+ require_relative 'search/instance_method'
@@ -5,7 +5,7 @@ module Bri
5
5
  MULTIPLE_CHOICES =<<-EOT
6
6
  <%= Bri::Templates::Helpers.hrule( "Multiple choices:" ) %>
7
7
 
8
- <%= Bri::Renderer.wrap_list( qualified_methods.sort ) %>
8
+ <%= qualified_methods.sort.join("\n") %>
9
9
 
10
10
 
11
11
  EOT
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Riedel