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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/TODO +2 -3
  3. data/bin/bri +21 -7
  4. data/lib/bri.rb +18 -15
  5. data/lib/bri/mall.rb +12 -14
  6. data/lib/bri/match/base.rb +1 -1
  7. data/lib/bri/match/class.rb +5 -1
  8. data/lib/bri/match/method.rb +2 -1
  9. data/lib/bri/renderer.rb +28 -188
  10. data/lib/bri/renderer/blank_line.rb +9 -0
  11. data/lib/bri/renderer/default.rb +27 -0
  12. data/lib/bri/renderer/document.rb +11 -0
  13. data/lib/bri/renderer/heading.rb +9 -0
  14. data/lib/bri/renderer/list.rb +24 -0
  15. data/lib/bri/renderer/list/base.rb +18 -0
  16. data/lib/bri/renderer/list/bullet.rb +15 -0
  17. data/lib/bri/renderer/list/labeled.rb +15 -0
  18. data/lib/bri/renderer/list/lower_lettered.rb +18 -0
  19. data/lib/bri/renderer/list/note.rb +15 -0
  20. data/lib/bri/renderer/list/numbered.rb +18 -0
  21. data/lib/bri/renderer/list/upper_lettered.rb +18 -0
  22. data/lib/bri/renderer/list_item.rb +24 -0
  23. data/lib/bri/renderer/paragraph.rb +11 -0
  24. data/lib/bri/renderer/result.rb +73 -0
  25. data/lib/bri/renderer/rule.rb +9 -0
  26. data/lib/bri/renderer/verbatim.rb +14 -0
  27. data/lib/bri/search/class.rb +3 -1
  28. data/lib/bri/search/method.rb +3 -3
  29. data/lib/bri/templates.rb +7 -38
  30. data/lib/bri/text_formatting_utils.rb +92 -0
  31. metadata +19 -12
  32. data/spec/bri_dummy_spec_class.rb +0 -132
  33. data/spec/lib/bri/mall_spec.rb +0 -38
  34. data/spec/lib/bri/match/class_spec.rb +0 -125
  35. data/spec/lib/bri/match/method_spec.rb +0 -112
  36. data/spec/lib/bri/matcher_spec.rb +0 -70
  37. data/spec/lib/bri/renderer_spec.rb +0 -338
  38. data/spec/lib/bri/search/class_method_spec.rb +0 -172
  39. data/spec/lib/bri/search/class_spec.rb +0 -66
  40. data/spec/lib/bri/search/instance_method_spec.rb +0 -173
  41. data/spec/lib/bri/search/method_spec.rb +0 -41
  42. data/spec/spec_helper.rb +0 -22
@@ -0,0 +1,92 @@
1
+ module Bri
2
+ module TextFormattingUtils
3
+ RULE_CHARACTER = '-'.freeze
4
+
5
+ def wrap_to_width( styled_text, width )
6
+ styled_text.split( "\n" ).map { |row| wrap_row( row, width ) }.join
7
+ end
8
+ module_function :wrap_to_width
9
+
10
+ def wrap_row( physical_row, width )
11
+ output_text = ''
12
+ logical_row = ''
13
+ printable_row_length = 0
14
+ tokens_in_row = 0
15
+
16
+ scanner = StringScanner.new( physical_row )
17
+
18
+ while( !scanner.eos? )
19
+ token = scanner.scan( /\S+/ ).to_s
20
+ printable_token_length = printable_length( token )
21
+
22
+ if printable_token_length + printable_row_length > width && tokens_in_row > 0
23
+ output_text << logical_row.rstrip << "\n"
24
+ logical_row.clear
25
+ printable_row_length = 0
26
+ tokens_in_row = 0
27
+ end
28
+
29
+ logical_row << token
30
+ printable_row_length += printable_token_length
31
+ tokens_in_row += 1
32
+
33
+ # TODO: Instead of using rstrip when appending the logical row,
34
+ # identify here if the whitespace token will be the last
35
+ # on the row, and if so, don't add it in the first place.
36
+ # (sr 2019-06-23)
37
+ token = scanner.scan( /\s+/ ).to_s
38
+ logical_row << token
39
+ printable_row_length += token.length
40
+ end
41
+
42
+ output_text << logical_row.rstrip << "\n"
43
+ end
44
+ module_function :wrap_row
45
+
46
+ def indent( text, indent_depth: 2, each_row: true )
47
+ indent = " " * indent_depth
48
+
49
+ if each_row
50
+ text.lines.map { |row| row.prepend( indent ) }.join
51
+ else
52
+ text.prepend( indent )
53
+ end
54
+ end
55
+ module_function :indent
56
+
57
+ def printable_length( text )
58
+ Term::ANSIColor.uncolored( text ).length
59
+ end
60
+ module_function :printable_length
61
+
62
+ def wrap_list( array, width = Bri.width )
63
+ return '' if array.empty?
64
+
65
+ indent( wrap_to_width( array.join( " " ), width - 2 ) )
66
+ end
67
+ module_function :wrap_list
68
+
69
+ def hrule( text = '', width = Bri.width )
70
+ return "#{RULE_CHARACTER * width}\n" if text.empty?
71
+
72
+ rule_length = width - text.length - 1
73
+ rule_length = 1 if rule_length < 1
74
+
75
+ rule = RULE_CHARACTER * rule_length
76
+ "#{rule} #{Term::ANSIColor::bold( text )}\n"
77
+ end
78
+ module_function :hrule
79
+
80
+ def print_origin( origin_text, width = Bri.width )
81
+ return '' if !origin_text || origin_text.empty?
82
+
83
+ "(#{origin_text})".rjust( width )
84
+ end
85
+ module_function :print_origin
86
+
87
+ def section_header( text )
88
+ "#{Term::ANSIColor.green}#{Term::ANSIColor.underline}#{text}#{Term::ANSIColor.reset}\n"
89
+ end
90
+ module_function :section_header
91
+ end
92
+ end
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.4
4
+ version: 1.0.0.pre.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Riedel
@@ -100,6 +100,23 @@ files:
100
100
  - lib/bri/match/method.rb
101
101
  - lib/bri/matcher.rb
102
102
  - lib/bri/renderer.rb
103
+ - lib/bri/renderer/blank_line.rb
104
+ - lib/bri/renderer/default.rb
105
+ - lib/bri/renderer/document.rb
106
+ - lib/bri/renderer/heading.rb
107
+ - lib/bri/renderer/list.rb
108
+ - lib/bri/renderer/list/base.rb
109
+ - lib/bri/renderer/list/bullet.rb
110
+ - lib/bri/renderer/list/labeled.rb
111
+ - lib/bri/renderer/list/lower_lettered.rb
112
+ - lib/bri/renderer/list/note.rb
113
+ - lib/bri/renderer/list/numbered.rb
114
+ - lib/bri/renderer/list/upper_lettered.rb
115
+ - lib/bri/renderer/list_item.rb
116
+ - lib/bri/renderer/paragraph.rb
117
+ - lib/bri/renderer/result.rb
118
+ - lib/bri/renderer/rule.rb
119
+ - lib/bri/renderer/verbatim.rb
103
120
  - lib/bri/search.rb
104
121
  - lib/bri/search/base.rb
105
122
  - lib/bri/search/class.rb
@@ -107,17 +124,7 @@ files:
107
124
  - lib/bri/search/instance_method.rb
108
125
  - lib/bri/search/method.rb
109
126
  - lib/bri/templates.rb
110
- - spec/bri_dummy_spec_class.rb
111
- - spec/lib/bri/mall_spec.rb
112
- - spec/lib/bri/match/class_spec.rb
113
- - spec/lib/bri/match/method_spec.rb
114
- - spec/lib/bri/matcher_spec.rb
115
- - spec/lib/bri/renderer_spec.rb
116
- - spec/lib/bri/search/class_method_spec.rb
117
- - spec/lib/bri/search/class_spec.rb
118
- - spec/lib/bri/search/instance_method_spec.rb
119
- - spec/lib/bri/search/method_spec.rb
120
- - spec/spec_helper.rb
127
+ - lib/bri/text_formatting_utils.rb
121
128
  homepage: http://github.com/sriedel/bri
122
129
  licenses: []
123
130
  metadata: {}
@@ -1,132 +0,0 @@
1
- # This is a class description
2
- class BriDummySpecClassTwo
3
- include BriDummySpecModule
4
- extend BriDummySpecModuleTwo
5
- CONSTANT = 'value'
6
- OTHER_CONSTANT = nil
7
- attr_reader :read_attr
8
- attr_writer :write_attr
9
- attr_accessor :access_attr
10
-
11
- def self.bri_dummy_spec_second_singleton_method; end
12
- def bri_dummy_spec_instance_method_with_arguments( a, b ); end
13
- end
14
-
15
- class BriDummySpecClassEmpty; end
16
-
17
- module BriDummySpecModule; end
18
- module BriDummySpecModuleTwo; end
19
-
20
- module BriDummySpec
21
- class Class; end
22
- end
23
-
24
- class BriDummySpecClass
25
- def self.bri_dummy_spec_singleton_method; end
26
- def self.bri_dummy_spec_second_singleton_method; end
27
-
28
- def bri_dummy_spec_instance_method; end
29
-
30
- def bri_dummy_spec_instance_method_with_arguments( a, b ); end
31
-
32
- def bri_dummy_spec_instance_method_with_default_arguments( a, b, c = nil ); end
33
-
34
- def bri_dummy_spec_instance_method_which_yields
35
- yield yield_param_one, yield_param_two
36
- end
37
-
38
- def bri_dummy_spec_instance_method_with_yield_override # :yields: foo, bar
39
- yield yield_param_one, yield_param_two
40
- end
41
-
42
-
43
- # = This is a headline
44
- #
45
- # Followed by some introduction text.
46
- def basic_headline_and_paragraph_rendering_test_method; end
47
-
48
- # == This is a level two headline
49
- # This is a paragraph with a really really really really really really really really really really long line that needs to be wrapped.
50
- def level_two_headline_and_line_wrapping_rendering_test_method; end
51
-
52
- # This is some text before a horizontal rule.
53
- # ---
54
- # After a horizontal rule, the text continues.
55
- def horizontal_rule_rendering_test_method; end
56
-
57
- # * First item in a bulleted list
58
- # With a second line
59
- # * Second item in a bulleted list
60
- # * First item of a nested bulleted list
61
- # * Second item of a nested bulleted list
62
- # * Ending a bulleted list with a really really really really really really really really long line that needs to be wrapped
63
- def bulleted_list_rendering_test_method; end
64
-
65
- # - A second bulleted list
66
- # - Second item in second bulleted list
67
- # - Nested bulleted list
68
- # - Second nested bulleted list item
69
- # - Ending the second bulleted list
70
- def second_bulleted_list_rendering_test_method; end
71
-
72
- # 1. First numbered list item
73
- # 2. Second numbered list
74
- # 1. Nested numbered list item
75
- # 2. Second nested numbered list item
76
- # 3. Ending the main numbered list item
77
- def numbered_list_rendering_test_method; end
78
-
79
- # a. Some goes for lettered lists
80
- # b. Second item in a lettered list
81
- # a. And a nested lettered list item
82
- # c. Second nested lettered list item
83
- # c. Ending the main lettered list item.
84
- def lettered_list_rendering_test_method; end
85
-
86
- # * A mixed list, containing
87
- # * bullets in the main list
88
- # 1. And numbers in a sublist
89
- def mixed_list_rendering_test_method; end
90
-
91
- # 1. Also in reverse
92
- # 2. Second item
93
- # * Nested bulleted list
94
- def second_mixed_list_rendering_test_method; end
95
-
96
- # [First] And this is the list item body
97
- # With a second line containing more text
98
- #
99
- # [Second] Another labled list item
100
- def labeled_list_rendering_test_method; end
101
-
102
- # First:: With some text.
103
- # Secondarily:: Lets see if this lines up.
104
- def lined_up_labeled_list_rendering_test_method; end
105
-
106
- # * a list item
107
- # with a long item text
108
- # Containing verbatim text
109
- def list_containing_verbatim_text_rendering_test_method; end
110
-
111
- # Text with stylings: *bold*, _emphasized_ and +monospaced+.
112
- def simple_styling_rendering_test_method; end
113
-
114
- # Also with html: <b>Bold</b>, <em>emphasized</em>, <i>also emphasized</i>
115
- # and <tt>monospaced tt</tt> or <code>monospaced code</code>.
116
- def html_styling_rendering_test_method; end
117
-
118
- # These should not be styled: \<b>Not bold\</b>, \<em>not emphasized\</em>.
119
- def escaped_styling_rendering_test_method; end
120
-
121
- # Furthermore, this text contains links to raw links http://www.google.com mailto:spamidyspam@spam.com ftp://warez.teuto.de and plain web links: www.test.com .
122
- #
123
- # Then we have local links to other files: link:/etc/fstab
124
- def raw_link_rendering_test_method; end
125
-
126
- # Plus: Labled links SingleWordLabel[http://duckduckgo.com] and
127
- # {Multi Word Labels}[http://www.github.com].
128
- def labeled_link_rendering_test_method; end
129
-
130
- # Conversion characters: this: -- or --- should be an em-dash. We also have an ellipsis: ... . Copyright: (c) and registered trademark (r).
131
- def conversion_character_rendering_test_method; end
132
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bri::Mall do
4
- # NOTE the specs here are commented out until I figure out how to properly
5
- # test singletons. Otherwise specs will fail in a bulk run while
6
- # running fine on their own
7
- subject { Bri::Mall.instance }
8
-
9
- before( :each ) do
10
- RDoc::RI::Paths.stub!( :each ).
11
- and_yield( "store1_path", "store1_type" ).
12
- and_yield( "store2_path", "store2_type" )
13
- RDoc::RI::Store.stub!( :new ).
14
- and_return { mock( RDoc::RI::Store, :load_cache=> true ) }
15
- end
16
-
17
- # describe "the instance" do
18
-
19
- # its( :stores ) { should have(2).objects }
20
- # end
21
-
22
- # describe "#classes" do
23
- # it "should query all stores for their modules" do
24
- # subject.stores.each do |store|
25
- # store.should_receive( :modules ).and_return( true )
26
- # end
27
-
28
- # subject.classes
29
- # end
30
-
31
- # it "should return a sorted array of unique class names" do
32
- # subject.stores.first.stub!( :modules => [ "C", "B", "A" ] )
33
- # subject.stores.last.stub!( :modules => [ "Z", "B", "C" ] )
34
- # subject.classes.should == [ "A", "B", "C", "Z" ]
35
- # end
36
- # end
37
-
38
- end
@@ -1,125 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bri::Match::Class do
4
- let( :fully_developed_class ) do
5
- search_instance = Bri::Search::Class.new( "BriDummySpecClassTwo" )
6
- search_instance.search
7
- search_instance.matches.first
8
- end
9
-
10
- let( :empty_class ) do
11
- search_instance = Bri::Search::Class.new( "BriDummySpecClassEmpty" )
12
- search_instance.search
13
- search_instance.matches.first
14
- end
15
-
16
- let( :empty_module ) do
17
- search_instance = Bri::Search::Class.new( "BriDummySpecModule" )
18
- search_instance.search
19
- search_instance.matches.first
20
- end
21
-
22
- let( :namespaced_class ) do
23
- search_instance = Bri::Search::Class.new( "BriDummySpec::Class" )
24
- search_instance.search
25
- search_instance.matches.first
26
- end
27
-
28
- describe "#type" do
29
- it "should be class for a class" do
30
- empty_class.type.should == "class"
31
- end
32
-
33
- it "should be module for a module" do
34
- empty_module.type.should == "module"
35
- end
36
- end
37
-
38
- describe "#name" do
39
- it "should contain the name of a class" do
40
- empty_class.name.should == "BriDummySpecClassEmpty < Object"
41
- end
42
-
43
- it "should contain the fully qualified name of a namespaced class" do
44
- namespaced_class.name.should == "BriDummySpec::Class < Object"
45
- end
46
- end
47
-
48
- describe "#description_paragraphs" do
49
- it "should be empty for an undocumented class" do
50
- empty_class.description_paragraphs.should == []
51
- end
52
-
53
- it "should contain rendered text for a documented class" do
54
- fully_developed_class.description_paragraphs.size.should == 1
55
- fully_developed_class.description_paragraphs.first.should =~ /This is a class description/
56
- end
57
- end
58
-
59
- describe "#includes" do
60
- it "should be empty for a class without includes" do
61
- empty_class.includes.should be_empty
62
- end
63
-
64
- it "should contain a list of includes for classes with includes" do
65
- fully_developed_class.includes.size.should == 1
66
- fully_developed_class.includes.should include( "BriDummySpecModule" )
67
- end
68
- end
69
-
70
- describe "#constants" do
71
- it "should be empty for a class without constants" do
72
- empty_class.constants.should be_empty
73
- end
74
-
75
- it "should contain a list of constants for classes with constants" do
76
- fully_developed_class.constants.size.should == 2
77
- fully_developed_class.constants.should include( "CONSTANT" )
78
- fully_developed_class.constants.should include( "OTHER_CONSTANT" )
79
- end
80
- end
81
-
82
- describe "#attributes" do
83
- it "should be empty for a class without attributes" do
84
- empty_class.attributes.should be_empty
85
- end
86
-
87
- it "should contain a list of attributes for classes with attr_* declarations" do
88
- fully_developed_class.attributes.should_not be_empty
89
- end
90
-
91
- it "should mark attr_readers as read only" do
92
- fully_developed_class.attributes.should include( "read_attr (R)" )
93
- end
94
-
95
- it "should mark attr_writers as write only" do
96
- fully_developed_class.attributes.should include( "write_attr (W)" )
97
- end
98
-
99
- it "should mark attr_accessors as read/writeable" do
100
- fully_developed_class.attributes.should include( "access_attr (RW)" )
101
- end
102
- end
103
-
104
- describe "#class_methods" do
105
- it "should be empty for a class without class methods" do
106
- empty_class.class_methods.should be_empty
107
- end
108
-
109
- it "should contain class methods for classes with class methods" do
110
- fully_developed_class.class_methods.size.should == 1
111
- fully_developed_class.class_methods.first.should == "bri_dummy_spec_second_singleton_method"
112
- end
113
- end
114
-
115
- describe "#instance_methods" do
116
- it "should be empty for a class without instance methods" do
117
- empty_class.instance_methods.should be_empty
118
- end
119
-
120
- it "should contain class methods for classes with class methods" do
121
- fully_developed_class.instance_methods.size.should == 1
122
- fully_developed_class.instance_methods.first.should == "bri_dummy_spec_instance_method_with_arguments"
123
- end
124
- end
125
- end
@@ -1,112 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Bri::Match::Method do
4
- let( :fake_paragraph ) do
5
- RDoc::Markup::Paragraph.new "This is line one", "This is line two"
6
- end
7
-
8
- let( :fake_description ) do
9
- double( RDoc::Markup::Document, :parts => [ fake_paragraph ] )
10
- end
11
-
12
- let( :rdoc_method ) do
13
- double( RDoc::AnyMethod, :full_name => "This::IS::My.full_name",
14
- :arglists => "First\nSecond\nThird",
15
- :comment => fake_description )
16
- end
17
-
18
- describe "#initialize" do
19
- subject { Bri::Match::Method.new( rdoc_method ) }
20
-
21
- its( :full_name ) { should == rdoc_method.full_name }
22
- its( :call_syntaxes ) { should == " First\n Second\n Third\n" }
23
- its( :description_paragraphs ) { should == [ " This is line one This is line two" ] }
24
- end
25
-
26
- describe "#full_name" do
27
- subject do
28
- search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method" )
29
- search_instance.search( :fully_qualified )
30
- search_instance.matches.first
31
- end
32
-
33
- its( :full_name ) { should == "BriDummySpecClass#bri_dummy_spec_instance_method" }
34
- end
35
-
36
- describe "#call_syntaxes" do
37
- context "for methods with no arguments" do
38
- subject do
39
- search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method" )
40
- search_instance.search( :fully_qualified )
41
- search_instance.matches.first
42
- end
43
-
44
- its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method()\n" }
45
- end
46
-
47
- context "for methods with arguments" do
48
- subject do
49
- search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method_with_arguments" )
50
- search_instance.search( :fully_qualified )
51
- search_instance.matches.first
52
- end
53
-
54
- its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method_with_arguments( a, b )\n" }
55
- end
56
-
57
- context "for methods with default arguments" do
58
- subject do
59
- search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method_with_default_arguments" )
60
- search_instance.search( :fully_qualified )
61
- search_instance.matches.first
62
- end
63
-
64
- its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method_with_default_arguments( a, b, c = nil )\n" }
65
- end
66
-
67
- context "for methods that yield" do
68
- subject do
69
- search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method_which_yields" )
70
- search_instance.search( :fully_qualified )
71
- search_instance.matches.first
72
- end
73
-
74
- its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method_which_yields() { |yield_param_one, yield_param_two| ... }\n" }
75
- end
76
-
77
- context "for methods with an rdoc yield override" do
78
- subject do
79
- search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method_with_yield_override" )
80
- search_instance.search( :fully_qualified )
81
- search_instance.matches.first
82
- end
83
-
84
- its( :call_syntaxes ) { should == " bri_dummy_spec_instance_method_with_yield_override() { |foo, bar| ... }\n" }
85
- end
86
- end
87
-
88
- describe "#description_paragraphs" do
89
- context "for an undocumented method" do
90
- subject do
91
- search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#bri_dummy_spec_instance_method" )
92
- search_instance.search( :fully_qualified )
93
- search_instance.matches.first
94
- end
95
-
96
- its( :description_paragraphs ) { should == [] }
97
- end
98
-
99
- context "for a documented method" do
100
- subject do
101
- search_instance = Bri::Search::InstanceMethod.new( "BriDummySpecClass#basic_headline_and_paragraph_rendering_test_method" )
102
- search_instance.search( :fully_qualified )
103
- search_instance.matches.first
104
- end
105
-
106
- its( :description_paragraphs ) { should_not be_empty }
107
- it "should contain rendered paragraphs as the array elements" do
108
- subject.description_paragraphs.first.should =~ /This is a headline/
109
- end
110
- end
111
- end
112
- end