yard 0.8.3 → 0.8.4

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 (64) hide show
  1. data/ChangeLog +197 -38
  2. data/LICENSE +1 -1
  3. data/README.md +15 -4
  4. data/docs/GettingStarted.md +6 -6
  5. data/docs/WhatsNew.md +5 -0
  6. data/docs/images/code-objects-class-diagram.png +0 -0
  7. data/docs/images/handlers-class-diagram.png +0 -0
  8. data/docs/images/overview-class-diagram.png +0 -0
  9. data/docs/images/parser-class-diagram.png +0 -0
  10. data/docs/images/tags-class-diagram.png +0 -0
  11. data/lib/yard/autoload.rb +2 -0
  12. data/lib/yard/cli/graph.rb +3 -2
  13. data/lib/yard/cli/server.rb +3 -0
  14. data/lib/yard/cli/yardoc.rb +1 -0
  15. data/lib/yard/code_objects/base.rb +60 -30
  16. data/lib/yard/code_objects/extra_file_object.rb +1 -1
  17. data/lib/yard/code_objects/proxy.rb +1 -0
  18. data/lib/yard/docstring.rb +36 -2
  19. data/lib/yard/docstring_parser.rb +25 -2
  20. data/lib/yard/handlers/base.rb +18 -2
  21. data/lib/yard/handlers/c/handler_methods.rb +1 -1
  22. data/lib/yard/handlers/processor.rb +3 -0
  23. data/lib/yard/handlers/ruby/class_handler.rb +1 -2
  24. data/lib/yard/handlers/ruby/dsl_handler_methods.rb +7 -1
  25. data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
  26. data/lib/yard/handlers/ruby/legacy/class_handler.rb +4 -3
  27. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +2 -2
  28. data/lib/yard/handlers/ruby/legacy/method_handler.rb +4 -4
  29. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +4 -4
  30. data/lib/yard/handlers/ruby/method_handler.rb +6 -6
  31. data/lib/yard/handlers/ruby/struct_handler_methods.rb +4 -4
  32. data/lib/yard/handlers/ruby/yield_handler.rb +4 -4
  33. data/lib/yard/i18n/locale.rb +16 -0
  34. data/lib/yard/parser/ruby/legacy/statement_list.rb +3 -0
  35. data/lib/yard/parser/ruby/ruby_parser.rb +9 -4
  36. data/lib/yard/rubygems/doc_manager.rb +16 -7
  37. data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
  38. data/lib/yard/tags/directives.rb +3 -2
  39. data/lib/yard/tags/overload_tag.rb +1 -1
  40. data/lib/yard/templates/helpers/html_helper.rb +5 -2
  41. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +3 -3
  42. data/lib/yard/version.rb +1 -1
  43. data/spec/cli/server_spec.rb +18 -0
  44. data/spec/code_objects/base_spec.rb +32 -1
  45. data/spec/handlers/base_spec.rb +9 -0
  46. data/spec/handlers/dsl_handler_spec.rb +12 -1
  47. data/spec/handlers/examples/dsl_handler_001.rb.txt +16 -1
  48. data/spec/handlers/examples/visibility_handler_001.rb.txt +5 -0
  49. data/spec/handlers/method_handler_spec.rb +3 -3
  50. data/spec/handlers/processor_spec.rb +12 -1
  51. data/spec/handlers/visibility_handler_spec.rb +5 -0
  52. data/spec/parser/ruby/ruby_parser_spec.rb +13 -0
  53. data/spec/parser/source_parser_spec.rb +38 -1
  54. data/spec/server/doc_server_helper_spec.rb +2 -0
  55. data/spec/tags/directives_spec.rb +8 -1
  56. data/spec/tags/overload_tag_spec.rb +1 -1
  57. data/spec/templates/helpers/html_helper_spec.rb +25 -5
  58. data/templates/default/class/setup.rb +1 -1
  59. data/templates/default/module/html/box_info.erb +1 -1
  60. data/templates/default/tags/html/example.erb +1 -1
  61. data/templates/default/tags/setup.rb +1 -1
  62. data/templates/guide/fulldoc/html/css/style.css +12 -5
  63. data/templates/guide/layout/html/layout.erb +4 -4
  64. metadata +3 -3
@@ -23,11 +23,11 @@ module YARD
23
23
  output << "<span class='tstring'>" if [:tstring_beg, :regexp_beg].include?(s[0])
24
24
  case s.first
25
25
  when :nl, :ignored_nl, :sp
26
- output << h(s.last)
26
+ output << h(s[1])
27
27
  when :ident
28
- output << "<span class='id identifier rubyid_#{h(s.last)}'>#{h(s.last)}</span>"
28
+ output << "<span class='id identifier rubyid_#{h(s[1])}'>#{h(s[1])}</span>"
29
29
  else
30
- output << "<span class='#{s.first}'>#{h(s.last)}</span>"
30
+ output << "<span class='#{s.first}'>#{h(s[1])}</span>"
31
31
  end
32
32
  output << "</span>" if [:tstring_end, :regexp_end].include?(s[0])
33
33
  end
@@ -1,3 +1,3 @@
1
1
  module YARD
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
@@ -173,6 +173,24 @@ describe YARD::CLI::Server do
173
173
  run '--daemon'
174
174
  end
175
175
 
176
+ it "should accept -B, --bind" do
177
+ @server_options[:Host] = 'example.com'
178
+ run '-B', 'example.com'
179
+ run '--bind', 'example.com'
180
+ end
181
+
182
+ it "should bind address with WebRick adapter" do
183
+ @server_options[:Host] = 'example.com'
184
+ run '-B', 'example.com', '-a', 'webrick'
185
+ run '--bind', 'example.com', '-a', 'webrick'
186
+ end
187
+
188
+ it "should bind address with Rack adapter" do
189
+ @server_options[:Host] = 'example.com'
190
+ run '-B', 'example.com', '-a', 'rack'
191
+ run '--bind', 'example.com', '-a', 'rack'
192
+ end
193
+
176
194
  it "should accept -p, --port" do
177
195
  @server_options[:Port] = 10
178
196
  run '-p', '10'
@@ -333,6 +333,37 @@ describe YARD::CodeObjects::Base do
333
333
  ClassObject.new(:root, :AnotherObject) {|x| x.docstring = "FOO" }
334
334
  o.docstring.should == "FOO"
335
335
  end
336
+
337
+ describe 'localization' do
338
+ it "should return localized docstring" do
339
+ fr_locale = YARD::I18n::Locale.new('fr')
340
+ fr_locale.stub!(:translate).with('Hello').and_return('Bonjour')
341
+
342
+ o = ClassObject.new(:root, :Me)
343
+ o.docstring = 'Hello'
344
+ o.docstring.should == 'Hello'
345
+
346
+ Registry.stub!(:locale).with('fr').and_return(fr_locale)
347
+ o.docstring('fr').should == "Bonjour"
348
+ end
349
+
350
+ it "should return updated localized docstring" do
351
+ fr_locale = YARD::I18n::Locale.new('fr')
352
+ Registry.stub!(:locale).with('fr').and_return(fr_locale)
353
+
354
+ o = ClassObject.new(:root, :Me)
355
+ o.docstring = 'Hello'
356
+ o.docstring.should == 'Hello'
357
+
358
+ fr_locale.stub!(:translate).with('Hello').and_return('Bonjour')
359
+ o.docstring('fr').should == "Bonjour"
360
+
361
+ o.docstring = 'World'
362
+ fr_locale.stub!(:translate).with('World').and_return('Monde')
363
+ o.docstring('fr').should == "Monde"
364
+ o.docstring.should == 'World'
365
+ end
366
+ end
336
367
  end
337
368
 
338
369
  describe '#add_file' do
@@ -404,4 +435,4 @@ describe YARD::CodeObjects::Base do
404
435
  foo.copy_to(bar)
405
436
  end
406
437
  end
407
- end
438
+ end
@@ -40,6 +40,15 @@ describe YARD::Handlers::Base do
40
40
  end
41
41
  end
42
42
 
43
+ describe '#abort! (and HandlerAborted)' do
44
+ it 'should allow HandlerAborted to be raised' do
45
+ class AbortHandler1 < Handlers::Ruby::Base
46
+ process { abort! }
47
+ end
48
+ lambda { AbortHandler1.new(nil, nil).process }.should raise_error(HandlerAborted)
49
+ end
50
+ end
51
+
43
52
  describe 'transitive tags' do
44
53
  it "should add transitive tags to children" do
45
54
  Registry.clear
@@ -61,7 +61,7 @@ describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}DSLHandler" do
61
61
  obj = Registry.at('Foo.xyz')
62
62
  obj.should_not be_nil
63
63
  obj.signature.should == 'def xyz(a, b, c)'
64
- obj.parameters.should == [[:a, nil], [:b, nil], [:c, nil]]
64
+ obj.parameters.should == [['a', nil], ['b', nil], ['c', nil]]
65
65
  obj.source.should == 'foo_bar'
66
66
  obj.docstring.should == 'The foo method'
67
67
  end
@@ -163,6 +163,12 @@ describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}DSLHandler" do
163
163
  Registry.at('Baz#y_parser').should_not be_nil
164
164
  end
165
165
 
166
+ it "should look through mixins for attached macros" do
167
+ meth = Registry.at('Baz#mixin_method')
168
+ meth.should_not be_nil
169
+ meth.docstring.should == 'DSL method mixin_method'
170
+ end
171
+
166
172
  it "should handle top-level DSL methods" do
167
173
  obj = Registry.at('#my_other_method')
168
174
  obj.should_not be_nil
@@ -175,6 +181,11 @@ describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}DSLHandler" do
175
181
  obj.signature.should == 'def beep(a, b, c)'
176
182
  end
177
183
 
184
+ it "should expand attached macros in first DSL method" do
185
+ Registry.at('DSLMethods#foo').docstring.should == "Returns String for foo"
186
+ Registry.at('DSLMethods#bar').docstring.should == "Returns Integer for bar"
187
+ end
188
+
178
189
  it "should not detect implicit macros with invalid method names" do
179
190
  undoc_error <<-eof
180
191
  ##
@@ -93,13 +93,21 @@ class Foo
93
93
  a_module_function :modfunc1
94
94
  end
95
95
 
96
+ module MyMixin
97
+ # @!macro [attach] special
98
+ # DSL method $1
99
+ def defined_by_mixin; end
100
+ end
101
+
96
102
  class Bar
97
103
  parser :x_parser
98
104
  end
99
105
 
100
106
  class Baz < Foo
107
+ extend MyMixin
101
108
  parser :y_parser
102
109
  none { }
110
+ defined_by_mixin :mixin_method
103
111
  end
104
112
 
105
113
  # @!method my_other_method
@@ -107,4 +115,11 @@ end
107
115
  method_that_makes_a_method
108
116
 
109
117
  # @!macro something
110
- foobarbaz :beep
118
+ foobarbaz :beep
119
+
120
+ module DSLMethods
121
+ # @macro [attach] dsl_method
122
+ # Returns $2 for $1
123
+ dsl_method :foo, String
124
+ dsl_method :bar, Integer
125
+ end
@@ -24,4 +24,9 @@ class Testing
24
24
 
25
25
  def Foo; end
26
26
  private :Foo
27
+
28
+ private
29
+
30
+ class Bar; end
31
+ module Baz; end
27
32
  end
@@ -55,17 +55,17 @@ describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}MethodHandler"
55
55
 
56
56
  o1 = meth.tags(:overload).first
57
57
  o1.name.should == :bar
58
- o1.parameters.should == [[:a, nil], [:b, "1"]]
58
+ o1.parameters.should == [['a', nil], ['b', "1"]]
59
59
  o1.tag(:return).type.should == "String"
60
60
 
61
61
  o2 = meth.tags(:overload)[1]
62
62
  o2.name.should == :baz
63
- o2.parameters.should == [[:b, nil], [:c, nil]]
63
+ o2.parameters.should == [['b', nil], ['c', nil]]
64
64
  o2.tag(:return).type.should == "Fixnum"
65
65
 
66
66
  o3 = meth.tags(:overload)[2]
67
67
  o3.name.should == :bang
68
- o3.parameters.should == [[:d, nil], [:e, nil]]
68
+ o3.parameters.should == [['d', nil], ['e', nil]]
69
69
  o3.docstring.should be_empty
70
70
  o3.docstring.should be_blank
71
71
  end
@@ -20,4 +20,15 @@ describe YARD::Handlers::Processor do
20
20
  it "should have a globals structure" do
21
21
  @proc.globals.should be_a(OpenStruct)
22
22
  end
23
- end
23
+
24
+ it 'should ignore HandlerAborted exceptions (but print debug info)' do
25
+ class AbortHandlerProcessor < YARD::Handlers::Ruby::Base
26
+ process { abort! }
27
+ end
28
+ stmt = OpenStruct.new(:line => 1, :show => 'SOURCE')
29
+ @proc.stub!(:find_handlers).and_return([AbortHandlerProcessor])
30
+ log.should_receive(:debug).with(/AbortHandlerProcessor cancelled from/)
31
+ log.should_receive(:debug).with("\tin file '(stdin)':1:\n\nSOURCE\n")
32
+ @proc.process([stmt])
33
+ end
34
+ end
@@ -31,4 +31,9 @@ describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}VisibilityHand
31
31
  it "should handle constants passed in as symbols" do
32
32
  Registry.at('Testing#Foo').visibility.should == :private
33
33
  end
34
+
35
+ it 'should not register classes with visibility' do
36
+ Registry.at('Testing::Bar').visibility.should == :public
37
+ Registry.at('Testing::Baz').visibility.should == :public
38
+ end
34
39
  end
@@ -296,6 +296,19 @@ eof
296
296
  stmt("X = !1").jump(:unary).source.should == '!1'
297
297
  end
298
298
 
299
+ it "should have the correct line range for class/modules" do
300
+ s = stmt(<<-eof)
301
+ class Foo
302
+ def foo; end
303
+
304
+
305
+
306
+ # Ending comment
307
+ end
308
+ eof
309
+ s.jump(:class).line_range.should == (1..7)
310
+ end
311
+
299
312
  it "should find lone comments" do
300
313
  Registry.clear
301
314
  ast = YARD.parse_string(<<-eof).enumerator
@@ -628,6 +628,10 @@ describe YARD::Parser::SourceParser do
628
628
  end
629
629
 
630
630
  describe '#parse_statements' do
631
+ before do
632
+ Registry.clear
633
+ end
634
+
631
635
  it "should display a warning for invalid parser type" do
632
636
  log.should_receive(:warn).with(/unrecognized file/)
633
637
  log.should_receive(:backtrace)
@@ -644,7 +648,6 @@ describe YARD::Parser::SourceParser do
644
648
  end
645
649
 
646
650
  it "should handle groups" do
647
- Registry.clear
648
651
  YARD.parse_string <<-eof
649
652
  class A
650
653
  # @group Group Name
@@ -666,5 +669,39 @@ describe YARD::Parser::SourceParser do
666
669
  Registry.at('A#foo2').group.should == "Group Name"
667
670
  Registry.at('A#baz').group.should == "Group 2"
668
671
  end
672
+
673
+ it 'handles multi-line class/module references' do
674
+ YARD.parse_string <<-eof
675
+ class A::
676
+ B::C; end
677
+ eof
678
+ Registry.all.should == [P('A::B::C')]
679
+ end
680
+
681
+ it 'handles sclass definitions of multi-line class/module references' do
682
+ YARD.parse_string <<-eof
683
+ class << A::
684
+ B::C
685
+ def foo; end
686
+ end
687
+ eof
688
+ Registry.all.size.should == 2
689
+ Registry.at('A::B::C').should_not be_nil
690
+ Registry.at('A::B::C.foo').should_not be_nil
691
+ end
692
+
693
+ it 'handles lone comment blocks at the end of a namespace' do
694
+ YARD.parse_string <<-eof
695
+ module A
696
+ class B
697
+ def c; end
698
+
699
+ # @!method d
700
+ end
701
+ end
702
+ eof
703
+ Registry.at('A#d').should be_nil
704
+ Registry.at('A::B#d').should_not be_nil
705
+ end
669
706
  end
670
707
  end
@@ -22,6 +22,8 @@ class MockDocServerHelper
22
22
  @serializer = YARD::Server::DocServerSerializer.new
23
23
  @object = YARD::Registry.root
24
24
  end
25
+
26
+ def options; OpenStruct.new end
25
27
  end
26
28
 
27
29
  describe YARD::Server::DocServerHelper do
@@ -138,6 +138,13 @@ describe YARD::Tags::MacroDirective do
138
138
  baz.visibility.should == :public
139
139
  end
140
140
 
141
+ it "should expand macro if defined on class method and there is no data block" do
142
+ tag_parse("@!macro [new] attached3\n expanded_data")
143
+ baz = CodeObjects::MethodObject.new(P('Foo::Bar'), :baz, :class)
144
+ doc = DocstringParser.new.parse('@!macro attached3', baz, handler).to_docstring
145
+ doc.should == 'expanded_data'
146
+ end
147
+
141
148
  it "should not attempt to expand macro values if handler = nil" do
142
149
  tag_parse("@!macro [attach] xyz\n $1 $2 $3")
143
150
  end
@@ -243,7 +250,7 @@ describe YARD::Tags::MethodDirective do
243
250
  YARD.parse_string <<-eof
244
251
  # @!method foo(a, b, c = nil)
245
252
  eof
246
- Registry.at('#foo').parameters.should == [[:a, nil], [:b, nil], [:c, 'nil']]
253
+ Registry.at('#foo').parameters.should == [['a', nil], ['b', nil], ['c', 'nil']]
247
254
  end
248
255
 
249
256
  it "should be able to define method with module scope (module function)" do
@@ -12,7 +12,7 @@ describe YARD::Tags::OverloadTag do
12
12
 
13
13
  it "should parse the first line as a method signature" do
14
14
  @tag.signature.should == "def bar(a, b = 1, &block)"
15
- @tag.parameters.should == [[:a, nil], [:b, "1"], [:"&block", nil]]
15
+ @tag.parameters.should == [['a', nil], ['b', "1"], ['&block', nil]]
16
16
  end
17
17
 
18
18
  it "should parse the rest of the text as a new Docstring" do
@@ -207,6 +207,16 @@ describe YARD::Templates::Helpers::HtmlHelper do
207
207
  link_object("Bar").should =~ %r{>Bar</a>}
208
208
  end
209
209
 
210
+ it "should use #title if overridden" do
211
+ CodeObjects::ModuleObject.new(:root, :YARD)
212
+ CodeObjects::ClassObject.new(P('YARD'), :Bar)
213
+ Registry.at('YARD::Bar').stub(:title).and_return('TITLE!')
214
+ stub!(:object).and_return(Registry.at('YARD::Bar'))
215
+ serializer = Serializers::FileSystemSerializer.new
216
+ stub!(:serializer).and_return(serializer)
217
+ link_object("Bar").should =~ %r{>TITLE!</a>}
218
+ end
219
+
210
220
  it "should use relative path to parent class in title" do
211
221
  root = CodeObjects::ModuleObject.new(:root, :YARD)
212
222
  obj = CodeObjects::ModuleObject.new(root, :SubModule)
@@ -249,6 +259,16 @@ describe YARD::Templates::Helpers::HtmlHelper do
249
259
  url_for(P("Mod::Class#meth")).should be_nil
250
260
  end
251
261
 
262
+ it "should return nil if object is hidden" do
263
+ yard = CodeObjects::ModuleObject.new(:root, :YARD)
264
+
265
+ stub!(:serializer).and_return Serializers::FileSystemSerializer.new
266
+ stub!(:object).and_return Registry.root
267
+ stub!(:options).and_return OpenStruct.new(:verifier => Verifier.new('false'))
268
+
269
+ url_for(yard).should be_nil
270
+ end
271
+
252
272
  it "should return nil if serializer does not implement #serialized_path" do
253
273
  stub!(:serializer).and_return Serializers::Base.new
254
274
  stub!(:object).and_return Registry.root
@@ -516,7 +536,7 @@ describe YARD::Templates::Helpers::HtmlHelper do
516
536
  subject.should_receive(:respond_to?).with('html_syntax_highlight_NAME').and_return(true)
517
537
  subject.should_receive(:html_syntax_highlight_NAME).and_return("foobar")
518
538
  subject.htmlify('<pre><code>def x; end</code></pre>', :html).should ==
519
- '<pre class="code NAME"><code>foobar</code></pre>'
539
+ '<pre class="code NAME"><code class="NAME">foobar</code></pre>'
520
540
  end
521
541
 
522
542
  it "should add !!!LANG to className in outputted pre tag" do
@@ -525,7 +545,7 @@ describe YARD::Templates::Helpers::HtmlHelper do
525
545
  subject.should_receive(:respond_to?).with('html_syntax_highlight_LANG').and_return(true)
526
546
  subject.should_receive(:html_syntax_highlight_LANG).and_return("foobar")
527
547
  subject.htmlify("<pre><code>!!!LANG\ndef x; end</code></pre>", :html).should ==
528
- '<pre class="code LANG"><code>foobar</code></pre>'
548
+ '<pre class="code LANG"><code class="LANG">foobar</code></pre>'
529
549
  end
530
550
 
531
551
  it "should call html_syntax_highlight_NAME if source starts with !!!NAME" do
@@ -563,17 +583,17 @@ describe YARD::Templates::Helpers::HtmlHelper do
563
583
 
564
584
  it "shouldn't escape code snippets twice" do
565
585
  subject.htmlify('<pre lang="foo"><code>{"foo" => 1}</code></pre>', :html).should ==
566
- '<pre class="code foo"><code>{&quot;foo&quot; =&gt; 1}</code></pre>'
586
+ '<pre class="code foo"><code class="foo">{&quot;foo&quot; =&gt; 1}</code></pre>'
567
587
  end
568
588
 
569
589
  it "should highlight source when matching a pre lang= tag" do
570
590
  subject.htmlify('<pre lang="foo"><code>x = 1</code></pre>', :html).should ==
571
- '<pre class="code foo"><code>x = 1</code></pre>'
591
+ '<pre class="code foo"><code class="foo">x = 1</code></pre>'
572
592
  end
573
593
 
574
594
  it "should highlight source when matching a code class= tag" do
575
595
  subject.htmlify('<pre><code class="foo">x = 1</code></pre>', :html).should ==
576
- '<pre class="code foo"><code>x = 1</code></pre>'
596
+ '<pre class="code foo"><code class="foo">x = 1</code></pre>'
577
597
  end
578
598
  end
579
599
 
@@ -8,7 +8,7 @@ end
8
8
 
9
9
  def constructor_details
10
10
  ctors = object.meths(:inherited => true, :included => true)
11
- return unless @ctor = ctors.find {|o| o.name == :initialize }
11
+ return unless @ctor = ctors.find {|o| o.constructor? }
12
12
  return if prune_method_listing([@ctor]).empty?
13
13
  erb(:constructor_details)
14
14
  end
@@ -17,7 +17,7 @@
17
17
  <% n = 2 %>
18
18
  <% end %>
19
19
  <% [[:class, "Extended by"], [:instance, "Includes"]].each do |scope, name| %>
20
- <% if (mix = object.mixins(scope)).size > 0 %>
20
+ <% if (mix = run_verifier(object.mixins(scope))).size > 0 %>
21
21
  <dt class="r<%=n%>"><%= name %>:</dt>
22
22
  <dd class="r<%=n%>"><%= mix.sort_by {|o| o.path }.map {|o| linkify(o) }.join(", ") %></dd>
23
23
  <% n = n == 2 ? 1 : 2 %>