bri 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,9 @@
1
+ 0.1.5
2
+ - Fix rendering of nested lists
3
+ - Fix highlighting of sequences of + and _ characters
4
+ - Add a more elaborate help banner
5
+ - Show the help banner if no arguments are passed to the executable
6
+
1
7
  0.1.4
2
8
  - Better rendering of list items
3
9
  - Bulleted Lists now have bullets in front of the list items
data/bin/bri CHANGED
@@ -10,6 +10,15 @@ require 'optparse'
10
10
 
11
11
  def parse_options
12
12
  parser = OptionParser.new do |opts|
13
+ opts.banner = "Usage: #{$0} [options] <method_name>"
14
+ opts.separator ""
15
+ opts.separator " method_name should be in one of the following formats:"
16
+ opts.separator ""
17
+ opts.separator " * ClassOrModuleName#instance_method_name"
18
+ opts.separator " * ClassOrModuleName.class_method_name"
19
+ opts.separator " * #instance_method_name"
20
+ opts.separator " * .class_method_name"
21
+ opts.separator ""
13
22
  opts.on( nil, "--classes", "List known classes" ) { |v| @options[:list_classes] = true }
14
23
  opts.on( nil, "--methods", "List known methods" ) { |v| @options[:list_methods] = true }
15
24
  opts.on( "-l", "--list-names", "List known namespaces/methods" ) { |v| @options[:list_names] = true }
@@ -17,6 +26,11 @@ def parse_options
17
26
  opts.on_tail( "-h", "--help", "This help text" ) { puts opts; exit }
18
27
  end
19
28
  parser.parse!( ARGV )
29
+
30
+ if ARGV.size == 0
31
+ puts parser.summarize
32
+ exit 0
33
+ end
20
34
  end
21
35
 
22
36
  parse_options
@@ -1,7 +1,6 @@
1
1
  module Bri
2
2
  module Match
3
3
  class Base
4
- @@renderer = Bri::Renderer.new
5
4
  def to_s
6
5
  ERB.new( self.class.const_get( :TEMPLATE ), nil, '<>' ).
7
6
  result( binding )
@@ -9,7 +8,7 @@ module Bri
9
8
 
10
9
  private
11
10
  def build_description( source )
12
- source.collect { |element| @@renderer.render element }
11
+ source.collect { |element| Bri::Renderer.render element }
13
12
  end
14
13
  end
15
14
  end
@@ -1,13 +1,10 @@
1
1
  require 'strscan'
2
2
 
3
3
  module Bri
4
- class Renderer
4
+ module Renderer
5
5
  INDENT = ' ' * 2
6
6
 
7
- def initialize
8
- end
9
-
10
- def render( element, width = Bri.width )
7
+ def self.render( element, width = Bri.width )
11
8
  case element
12
9
  when RDoc::Markup::Verbatim
13
10
  text = extract_text( element, width )
@@ -24,6 +21,8 @@ module Bri
24
21
  when :NUMBER
25
22
  i = 0
26
23
  rendered_items.map! { |item| i+=1; sprintf "%d.%s", i, item }
24
+ when :NOTE, :LABEL
25
+ # do nothing
27
26
  end
28
27
 
29
28
  rendered_items.join( "\n\n" ) + "\n"
@@ -36,7 +35,7 @@ module Bri
36
35
  end
37
36
  end
38
37
 
39
- def extract_text( element, width )
38
+ def self.extract_text( element, width )
40
39
  text = case element
41
40
  when RDoc::Markup::Paragraph
42
41
  element.text
@@ -49,14 +48,17 @@ module Bri
49
48
  when RDoc::Markup::Heading
50
49
  "<h>#{element.text}</h>"
51
50
  when RDoc::Markup::ListItem
52
- element.label.to_s + element.parts.collect { |part| extract_text part, width }.join
51
+ parts = element.parts.collect { |part| extract_text part, width }.join
52
+ element.label ? "#{element.label}: #{parts}" : parts
53
+ when RDoc::Markup::List
54
+ render( element, width - INDENT.length )
53
55
  else
54
56
  raise "Don't know how to handle type #{element.class}: #{element.inspect}"
55
57
  end
56
58
  text + "\n"
57
59
  end
58
60
 
59
- def replace_markup( text )
61
+ def self.replace_markup( text )
60
62
  text.gsub!( "<tt>", Term::ANSIColor::cyan )
61
63
  text.gsub!( "</tt>", Term::ANSIColor::reset )
62
64
 
@@ -66,22 +68,26 @@ module Bri
66
68
  text.gsub!( "<h>", Term::ANSIColor::green )
67
69
  text.gsub!( "</h>", Term::ANSIColor::reset )
68
70
 
69
- text.gsub!( /(^|\s)\+(.*?)\+/,
71
+ text.gsub!( /(^|\s)\+(.*?[a-zA-Z0-9]+.*?)\+/,
70
72
  "\\1#{Term::ANSIColor::yellow}\\2#{Term::ANSIColor::reset}" )
71
- text.gsub!( /(^|\s)_(.*?)_/,
73
+ text.gsub!( /(^|\s)_(.*?[a-zA-Z0-9]+.*?)_/,
72
74
  "\\1#{Term::ANSIColor::yellow}\\2#{Term::ANSIColor::reset}" )
73
75
  text
74
76
  end
75
77
 
76
- def printable_length( text )
78
+ def self.printable_length( text )
77
79
  Term::ANSIColor.uncolored( text ).length
78
80
  end
79
81
 
80
- def wrap_to_width( styled_text, width )
82
+ def self.wrap_list( array, width = Bri.width )
83
+ indent( wrap_to_width( array.join(", "), width ) )
84
+ end
85
+
86
+ def self.wrap_to_width( styled_text, width )
81
87
  styled_text.split( "\n" ).collect { |row| wrap_row row, width }.join
82
88
  end
83
89
 
84
- def wrap_row( physical_row, width )
90
+ def self.wrap_row( physical_row, width )
85
91
  output_text = ''
86
92
  logical_row = ''
87
93
  printable_row_length = 0
@@ -107,7 +113,7 @@ module Bri
107
113
  output_text << logical_row << "\n"
108
114
  end
109
115
 
110
- def indent( text )
116
+ def self.indent( text )
111
117
  text.split( "\n" ).collect { |row| "#{INDENT}#{row}" }.join("\n" )
112
118
  end
113
119
  end
@@ -3,7 +3,7 @@ module Bri
3
3
  MULTIPLE_CHOICES =<<-EOT
4
4
  <%= Bri::Templates::Helpers.hrule( "Multiple choices:" ) %>
5
5
 
6
- <%= Bri::Templates::Helpers.array_to_width( qualified_methods.sort ) %>
6
+ <%= Bri::Renderer.wrap_list( qualified_methods.sort ) %>
7
7
 
8
8
 
9
9
  EOT
@@ -20,31 +20,31 @@ module Bri
20
20
 
21
21
  <% if !includes.empty? %>
22
22
  <%= section_header( "Includes:" ) %>
23
- <%= array_to_width( includes.sort ) %>
23
+ <%= Bri::Renderer.wrap_list( includes.sort ) %>
24
24
 
25
25
 
26
26
  <% end %>
27
27
  <% if !constants.empty? %>
28
28
  <%= section_header( "Constants:" ) %>
29
- <%= array_to_width( constants.sort ) %>
29
+ <%= Bri::Renderer.wrap_list( constants.sort ) %>
30
30
 
31
31
 
32
32
  <% end %>
33
33
  <% if !class_methods.empty? %>
34
34
  <%= section_header( "Class methods:" ) %>
35
- <%= array_to_width( class_methods.sort ) %>
35
+ <%= Bri::Renderer.wrap_list( class_methods.sort ) %>
36
36
 
37
37
 
38
38
  <% end %>
39
39
  <% if !instance_methods.empty? %>
40
40
  <%= section_header( "Instance methods:" ) %>
41
- <%= array_to_width( instance_methods.sort ) %>
41
+ <%= Bri::Renderer.wrap_list( instance_methods.sort ) %>
42
42
 
43
43
 
44
44
  <% end %>
45
45
  <% if !attributes.empty? %>
46
46
  <%= section_header( "Attributes:" ) %>
47
- <%= array_to_width( attributes.sort ) %>
47
+ <%= Bri::Renderer.wrap_list( attributes.sort ) %>
48
48
 
49
49
 
50
50
  <% end %>
@@ -68,9 +68,7 @@ module Bri
68
68
  '-' * width + "\n"
69
69
  else
70
70
  text = " " + text if text != ''
71
- '-' * ( width - text.length ) +
72
- Term::ANSIColor::bold + text + Term::ANSIColor::reset +
73
- "\n"
71
+ '-' * ( width - text.length ) + Term::ANSIColor::bold( text ) + "\n"
74
72
  end
75
73
  end
76
74
  module_function :hrule
@@ -79,34 +77,6 @@ module Bri
79
77
  Term::ANSIColor::green + Term::ANSIColor::underline + text + Term::ANSIColor::reset + "\n"
80
78
  end
81
79
  module_function :section_header
82
-
83
- def array_to_width( array, width = Bri.width, separator = ", ", indent_steps = 1 )
84
- indentation = ' '
85
- rows = '' + indentation * indent_steps
86
- row = ''
87
- row_length = 0
88
-
89
- array = add_separators( array, separator )
90
-
91
- array.compact.each do |element|
92
- if row.length + element.length >= width
93
- rows << row + "\n" + indentation * indent_steps
94
- row = ''
95
- end
96
-
97
- row << element
98
- end
99
-
100
- rows << row
101
- rows
102
- end
103
- module_function :array_to_width
104
-
105
- def add_separators( array, separator )
106
- last_element = array.pop
107
- array.map { |e| e + separator } + [ last_element ]
108
- end
109
- module_function :add_separators
110
80
  end
111
81
  end
112
82
  end
@@ -11,7 +11,7 @@ describe Bri::Match::Method do
11
11
 
12
12
  let( :rdoc_method ) do
13
13
  mock( RDoc::AnyMethod, :full_name => "This::IS::My.full_name",
14
- :call_seq => "First\nSecond\nThird",
14
+ :arglists => "First\nSecond\nThird",
15
15
  :comment => fake_description )
16
16
  end
17
17
 
@@ -5,7 +5,7 @@ describe Bri::Search::ClassMethod do
5
5
  let( :paragraph ) { RDoc::Markup::Paragraph.new( "Foo Description" ) }
6
6
  let( :document ) { mock( RDoc::Markup::Document, :parts => [ paragraph ] ) }
7
7
  let( :rdoc_method ) { mock( RDoc::AnyMethod, :full_name => "Foo",
8
- :call_seq => "",
8
+ :arglists => "",
9
9
  :comment => document ) }
10
10
  before( :each ) do
11
11
  store_one = mock( RDoc::RI::Store, :load_cache => true,
@@ -5,7 +5,7 @@ describe Bri::Search::InstanceMethod do
5
5
  let( :paragraph ) { RDoc::Markup::Paragraph.new( "Foo Description" ) }
6
6
  let( :document ) { mock( RDoc::Markup::Document, :parts => [ paragraph ] ) }
7
7
  let( :rdoc_method ) { mock( RDoc::AnyMethod, :full_name => "Foo",
8
- :call_seq => "",
8
+ :arglists => "",
9
9
  :comment => document ) }
10
10
  before( :each ) do
11
11
  store_one = mock( RDoc::RI::Store, :load_cache => true,
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bri
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 4
9
- version: 0.1.4
4
+ prerelease:
5
+ version: 0.1.5
10
6
  platform: ruby
11
7
  authors:
12
8
  - Sven Riedel
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-10-06 00:00:00 +02:00
13
+ date: 2011-02-04 00:00:00 +01:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,10 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 0
31
- - 5
32
24
  version: 1.0.5
33
25
  type: :runtime
34
26
  version_requirements: *id001
@@ -38,13 +30,9 @@ dependencies:
38
30
  requirement: &id002 !ruby/object:Gem::Requirement
39
31
  none: false
40
32
  requirements:
41
- - - ">="
33
+ - - ~>
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 2
45
- - 5
46
- - 0
47
- version: 2.5.0
35
+ version: 3.5.2
48
36
  type: :runtime
49
37
  version_requirements: *id002
50
38
  description: An alternative to the ri command
@@ -98,23 +86,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
86
  requirements:
99
87
  - - ">="
100
88
  - !ruby/object:Gem::Version
101
- segments:
102
- - 1
103
- - 9
104
- - 2
105
89
  version: 1.9.2
106
90
  required_rubygems_version: !ruby/object:Gem::Requirement
107
91
  none: false
108
92
  requirements:
109
93
  - - ">="
110
94
  - !ruby/object:Gem::Version
111
- segments:
112
- - 0
113
95
  version: "0"
114
96
  requirements: []
115
97
 
116
98
  rubyforge_project:
117
- rubygems_version: 1.3.7
99
+ rubygems_version: 1.5.0
118
100
  signing_key:
119
101
  specification_version: 3
120
102
  summary: Beautified RI in the spirit of fastri/qri. Unlike fastri, bri builds on top of the rdoc 2.x backend, only output and formatting is handled by bri