bri 0.1.1 → 0.1.2
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.
- data/TODO +0 -2
- data/bin/bri +27 -4
- data/lib/bri.rb +25 -2
- data/lib/bri/mall.rb +16 -0
- data/lib/bri/match/base.rb +2 -2
- data/lib/bri/match/class.rb +4 -3
- data/lib/bri/templates.rb +4 -4
- metadata +4 -4
data/TODO
CHANGED
data/bin/bri
CHANGED
@@ -1,9 +1,32 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'bri'
|
3
|
+
require 'optparse'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
@options = {
|
6
|
+
:list_classes => false,
|
7
|
+
:list_methods => false,
|
8
|
+
:list_names => false
|
9
|
+
}
|
10
|
+
|
11
|
+
def parse_options
|
12
|
+
parser = OptionParser.new do |opts|
|
13
|
+
opts.on( nil, "--classes", "List known classes" ) { |v| @options[:list_classes] = true }
|
14
|
+
opts.on( nil, "--methods", "List known methods" ) { |v| @options[:list_methods] = true }
|
15
|
+
opts.on( "-l", "--list-names", "List known namespaces/methods" ) { |v| @options[:list_names] = true }
|
16
|
+
opts.on( "-w", "--width [COLUMNS]", "Set the output width", Integer ) { |v| Bri.width = v.to_i - 8 }
|
17
|
+
opts.on_tail( "-h", "--help", "This help text" ) { puts opts; exit }
|
18
|
+
end
|
19
|
+
parser.parse!( ARGV )
|
7
20
|
end
|
8
21
|
|
9
|
-
|
22
|
+
parse_options
|
23
|
+
|
24
|
+
if @options[:list_classes]
|
25
|
+
puts Bri.list_classes
|
26
|
+
elsif @options[:list_methods]
|
27
|
+
puts Bri.list_methods
|
28
|
+
elsif @options[:list_names]
|
29
|
+
puts Bri.list_names
|
30
|
+
else
|
31
|
+
puts Bri.ri( ARGV[0] )
|
32
|
+
end
|
data/lib/bri.rb
CHANGED
@@ -10,7 +10,7 @@ require 'bri/search'
|
|
10
10
|
require 'bri/match'
|
11
11
|
|
12
12
|
module Bri
|
13
|
-
|
13
|
+
DEFAULT_WIDTH = 72
|
14
14
|
|
15
15
|
def self.format_elements( array )
|
16
16
|
rows = []
|
@@ -20,7 +20,7 @@ module Bri
|
|
20
20
|
array.each do |element|
|
21
21
|
element_length_with_separator = element.length + 2
|
22
22
|
|
23
|
-
if row_length + element_length_with_separator >=
|
23
|
+
if row_length + element_length_with_separator >= Bri.width
|
24
24
|
rows << row
|
25
25
|
row = []
|
26
26
|
row_length = 0
|
@@ -47,5 +47,28 @@ module Bri
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
def self.width
|
51
|
+
@@width ||= [ ( ENV['COLUMNS'] || 80 ) - 8, 1 ].max
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.width=( width )
|
55
|
+
@@width = [ width, 1 ].max
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.list_classes
|
59
|
+
Bri::Mall.instance.classes.join("\n" )
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.list_methods
|
63
|
+
( Bri::Mall.instance.instance_methods +
|
64
|
+
Bri::Mall.instance.class_methods ).sort.join( "\n" )
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.list_names
|
68
|
+
( Bri::Mall.instance.classes +
|
69
|
+
Bri::Mall.instance.instance_methods +
|
70
|
+
Bri::Mall.instance.class_methods ).sort.join( "\n" )
|
71
|
+
end
|
72
|
+
|
50
73
|
end
|
51
74
|
|
data/lib/bri/mall.rb
CHANGED
@@ -12,6 +12,22 @@ module Bri
|
|
12
12
|
@stores.collect { |store| store.modules }.flatten.uniq.sort
|
13
13
|
end
|
14
14
|
|
15
|
+
def class_methods
|
16
|
+
Bri::Mall.instance.stores.map do |store|
|
17
|
+
store.class_methods.map do |klass, methods|
|
18
|
+
methods.map { |method| "#{klass}.#{method}" }
|
19
|
+
end
|
20
|
+
end.flatten.uniq
|
21
|
+
end
|
22
|
+
|
23
|
+
def instance_methods
|
24
|
+
Bri::Mall.instance.stores.map do |store|
|
25
|
+
store.instance_methods.map do |klass, methods|
|
26
|
+
methods.map { |method| "#{klass}##{method}" }
|
27
|
+
end
|
28
|
+
end.flatten.uniq
|
29
|
+
end
|
30
|
+
|
15
31
|
private
|
16
32
|
def initialize
|
17
33
|
@stores = []
|
data/lib/bri/match/base.rb
CHANGED
@@ -16,7 +16,7 @@ module Bri
|
|
16
16
|
when RDoc::Markup::BlankLine
|
17
17
|
result << ""
|
18
18
|
when RDoc::Markup::Rule
|
19
|
-
result << "-" * Bri
|
19
|
+
result << "-" * Bri.width
|
20
20
|
when RDoc::Markup::Verbatim
|
21
21
|
result << element.text
|
22
22
|
when RDoc::Markup::Heading
|
@@ -45,7 +45,7 @@ module Bri
|
|
45
45
|
result
|
46
46
|
end
|
47
47
|
|
48
|
-
def reflow( text, width = Bri
|
48
|
+
def reflow( text, width = Bri.width )
|
49
49
|
array_to_width( text.split( /\s+/ ), width, " ", 1 )
|
50
50
|
end
|
51
51
|
end
|
data/lib/bri/match/class.rb
CHANGED
@@ -14,10 +14,11 @@ module Bri
|
|
14
14
|
def initialize( rdoc_result )
|
15
15
|
@type = rdoc_result.type
|
16
16
|
@name = rdoc_result.name
|
17
|
-
@description_paragraphs = rdoc_result.comment.parts
|
17
|
+
@description_paragraphs = build_description( rdoc_result.comment.parts )
|
18
18
|
@includes = rdoc_result.includes.collect { |i| i.full_name }
|
19
|
-
@constants = rdoc_result.constants.collect
|
20
|
-
|
19
|
+
@constants = rdoc_result.constants.collect do |c|
|
20
|
+
c.value ? "#{c.name} = #{c.value}" : c.name
|
21
|
+
end
|
21
22
|
@attributes = rdoc_result.attributes.collect { |a| "#{a.name} (#{a.rw})" }
|
22
23
|
|
23
24
|
class_methods, instance_methods = rdoc_result.method_list.
|
data/lib/bri/templates.rb
CHANGED
@@ -14,7 +14,7 @@ module Bri
|
|
14
14
|
(no description...)
|
15
15
|
<% else %>
|
16
16
|
<% description_paragraphs.each do |paragraph| %>
|
17
|
-
<%= array_to_width( paragraph.split( /\s+/ ),
|
17
|
+
<%= array_to_width( paragraph.split( /\s+/ ), Bri.width, " ") %>
|
18
18
|
<% end %>
|
19
19
|
<% end %>
|
20
20
|
|
@@ -65,7 +65,7 @@ module Bri
|
|
65
65
|
EOT
|
66
66
|
|
67
67
|
module Helpers
|
68
|
-
def hrule( text = '', width = Bri
|
68
|
+
def hrule( text = '', width = Bri.width )
|
69
69
|
'-' * ( width - text.length - 1 ) + " " +
|
70
70
|
Term::ANSIColor::bold + text + Term::ANSIColor::reset +
|
71
71
|
"\n"
|
@@ -77,7 +77,7 @@ module Bri
|
|
77
77
|
end
|
78
78
|
module_function :section_header
|
79
79
|
|
80
|
-
def array_to_width( array, width = Bri
|
80
|
+
def array_to_width( array, width = Bri.width, separator = ", ", indent_steps = 1 )
|
81
81
|
indentation = ' '
|
82
82
|
rows = '' + indentation * indent_steps
|
83
83
|
row = ''
|
@@ -85,7 +85,7 @@ module Bri
|
|
85
85
|
|
86
86
|
array = add_separators( array, separator )
|
87
87
|
|
88
|
-
array.each do |element|
|
88
|
+
array.compact.each do |element|
|
89
89
|
if row.length + element.length >= width
|
90
90
|
rows << row + "\n" + indentation * indent_steps
|
91
91
|
row = ''
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sven Riedel
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-30 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -83,7 +83,7 @@ files:
|
|
83
83
|
- spec/lib/bri/search/instance_method_spec.rb
|
84
84
|
- spec/lib/bri/search/method_spec.rb
|
85
85
|
has_rdoc: true
|
86
|
-
homepage:
|
86
|
+
homepage: http://github.com/sriedel/bri
|
87
87
|
licenses: []
|
88
88
|
|
89
89
|
post_install_message:
|