bri 0.4.4 → 1.0.0.pre.beta1
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/TODO +2 -3
- data/bin/bri +21 -7
- data/lib/bri.rb +18 -15
- data/lib/bri/mall.rb +12 -14
- data/lib/bri/match/base.rb +1 -1
- data/lib/bri/match/class.rb +5 -1
- data/lib/bri/match/method.rb +2 -1
- data/lib/bri/renderer.rb +28 -188
- data/lib/bri/renderer/blank_line.rb +9 -0
- data/lib/bri/renderer/default.rb +27 -0
- data/lib/bri/renderer/document.rb +11 -0
- data/lib/bri/renderer/heading.rb +9 -0
- data/lib/bri/renderer/list.rb +24 -0
- data/lib/bri/renderer/list/base.rb +18 -0
- data/lib/bri/renderer/list/bullet.rb +15 -0
- data/lib/bri/renderer/list/labeled.rb +15 -0
- data/lib/bri/renderer/list/lower_lettered.rb +18 -0
- data/lib/bri/renderer/list/note.rb +15 -0
- data/lib/bri/renderer/list/numbered.rb +18 -0
- data/lib/bri/renderer/list/upper_lettered.rb +18 -0
- data/lib/bri/renderer/list_item.rb +24 -0
- data/lib/bri/renderer/paragraph.rb +11 -0
- data/lib/bri/renderer/result.rb +73 -0
- data/lib/bri/renderer/rule.rb +9 -0
- data/lib/bri/renderer/verbatim.rb +14 -0
- data/lib/bri/search/class.rb +3 -1
- data/lib/bri/search/method.rb +3 -3
- data/lib/bri/templates.rb +7 -38
- data/lib/bri/text_formatting_utils.rb +92 -0
- metadata +19 -12
- data/spec/bri_dummy_spec_class.rb +0 -132
- data/spec/lib/bri/mall_spec.rb +0 -38
- data/spec/lib/bri/match/class_spec.rb +0 -125
- data/spec/lib/bri/match/method_spec.rb +0 -112
- data/spec/lib/bri/matcher_spec.rb +0 -70
- data/spec/lib/bri/renderer_spec.rb +0 -338
- data/spec/lib/bri/search/class_method_spec.rb +0 -172
- data/spec/lib/bri/search/class_spec.rb +0 -66
- data/spec/lib/bri/search/instance_method_spec.rb +0 -173
- data/spec/lib/bri/search/method_spec.rb +0 -41
- data/spec/spec_helper.rb +0 -22
@@ -0,0 +1,27 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class Default
|
4
|
+
include ::Bri::TextFormattingUtils
|
5
|
+
|
6
|
+
attr_reader :element
|
7
|
+
|
8
|
+
def initialize( element )
|
9
|
+
@element = element
|
10
|
+
end
|
11
|
+
|
12
|
+
def render( width = Bri.width )
|
13
|
+
text = extract_text( width )
|
14
|
+
|
15
|
+
if text.empty?
|
16
|
+
nil
|
17
|
+
else
|
18
|
+
::Bri::Renderer::Result.new( text, width )
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def extract_text( width, conserve_newslines = false )
|
23
|
+
raise "Don't know how to handle type #{element.class}: #{element.inspect}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class List < Default
|
4
|
+
def self.new( element )
|
5
|
+
case element.type
|
6
|
+
when :BULLET then ::Bri::Renderer::List::Bullet.new( element )
|
7
|
+
when :NUMBER then ::Bri::Renderer::List::Numbered.new( element )
|
8
|
+
when :LALPHA then ::Bri::Renderer::List::LowerLettered.new( element )
|
9
|
+
when :UALPHA then ::Bri::Renderer::List::UpperLettered.new( element )
|
10
|
+
when :LABEL then ::Bri::Renderer::List::Labeled.new( element )
|
11
|
+
when :NOTE then ::Bri::Renderer::List::Note.new( element )
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
require_relative 'list/base'
|
19
|
+
require_relative 'list/bullet'
|
20
|
+
require_relative 'list/numbered'
|
21
|
+
require_relative 'list/lower_lettered'
|
22
|
+
require_relative 'list/upper_lettered'
|
23
|
+
require_relative 'list/labeled'
|
24
|
+
require_relative 'list/note'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class List
|
4
|
+
class Base < ::Bri::Renderer::Default
|
5
|
+
def extract_text( width, conserve_newlines = false )
|
6
|
+
item_width = width - max_bullet_width
|
7
|
+
rendered_items = element.items.each_with_index.
|
8
|
+
map do |item, index|
|
9
|
+
bullet = next_bullet( item )
|
10
|
+
::Bri::Renderer.new( item ).text( item_width, bullet )
|
11
|
+
end
|
12
|
+
|
13
|
+
rendered_items.join
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class List
|
4
|
+
class LowerLettered < Base
|
5
|
+
def max_bullet_width
|
6
|
+
@max_bullet_width ||= ( Math.log10( element.items.size ) / Math.log10( 26 ) ).ceil + 3
|
7
|
+
end
|
8
|
+
|
9
|
+
def next_bullet( item )
|
10
|
+
@current_bullet ||= 'a'
|
11
|
+
result = "#{@current_bullet}. "
|
12
|
+
@current_bullet.succ!
|
13
|
+
result
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class List
|
4
|
+
class Note < Base
|
5
|
+
def max_bullet_width
|
6
|
+
@max_bullet_width ||= element.items.flat_map(&:label).map(&:size).max
|
7
|
+
end
|
8
|
+
|
9
|
+
def next_bullet( item )
|
10
|
+
"#{item.label.first}:" + " " * (max_bullet_width - item.label.first.size + 1)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class List
|
4
|
+
class Numbered < Base
|
5
|
+
def next_bullet( item )
|
6
|
+
@current_bullet ||= '1'
|
7
|
+
result = "#{@current_bullet}. "
|
8
|
+
@current_bullet.succ!
|
9
|
+
result
|
10
|
+
end
|
11
|
+
|
12
|
+
def max_bullet_width
|
13
|
+
@max_bullet_width ||= Math.log10( element.items.size ).ceil + 3
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class List
|
4
|
+
class UpperLettered < Base
|
5
|
+
def max_bullet_width
|
6
|
+
@max_bullet_width ||= ( Math.log10( element.items.size ) / Math.log10( 26 ) ).ceil + 3
|
7
|
+
end
|
8
|
+
|
9
|
+
def next_bullet( item )
|
10
|
+
@current_bullet ||= 'A'
|
11
|
+
result = "#{@current_bullet}. "
|
12
|
+
@current_bullet.succ!
|
13
|
+
result
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class ListItem < Default
|
4
|
+
def text( total_width, bullet )
|
5
|
+
element.parts.map.with_index do |part, index|
|
6
|
+
part_is_list = part.is_a?(RDoc::Markup::List)
|
7
|
+
first_line_indent = ( part_is_list || index > 0 ) ? bullet.size : 0
|
8
|
+
following_line_indent = bullet.size
|
9
|
+
|
10
|
+
text = ::Bri::Renderer.new( part ).extract_text( total_width, true )
|
11
|
+
text.prepend( bullet ) if index == 0 && !part_is_list
|
12
|
+
lines = text.lines
|
13
|
+
|
14
|
+
result = indent( lines.first, indent_depth: first_line_indent )
|
15
|
+
lines.drop( 1 ).each do |line|
|
16
|
+
result << indent( line, indent_depth: following_line_indent )
|
17
|
+
end
|
18
|
+
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class Paragraph < Default
|
4
|
+
def extract_text( width, conserve_newlines = false )
|
5
|
+
join_char = conserve_newlines ? "\n" : " "
|
6
|
+
intermediate = element.parts.map(&:strip).join( join_char )
|
7
|
+
wrap_to_width( intermediate, width )
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class Result
|
4
|
+
include ::Bri::TextFormattingUtils
|
5
|
+
|
6
|
+
Color = ::Term::ANSIColor
|
7
|
+
|
8
|
+
attr_reader :input, :width
|
9
|
+
|
10
|
+
def initialize(input, width )
|
11
|
+
@input = input
|
12
|
+
@width = width
|
13
|
+
end
|
14
|
+
|
15
|
+
def output
|
16
|
+
return @output if instance_variable_defined?( :@output )
|
17
|
+
|
18
|
+
@output = replace_markup( input ).
|
19
|
+
then { |styled_text| width ? wrap_to_width( styled_text, width ) : styled_text }.
|
20
|
+
then { |wrapped_text| indent( wrapped_text ) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def concat( other )
|
24
|
+
output.concat( other.output )
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def replace_markup( text )
|
30
|
+
text.gsub!( /(?<!\\)<(?:tt|code)>/, Color.cyan )
|
31
|
+
text.gsub!( /(?<!\\)<\/(?:tt|code)>/, Color.reset )
|
32
|
+
|
33
|
+
text.gsub!( /(?<!\\)<b>/, Color.bold )
|
34
|
+
text.gsub!( /(?<!\\)<\/b>/, Color.reset )
|
35
|
+
|
36
|
+
text.gsub!( /(?<!\\)<(?:em|i)>/, Color.yellow )
|
37
|
+
text.gsub!( /(?<!\\)<\/(?:em|i)>/, Color.reset )
|
38
|
+
|
39
|
+
text.gsub!( "<h>", Color.green )
|
40
|
+
text.gsub!( "</h>", Color.reset )
|
41
|
+
|
42
|
+
text.gsub!( "\\<", "<" )
|
43
|
+
|
44
|
+
text.gsub!( /(#\s*=>)(.*)/,
|
45
|
+
"#{Color.dark}\\1#{Color.reset}#{Color.bold}\\2#{Color.reset}" )
|
46
|
+
|
47
|
+
text.gsub!( /(^|\s)\*(.*?[a-zA-Z0-9]+.*?)\*/,
|
48
|
+
"\\1#{Color.bold}\\2#{Color.reset}" )
|
49
|
+
text.gsub!( /(^|\s)\+(.*?[a-zA-Z0-9]+.*?)\+/,
|
50
|
+
"\\1#{Color.cyan}\\2#{Color.reset}" )
|
51
|
+
text.gsub!( /(^|\s)_(.*?[a-zA-Z0-9]+.*?)_/,
|
52
|
+
"\\1#{Color.yellow}\\2#{Color.reset}" )
|
53
|
+
|
54
|
+
text.gsub!( %r{\b((?:https?|ftp)://[-\w.?%&=/]+)\b},
|
55
|
+
"#{Color.underline}\\1#{Color.reset}" )
|
56
|
+
|
57
|
+
text.gsub!( %r{\b(mailto:[-\w.%]+@[-\w.]+)\b},
|
58
|
+
"#{Color.underline}\\1#{Color.reset}" )
|
59
|
+
|
60
|
+
text.gsub!( %r{\b((?<!:\/\/)www.[-\w.?%&=]+)\b},
|
61
|
+
"#{Color.underline}\\1#{Color.reset}" )
|
62
|
+
|
63
|
+
text.gsub!( %r{\blink:(.*?)(\s|$)},
|
64
|
+
"#{Color.underline}\\1#{Color.reset}\\2" )
|
65
|
+
|
66
|
+
text.gsub!( %r{\{(.*?)\}\[(.*?)\]}m, "\\1 (\\2)" )
|
67
|
+
text.gsub!( %r{\[(#{Regexp.escape( Color.underline )}.*?#{Regexp.escape( Color.reset )})\]},
|
68
|
+
" (\\1)" )
|
69
|
+
text
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Bri
|
2
|
+
module Renderer
|
3
|
+
class Verbatim < Default
|
4
|
+
def render( width = Bri.width )
|
5
|
+
text = ::Bri::Renderer.new( element ).extract_text( width )
|
6
|
+
::Bri::Renderer::Result.new( "#{text}\n", nil )
|
7
|
+
end
|
8
|
+
|
9
|
+
def extract_text( width, conserve_newlines = false )
|
10
|
+
element.parts.map { |part| indent(part) }.join + "\n"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/bri/search/class.rb
CHANGED
@@ -3,7 +3,9 @@ module Bri
|
|
3
3
|
class Class < Base
|
4
4
|
def search( type = :fully_qualified )
|
5
5
|
# NOTE: classes are only searched as fully qualified for the time being
|
6
|
-
Bri::Mall.
|
6
|
+
Bri::Mall.stores.
|
7
|
+
select { |s| s.module_names.include?( @term ) }.
|
8
|
+
each do |store|
|
7
9
|
@matches << Bri::Match::Class.new( store.load_class( @term ), store )
|
8
10
|
end
|
9
11
|
end
|
data/lib/bri/search/method.rb
CHANGED
@@ -31,7 +31,7 @@ module Bri
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def store_for_method
|
34
|
-
Bri::Mall.
|
34
|
+
Bri::Mall.stores.detect do |store|
|
35
35
|
store_methods( store ).has_key?( @class_term ) &&
|
36
36
|
store_methods( store )[@class_term].include?( @method_term )
|
37
37
|
end
|
@@ -54,7 +54,7 @@ module Bri
|
|
54
54
|
|
55
55
|
|
56
56
|
def partially_qualified_search
|
57
|
-
Bri::Mall.
|
57
|
+
Bri::Mall.stores.each do |store|
|
58
58
|
classes_with_method( store, @method_term ).each do |klass|
|
59
59
|
match_data = method_rdoc( store, klass, @method_term )
|
60
60
|
next unless match_data
|
@@ -74,7 +74,7 @@ module Bri
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def unqualified_search_worker( method_re )
|
77
|
-
Bri::Mall.
|
77
|
+
Bri::Mall.stores.each do |store|
|
78
78
|
candidates_from_method_re( store, method_re ).each do |klass, methods|
|
79
79
|
methods.each do |method|
|
80
80
|
match_data = method_rdoc( store, klass, method )
|
data/lib/bri/templates.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
module Bri
|
2
2
|
module Templates
|
3
|
-
RULE_CHARACTER = '-'.freeze
|
4
|
-
|
5
3
|
MULTIPLE_CHOICES =<<-EOT
|
6
|
-
<%=
|
4
|
+
<%= hrule( "Multiple choices:" ) %>
|
7
5
|
|
8
6
|
<%= qualified_methods.sort.join("\n") %>
|
9
7
|
|
@@ -24,38 +22,32 @@ module Bri
|
|
24
22
|
|
25
23
|
<% if !includes.empty? %>
|
26
24
|
<%= section_header( "Includes:" ) %>
|
27
|
-
<%=
|
28
|
-
|
25
|
+
<%= wrap_list( includes.sort ) %>
|
29
26
|
|
30
27
|
<% end %>
|
31
28
|
<% if !extends.empty? %>
|
32
29
|
<%= section_header( "Extends:" ) %>
|
33
|
-
<%=
|
34
|
-
|
30
|
+
<%= wrap_list( extends.sort ) %>
|
35
31
|
|
36
32
|
<% end %>
|
37
33
|
<% if !constants.empty? %>
|
38
34
|
<%= section_header( "Constants:" ) %>
|
39
|
-
<%=
|
40
|
-
|
35
|
+
<%= wrap_list( constants.sort ) %>
|
41
36
|
|
42
37
|
<% end %>
|
43
38
|
<% if !class_methods.empty? %>
|
44
39
|
<%= section_header( "Class methods:" ) %>
|
45
|
-
<%=
|
46
|
-
|
40
|
+
<%= wrap_list( class_methods.sort ) %>
|
47
41
|
|
48
42
|
<% end %>
|
49
43
|
<% if !instance_methods.empty? %>
|
50
44
|
<%= section_header( "Instance methods:" ) %>
|
51
|
-
<%=
|
52
|
-
|
45
|
+
<%= wrap_list( instance_methods.sort ) %>
|
53
46
|
|
54
47
|
<% end %>
|
55
48
|
<% if !attributes.empty? %>
|
56
49
|
<%= section_header( "Attributes:" ) %>
|
57
|
-
<%=
|
58
|
-
|
50
|
+
<%= wrap_list( attributes.sort ) %>
|
59
51
|
|
60
52
|
<% end %>
|
61
53
|
EOT
|
@@ -73,28 +65,5 @@ module Bri
|
|
73
65
|
<% end %>
|
74
66
|
|
75
67
|
EOT
|
76
|
-
|
77
|
-
module Helpers
|
78
|
-
def hrule( text = '', width = Bri.width )
|
79
|
-
text.prepend( " " ) unless text.empty?
|
80
|
-
|
81
|
-
rule_length = width - text.length
|
82
|
-
rule_length = 1 if rule_length < 1
|
83
|
-
|
84
|
-
rule = RULE_CHARACTER * rule_length
|
85
|
-
"#{rule}#{Term::ANSIColor::bold( text )}\n"
|
86
|
-
end
|
87
|
-
module_function :hrule
|
88
|
-
|
89
|
-
def print_origin( origin_text, width = Bri.width )
|
90
|
-
return unless origin_text
|
91
|
-
"(#{origin_text})".rjust( width )
|
92
|
-
end
|
93
|
-
|
94
|
-
def section_header( text )
|
95
|
-
"#{Term::ANSIColor.green}#{Term::ANSIColor.underline}#{text}#{Term::ANSIColor.reset}\n"
|
96
|
-
end
|
97
|
-
module_function :section_header
|
98
|
-
end
|
99
68
|
end
|
100
69
|
end
|