yard 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (47) hide show
  1. data/ChangeLog +162 -0
  2. data/README.md +20 -3
  3. data/docs/Glossary.md +2 -2
  4. data/docs/Overview.md +1 -1
  5. data/lib/yard.rb +1 -1
  6. data/lib/yard/cli/yardoc.rb +1 -0
  7. data/lib/yard/code_objects/base.rb +7 -0
  8. data/lib/yard/handlers/ruby/legacy/method_handler.rb +3 -1
  9. data/lib/yard/handlers/ruby/macro_handler_methods.rb +2 -1
  10. data/lib/yard/handlers/ruby/method_handler.rb +3 -1
  11. data/lib/yard/parser/c_parser.rb +48 -52
  12. data/lib/yard/parser/ruby/ruby_parser.rb +13 -1
  13. data/lib/yard/registry_store.rb +1 -1
  14. data/lib/yard/server/commands/library_command.rb +2 -1
  15. data/lib/yard/server/doc_server_helper.rb +3 -3
  16. data/lib/yard/server/doc_server_serializer.rb +9 -9
  17. data/lib/yard/server/rack_adapter.rb +1 -0
  18. data/lib/yard/server/router.rb +2 -0
  19. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +1 -1
  20. data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -2
  21. data/lib/yard/server/webrick_adapter.rb +1 -0
  22. data/lib/yard/templates/helpers/html_helper.rb +48 -22
  23. data/spec/cli/yardoc_spec.rb +17 -0
  24. data/spec/code_objects/base_spec.rb +1 -1
  25. data/spec/handlers/examples/method_handler_001.rb.txt +4 -0
  26. data/spec/handlers/macro_handler_spec.rb +9 -0
  27. data/spec/handlers/method_handler_spec.rb +7 -0
  28. data/spec/parser/c_parser_spec.rb +134 -9
  29. data/spec/parser/ruby/ruby_parser_spec.rb +17 -1
  30. data/spec/registry_spec.rb +1 -0
  31. data/spec/registry_store_spec.rb +2 -2
  32. data/spec/server/doc_server_helper_spec.rb +51 -0
  33. data/spec/server/doc_server_serializer_spec.rb +10 -23
  34. data/spec/server/rack_adapter_spec.rb +2 -0
  35. data/spec/server/router_spec.rb +8 -1
  36. data/spec/templates/class_spec.rb +2 -1
  37. data/spec/templates/examples/module001.html +1 -1
  38. data/spec/templates/examples/module003.html +186 -0
  39. data/spec/templates/helpers/html_helper_spec.rb +57 -31
  40. data/spec/templates/module_spec.rb +22 -0
  41. data/spec/templates/tag_spec.rb +12 -0
  42. data/templates/default/fulldoc/html/js/full_list.js +6 -0
  43. data/templates/default/module/html/inherited_attributes.erb +6 -9
  44. data/templates/default/module/html/inherited_constants.erb +8 -8
  45. data/templates/default/module/setup.rb +22 -0
  46. data/templates/default/tags/setup.rb +4 -0
  47. metadata +4 -2
@@ -236,7 +236,23 @@ describe YARD::Parser::Ruby::RubyParser do
236
236
  s.jump(:array).source.should == '%w( foo bar )'
237
237
  end
238
238
  end
239
-
239
+
240
+ it "should parse %w() array source in object[] parsed context" do
241
+ s = stmts(<<-eof)
242
+ {}[:key]
243
+ FOO = %w( foo bar )
244
+ eof
245
+ s[1].jump(:array).source.should == '%w( foo bar )'
246
+ end
247
+
248
+ it "should parse %w() array source in object[]= parsed context" do
249
+ s = stmts(<<-eof)
250
+ {}[:key] = :value
251
+ FOO = %w( foo bar )
252
+ eof
253
+ s[1].jump(:array).source.should == '%w( foo bar )'
254
+ end
255
+
240
256
  it "should parse [] as array" do
241
257
  s = stmt(<<-eof)
242
258
  class Foo
@@ -294,6 +294,7 @@ describe YARD::Registry do
294
294
  Registry.yardoc_file = 'foo2'
295
295
  end
296
296
  threads.each {|t| t.join }
297
+ Registry.yardoc_file = Registry::DEFAULT_YARDOC_FILE
297
298
  end
298
299
 
299
300
  it "should automatically clear in new threads" do
@@ -126,10 +126,10 @@ describe YARD::RegistryStore do
126
126
  saves_to_singledb
127
127
  end
128
128
 
129
- it "should not save as single object db if single_object_db is nil and there are more than 3000 objects" do
129
+ it "should save as single object db if single_object_db is nil and there are more than 3000 objects" do
130
130
  Registry.single_object_db = nil
131
131
  add_items(5000)
132
- saves_to_multidb
132
+ saves_to_singledb
133
133
  end
134
134
 
135
135
  it "should save as single object db if single_object_db is true (and any amount of objects)" do
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ class MyDocServerSerializerRouter
4
+ attr_accessor :request
5
+ def docs_prefix; 'PREFIX' end
6
+ def initialize; @request = mock_request end
7
+ end
8
+
9
+ class MockDocServerHelper
10
+ include YARD::Templates::Helpers::BaseHelper
11
+ include YARD::Templates::Helpers::HtmlHelper
12
+ include YARD::Server::DocServerHelper
13
+
14
+ attr_accessor :adapter
15
+ attr_accessor :single_library
16
+ attr_accessor :library
17
+
18
+ def initialize
19
+ @single_library = false
20
+ @library = LibraryVersion.new('foo')
21
+ @adapter = mock_adapter(:router => MyDocServerSerializerRouter.new)
22
+ @serializer = YARD::Server::DocServerSerializer.new
23
+ @object = YARD::Registry.root
24
+ end
25
+ end
26
+
27
+ describe YARD::Server::DocServerHelper do
28
+ before do
29
+ @helper = MockDocServerHelper.new
30
+ end
31
+
32
+ describe '#url_for' do
33
+ it "should not link to /library/ if single_library = true" do
34
+ @helper.single_library = true
35
+ @helper.url_for(Registry.root).should == "/PREFIX/toplevel"
36
+ end
37
+
38
+ it "should return /PREFIX/foo/version if foo has a version" do
39
+ @helper.library = LibraryVersion.new('foo', 'bar')
40
+ @helper.adapter.router.request.version_supplied = true
41
+ @helper.url_for(P('A')).should == '/PREFIX/foo/bar/A'
42
+ end
43
+ end
44
+
45
+ describe '#url_for_file' do
46
+ it "should properly link file objects using file/ prefix" do
47
+ file = CodeObjects::ExtraFileObject.new('a/b/FooBar.md', '')
48
+ @helper.url_for_file(file).should == '/PREFIX/foo/file/a/b/FooBar.md'
49
+ end
50
+ end
51
+ end
@@ -1,58 +1,45 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- class MyDocServerSerializerRouter
4
- def docs_prefix; 'PREFIX' end
5
- end
6
-
7
3
  describe YARD::Server::DocServerSerializer do
8
4
  describe '#serialized_path' do
9
5
  before do
10
6
  Registry.clear
11
- @command = mock(:command)
12
- @command.stub!(:single_library).and_return(false)
13
- @command.stub!(:library).and_return(LibraryVersion.new('foo'))
14
- @command.stub!(:adapter).and_return(mock_adapter(:router => MyDocServerSerializerRouter.new))
15
- @serializer = Server::DocServerSerializer.new(@command)
7
+ @serializer = Server::DocServerSerializer.new
16
8
  end
17
9
 
18
10
  after(:all) { Server::Adapter.shutdown }
19
11
 
20
12
  it "should return '/PREFIX/library/toplevel' for root" do
21
- @serializer.serialized_path(Registry.root).should == "/PREFIX/foo/toplevel"
13
+ @serializer.serialized_path(Registry.root).should == "toplevel"
22
14
  end
23
15
 
24
16
  it "should return /PREFIX/library/Object for Object in a library" do
25
- @serializer.serialized_path(P('A::B::C')).should == '/PREFIX/foo/A/B/C'
17
+ @serializer.serialized_path(P('A::B::C')).should == 'A/B/C'
26
18
  end
27
19
 
28
20
  it "should link to instance method as Class:method" do
29
21
  obj = CodeObjects::MethodObject.new(:root, :method)
30
- @serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel:method'
22
+ @serializer.serialized_path(obj).should == 'toplevel:method'
31
23
  end
32
24
 
33
25
  it "should link to class method as Class.method" do
34
26
  obj = CodeObjects::MethodObject.new(:root, :method, :class)
35
- @serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel.method'
27
+ @serializer.serialized_path(obj).should == 'toplevel.method'
36
28
  end
37
29
 
38
30
  it "should link to anchor for constant" do
39
31
  obj = CodeObjects::ConstantObject.new(:root, :FOO)
40
- @serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel#FOO-constant'
32
+ @serializer.serialized_path(obj).should == 'toplevel#FOO-constant'
41
33
  end
42
34
 
43
35
  it "should link to anchor for class variable" do
44
36
  obj = CodeObjects::ClassVariableObject.new(:root, :@@foo)
45
- @serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel#@@foo-classvariable'
46
- end
47
-
48
- it "should not link to /library/ if single_library = true" do
49
- @command.stub!(:single_library).and_return(true)
50
- @serializer.serialized_path(Registry.root).should == "/PREFIX/toplevel"
37
+ @serializer.serialized_path(obj).should == 'toplevel#@@foo-classvariable'
51
38
  end
52
39
 
53
- it "should return /PREFIX/foo/version if foo has a version" do
54
- @command.stub!(:library).and_return(LibraryVersion.new('foo', 'bar'))
55
- @serializer.serialized_path(P('A')).should == '/PREFIX/foo/bar/A'
40
+ it "should link files using file/ prefix" do
41
+ file = CodeObjects::ExtraFileObject.new('a/b/FooBar.md', '')
42
+ @serializer.serialized_path(file).should == 'file/FooBar'
56
43
  end
57
44
  end
58
45
  end
@@ -7,6 +7,8 @@ describe "YARD::Server::RackMiddleware" do
7
7
  @app = YARD::Server::RackMiddleware.new(@superapp, :libraries => {'foo' => [LibraryVersion.new('foo', nil)]})
8
8
  end
9
9
 
10
+ after(:all) { YARD::Server::Adapter.shutdown }
11
+
10
12
  it "should handle requests" do
11
13
  @app.call(Rack::MockRequest.env_for('/'))[0].should == 200
12
14
  end
@@ -12,23 +12,30 @@ describe YARD::Server::Router do
12
12
  before do
13
13
  @adapter = mock_adapter
14
14
  @projects = @adapter.libraries['project']
15
+ @request = mock_request
15
16
  end
16
17
 
17
18
  describe '#parse_library_from_path' do
18
19
  def parse(*args)
19
- MyRouterSpecRouter.new(@adapter).parse_library_from_path(args.flatten)
20
+ @request.path = '/' + args.join('/')
21
+ @router = MyRouterSpecRouter.new(@adapter)
22
+ @router.request = @request
23
+ @router.parse_library_from_path(args.flatten)
20
24
  end
21
25
 
22
26
  it "should parse library and version name out of path" do
23
27
  parse('project', '1.0.0').should == [@projects[0], []]
28
+ @request.version_supplied.should be_true
24
29
  end
25
30
 
26
31
  it "should parse library and use latest version if version is not supplied" do
27
32
  parse('project').should == [@projects[1], []]
33
+ @request.version_supplied.should be_false
28
34
  end
29
35
 
30
36
  it "should parse library and use latest version if next component is not a version" do
31
37
  parse('project', 'notaversion').should == [@projects[1], ['notaversion']]
38
+ @request.version_supplied.should be_false
32
39
  end
33
40
 
34
41
  it "should return nil library if no library is found" do
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe YARD::Templates::Engine.template(:default, :docstring) do
4
4
  before do
5
+ Registry.clear
5
6
  YARD.parse_string <<-'eof'
6
7
  private
7
8
  # Comments
@@ -40,4 +41,4 @@ describe YARD::Templates::Engine.template(:default, :docstring) do
40
41
  it "should hide private constructors" do
41
42
  html_equals(Registry.at('D').format(:format => :html, :no_highlight => true, :verifier => Verifier.new("!@private")), :class002)
42
43
  end
43
- end
44
+ end
@@ -204,7 +204,7 @@ and newlines.
204
204
 
205
205
 
206
206
  <h3 class="inherited">Attributes included from BaseMod</h3>
207
- <p class="inherited">base_attr1, base_attr2, base_attr3</p>
207
+ <p class="inherited">#base_attr1, #base_attr2, #base_attr3</p>
208
208
 
209
209
 
210
210
 
@@ -0,0 +1,186 @@
1
+ <h1>Module: A
2
+
3
+
4
+
5
+ </h1>
6
+
7
+ <dl class="box">
8
+
9
+
10
+
11
+
12
+
13
+ <dt class="r1">Includes:</dt>
14
+ <dd class="r1">B</dd>
15
+
16
+
17
+
18
+
19
+
20
+ <dt class="r2 last">Defined in:</dt>
21
+ <dd class="r2 last">(stdin)</dd>
22
+
23
+ </dl>
24
+ <div class="clear"></div>
25
+
26
+
27
+ <h2>Constant Summary</h2>
28
+
29
+ <dl class="constants">
30
+
31
+ <dt id="FOO-constant" class="">FOO =
32
+
33
+ </dt>
34
+ <dd><pre class="code">2</pre></dd>
35
+
36
+ </dl>
37
+
38
+
39
+
40
+
41
+
42
+ <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
43
+ <ul class="summary">
44
+
45
+ <li class="public ">
46
+ <span class="summary_signature">
47
+
48
+ <a title="#bar (instance method)">- <strong>bar</strong> </a>
49
+
50
+
51
+
52
+ </span>
53
+
54
+
55
+ <span class="note title readonly">readonly</span>
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ <span class="summary_desc"><div class='inline'>Returns the value of attribute bar.</div></span>
65
+
66
+ </li>
67
+
68
+
69
+ </ul>
70
+
71
+
72
+
73
+
74
+
75
+ <h2>
76
+ Instance Method Summary
77
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
78
+ </h2>
79
+
80
+ <ul class="summary">
81
+
82
+ <li class="public ">
83
+ <span class="summary_signature">
84
+
85
+ <a title="#foo (instance method)">- <strong>foo</strong> </a>
86
+
87
+
88
+
89
+ </span>
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+ <span class="summary_desc"><div class='inline'></div></span>
99
+
100
+ </li>
101
+
102
+
103
+ </ul>
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+ <div id="instance_attr_details" class="attr_details">
113
+ <h2>Instance Attribute Details</h2>
114
+
115
+
116
+ <span id=""></span>
117
+ <span id="bar-instance_method"></span>
118
+ <div class="method_details first">
119
+ <p class="signature first" id="bar-instance_method">
120
+
121
+ - <strong>bar</strong> <span class="extras">(readonly)</span>
122
+
123
+
124
+
125
+ </p><div class="docstring">
126
+ <div class="discussion">
127
+ Returns the value of attribute bar
128
+
129
+ </div>
130
+ </div>
131
+ <div class="tags">
132
+
133
+
134
+ </div><table class="source_code">
135
+ <tr>
136
+ <td>
137
+ <pre class="lines">
138
+
139
+
140
+ 11
141
+ 12
142
+ 13</pre>
143
+ </td>
144
+ <td>
145
+ <pre class="code"><span class="info file"># File '(stdin)', line 11</span>
146
+
147
+ def bar
148
+ @bar
149
+ end</pre>
150
+ </td>
151
+ </tr>
152
+ </table>
153
+ </div>
154
+
155
+ </div>
156
+
157
+
158
+ <div id="instance_method_details" class="method_details_list">
159
+ <h2>Instance Method Details</h2>
160
+
161
+
162
+ <div class="method_details first">
163
+ <p class="signature first" id="foo-instance_method">
164
+
165
+ - <strong>foo</strong>
166
+
167
+
168
+
169
+ </p><table class="source_code">
170
+ <tr>
171
+ <td>
172
+ <pre class="lines">
173
+
174
+
175
+ 10</pre>
176
+ </td>
177
+ <td>
178
+ <pre class="code"><span class="info file"># File '(stdin)', line 10</span>
179
+
180
+ def foo; end</pre>
181
+ </td>
182
+ </tr>
183
+ </table>
184
+ </div>
185
+
186
+ </div>
@@ -142,7 +142,7 @@ describe YARD::Templates::Helpers::HtmlHelper do
142
142
  log.enter_level(Logger::FATAL) do
143
143
  pending 'This test depends on markdown' unless markup_class(:markdown)
144
144
  end
145
- htmlify('http://example.com', :markdown).chomp.should ==
145
+ htmlify('http://example.com', :markdown).chomp.gsub('&#47;', '/').should ==
146
146
  '<p><a href="http://example.com">http://example.com</a></p>'
147
147
  end
148
148
 
@@ -471,40 +471,46 @@ describe YARD::Templates::Helpers::HtmlHelper do
471
471
  end
472
472
 
473
473
  describe '#html_syntax_highlight' do
474
- before do
475
- stub!(:options).and_return(:no_highlight => false)
476
- stub!(:object).and_return(Registry.root)
477
- end
478
-
479
- def fix_rspec2_mock_teardown
480
- return unless defined?(RSpec)
481
- should_receive(:respond_to?).with(:teardown_mocks_for_rspec).and_return(false)
482
- should_receive(:respond_to?).with(:verify_mocks_for_rspec).and_return(false)
474
+ subject do
475
+ obj = OpenStruct.new
476
+ obj.options = {:no_highlight => false}
477
+ obj.object = Registry.root
478
+ obj.extend(Templates::Helpers::HtmlHelper)
479
+ obj
483
480
  end
484
481
 
485
482
  it "should return empty string on nil input" do
486
- html_syntax_highlight(nil).should == ''
483
+ subject.html_syntax_highlight(nil).should == ''
487
484
  end
488
485
 
489
486
  it "should call #html_syntax_highlight_ruby by default" do
490
487
  Registry.root.source_type = nil
491
- should_receive(:html_syntax_highlight_ruby).with('def x; end')
492
- html_syntax_highlight('def x; end')
488
+ subject.should_receive(:html_syntax_highlight_ruby).with('def x; end')
489
+ subject.html_syntax_highlight('def x; end')
493
490
  end
494
491
 
495
492
  it "should call #html_syntax_highlight_NAME if there's an object with a #source_type" do
496
- Registry.root.source_type = :NAME
497
- fix_rspec2_mock_teardown
498
- should_receive(:respond_to?).with('html_syntax_highlight_NAME').and_return(true)
499
- should_receive(:html_syntax_highlight_NAME).and_return("foobar")
500
- html_syntax_highlight('def x; end').should == 'foobar'
493
+ subject.object = OpenStruct.new(:source_type => :NAME)
494
+ subject.should_receive(:respond_to?).with('html_markup_html').and_return(true)
495
+ subject.should_receive(:respond_to?).with('html_syntax_highlight_NAME').and_return(true)
496
+ subject.should_receive(:html_syntax_highlight_NAME).and_return("foobar")
497
+ subject.htmlify('<pre><code>def x; end</code></pre>', :html).should ==
498
+ '<pre class="code NAME"><code>foobar</code></pre>'
499
+ end
500
+
501
+ it "should add !!!LANG to className in outputted pre tag" do
502
+ subject.object = OpenStruct.new(:source_type => :LANG)
503
+ subject.should_receive(:respond_to?).with('html_markup_html').and_return(true)
504
+ subject.should_receive(:respond_to?).with('html_syntax_highlight_LANG').and_return(true)
505
+ subject.should_receive(:html_syntax_highlight_LANG).and_return("foobar")
506
+ subject.htmlify("<pre><code>!!!LANG\ndef x; end</code></pre>", :html).should ==
507
+ '<pre class="code LANG"><code>foobar</code></pre>'
501
508
  end
502
509
 
503
510
  it "should call html_syntax_highlight_NAME if source starts with !!!NAME" do
504
- fix_rspec2_mock_teardown
505
- should_receive(:respond_to?).with('html_syntax_highlight_NAME').and_return(true)
506
- should_receive(:html_syntax_highlight_NAME).and_return("foobar")
507
- html_syntax_highlight(<<-eof
511
+ subject.should_receive(:respond_to?).with('html_syntax_highlight_NAME').and_return(true)
512
+ subject.should_receive(:html_syntax_highlight_NAME).and_return("foobar")
513
+ subject.html_syntax_highlight(<<-eof
508
514
  !!!NAME
509
515
  def x; end
510
516
  eof
@@ -512,21 +518,41 @@ describe YARD::Templates::Helpers::HtmlHelper do
512
518
  end
513
519
 
514
520
  it "should not highlight if :no_highlight option is true" do
515
- stub!(:options).and_return(:no_highlight => true)
516
- should_not_receive(:html_syntax_highlight_ruby)
517
- html_syntax_highlight('def x; end').should == 'def x; end'
521
+ subject.options[:no_highlight] = true
522
+ subject.should_not_receive(:html_syntax_highlight_ruby)
523
+ subject.html_syntax_highlight('def x; end').should == 'def x; end'
518
524
  end
519
525
 
520
526
  it "should not highlight if there is no highlight method specified by !!!NAME" do
521
- fix_rspec2_mock_teardown
522
- should_receive(:respond_to?).with('html_syntax_highlight_NAME').and_return(false)
523
- should_not_receive(:html_syntax_highlight_NAME)
524
- html_syntax_highlight("!!!NAME\ndef x; end").should == "def x; end"
527
+ subject.should_receive(:respond_to?).with('html_syntax_highlight_NAME').and_return(false)
528
+ subject.should_not_receive(:html_syntax_highlight_NAME)
529
+ subject.html_syntax_highlight("!!!NAME\ndef x; end").should == "def x; end"
525
530
  end
526
531
 
527
532
  it "should highlight as ruby if htmlify(text, :ruby) is called" do
528
- should_receive(:html_syntax_highlight_ruby).with('def x; end').and_return('x')
529
- htmlify('def x; end', :ruby).should == '<pre class="code ruby">x</pre>'
533
+ subject.should_receive(:html_syntax_highlight_ruby).with('def x; end').and_return('x')
534
+ subject.htmlify('def x; end', :ruby).should == '<pre class="code ruby">x</pre>'
535
+ end
536
+
537
+ it "should not prioritize object source type when called directly" do
538
+ subject.should_receive(:html_syntax_highlight_ruby).with('def x; end').and_return('x')
539
+ subject.object = OpenStruct.new(:source_type => :c)
540
+ subject.html_syntax_highlight("def x; end").should == "x"
541
+ end
542
+
543
+ it "shouldn't escape code snippets twice" do
544
+ subject.htmlify('<pre lang="foo"><code>{"foo" => 1}</code></pre>', :html).should ==
545
+ '<pre class="code foo"><code>{&quot;foo&quot; =&gt; 1}</code></pre>'
546
+ end
547
+
548
+ it "should highlight source when matching a pre lang= tag" do
549
+ subject.htmlify('<pre lang="foo"><code>x = 1</code></pre>', :html).should ==
550
+ '<pre class="code foo"><code>x = 1</code></pre>'
551
+ end
552
+
553
+ it "should highlight source when matching a code class= tag" do
554
+ subject.htmlify('<pre><code class="foo">x = 1</code></pre>', :html).should ==
555
+ '<pre class="code foo"><code>x = 1</code></pre>'
530
556
  end
531
557
  end
532
558