yard 0.7.1 → 0.7.2

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 (44) hide show
  1. data/ChangeLog +180 -0
  2. data/README.md +12 -3
  3. data/docs/GettingStarted.md +2 -2
  4. data/lib/yard.rb +1 -1
  5. data/lib/yard/autoload.rb +2 -1
  6. data/lib/yard/cli/command.rb +4 -2
  7. data/lib/yard/cli/server.rb +4 -3
  8. data/lib/yard/cli/stats.rb +2 -2
  9. data/lib/yard/cli/yardoc.rb +11 -9
  10. data/lib/yard/code_objects/macro_object.rb +2 -2
  11. data/lib/yard/config.rb +35 -1
  12. data/lib/yard/handlers/base.rb +1 -5
  13. data/lib/yard/handlers/ruby/legacy/macro_handler.rb +0 -1
  14. data/lib/yard/handlers/ruby/macro_handler.rb +0 -1
  15. data/lib/yard/handlers/ruby/macro_handler_methods.rb +1 -1
  16. data/lib/yard/logging.rb +13 -0
  17. data/lib/yard/parser/c_parser.rb +4 -8
  18. data/lib/yard/parser/ruby/legacy/statement_list.rb +1 -1
  19. data/lib/yard/parser/ruby/ruby_parser.rb +3 -3
  20. data/lib/yard/parser/source_parser.rb +1 -1
  21. data/lib/yard/server/commands/frames_command.rb +1 -1
  22. data/lib/yard/server/commands/library_command.rb +2 -1
  23. data/lib/yard/tags/library.rb +1 -1
  24. data/lib/yard/templates/helpers/html_helper.rb +13 -2
  25. data/lib/yard/templates/helpers/text_helper.rb +6 -2
  26. data/spec/cli/command_spec.rb +36 -0
  27. data/spec/cli/diff_spec.rb +2 -0
  28. data/spec/cli/server_spec.rb +7 -7
  29. data/spec/cli/yardoc_spec.rb +20 -4
  30. data/spec/handlers/examples/macro_handler_001.rb.txt +10 -0
  31. data/spec/handlers/examples/method_handler_001.rb.txt +12 -0
  32. data/spec/handlers/macro_handler_spec.rb +17 -0
  33. data/spec/handlers/method_handler_spec.rb +8 -0
  34. data/spec/parser/base_spec.rb +2 -1
  35. data/spec/parser/c_parser_spec.rb +30 -2
  36. data/spec/parser/ruby/ruby_parser_spec.rb +9 -0
  37. data/spec/registry_spec.rb +23 -11
  38. data/spec/templates/helpers/html_helper_spec.rb +39 -3
  39. data/spec/templates/helpers/shared_signature_examples.rb +10 -0
  40. data/spec/templates/helpers/text_helper_spec.rb +2 -1
  41. data/spec/templates/onefile_spec.rb +3 -3
  42. data/templates/default/fulldoc/html/setup.rb +0 -2
  43. data/templates/default/onefile/html/setup.rb +1 -0
  44. metadata +4 -3
@@ -166,4 +166,12 @@ describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}MethodHandler"
166
166
  log.should_receive(:warn).with(/Invalid.+macro name.+Foo\.foo/)
167
167
  YARD.parse_string "class Foo\n# @macro\ndef self.foo; end\nend"
168
168
  end
169
+
170
+ it "should handle 'def end' methods" do
171
+ obj = Registry.at('F::A#foo')
172
+ obj.should_not be_nil
173
+ obj = Registry.at('F::A#bar')
174
+ obj.should_not be_nil
175
+ obj.docstring.should == 'PASS'
176
+ end
169
177
  end
@@ -5,7 +5,8 @@ describe YARD::Parser::Base do
5
5
  class MyParser < Parser::Base; def initialize(a, b) end end
6
6
 
7
7
  it "should take 2 arguments" do
8
- lambda { YARD::Parser::Base.new }.should raise_error(ArgumentError, /wrong (number|#) of arguments/)
8
+ lambda { YARD::Parser::Base.new }.should raise_error(ArgumentError,
9
+ /wrong (number|#) of arguments|given 0, expected 2/)
9
10
  end
10
11
 
11
12
  it "should raise NotImplementedError on #initialize" do
@@ -1,11 +1,14 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
  begin require 'continuation'; rescue LoadError; end unless RUBY18
3
3
 
4
+ class YARD::Parser::CParser; def ensure_loaded!(a, b=1) a end end
5
+
4
6
  describe YARD::Parser::CParser do
5
7
  describe '#parse' do
6
8
  before(:all) do
7
9
  file = File.join(File.dirname(__FILE__), 'examples', 'array.c.txt')
8
- @parser = Parser::CParser.new(IO.read(file)).parse
10
+ @parser = Parser::CParser.new(IO.read(file))
11
+ @parser.parse
9
12
  end
10
13
 
11
14
  describe 'Array class' do
@@ -48,6 +51,31 @@ describe YARD::Parser::CParser do
48
51
  Registry.at('Multifile#extra').docstring.should == ''
49
52
  end
50
53
  end
54
+
55
+ describe 'Foo' do
56
+ def parse
57
+ Registry.clear
58
+ Parser::CParser.new(@contents).parse
59
+ end
60
+
61
+ it 'should not include comments in docstring source' do
62
+ @contents = <<-eof
63
+ /*
64
+ * Hello world
65
+ */
66
+ VALUE foo(VALUE x) {
67
+ int value = x;
68
+ }
69
+
70
+ void Init_Foo() {
71
+ rb_define_method(rb_cFoo, "foo", foo, 1);
72
+ }
73
+ eof
74
+ parse
75
+ Registry.at('Foo#foo').source.gsub(/\s\s+/, ' ').should ==
76
+ "VALUE foo(VALUE x) { int value = x;\n}"
77
+ end
78
+ end
51
79
  end
52
80
 
53
81
  describe '#find_override_comment' do
@@ -89,4 +117,4 @@ describe YARD::Parser::CParser do
89
117
  neg_self.source.should be_nil
90
118
  end
91
119
  end
92
- end if CONTINUATIONS_SUPPORTED
120
+ end
@@ -203,5 +203,14 @@ describe YARD::Parser::Ruby::RubyParser do
203
203
  src = "%w(\na b c\n d e f\n)"
204
204
  stmt(src).jump(:qwords_literal).source.should == src
205
205
  end
206
+
207
+ it "should parse %w() array in constant declaration" do
208
+ s = stmt(<<-eof)
209
+ class Foo
210
+ FOO = %w( foo bar )
211
+ end
212
+ eof
213
+ s.jump(:qwords_literal).source.should == '%w( foo bar )'
214
+ end
206
215
  end
207
216
  end if HAVE_RIPPER
@@ -1,6 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), "spec_helper")
2
2
  include CodeObjects
3
3
 
4
+ require "thread"
5
+
4
6
  describe YARD::Registry do
5
7
  before { Registry.clear }
6
8
 
@@ -247,38 +249,48 @@ describe YARD::Registry do
247
249
  describe 'Thread local' do
248
250
  it "should maintain two Registries in separate threads" do
249
251
  barrier = 0
252
+ mutex = Mutex.new
250
253
  threads = []
251
- threads << Thread.new do
254
+ threads << Thread.new do
252
255
  Registry.clear
253
256
  YARD.parse_string "# docstring 1\nclass Foo; end"
254
- barrier += 1
255
- while barrier < 2 do end
257
+ mutex.synchronize { barrier += 1 }
258
+ while barrier < 2 do
259
+ s = "barrier < 2, spinning"
260
+ end
256
261
  Registry.at('Foo').docstring.should == "docstring 1"
257
262
  end
258
263
  threads << Thread.new do
259
264
  Registry.clear
260
265
  YARD.parse_string "# docstring 2\nclass Foo; end"
261
- barrier += 1
262
- while barrier < 2 do end
266
+ mutex.synchronize { barrier += 1 }
267
+ while barrier < 2 do
268
+ s = "barrier < 2, spinning"
269
+ end
263
270
  Registry.at('Foo').docstring.should == "docstring 2"
264
271
  end
265
272
  threads.each {|t| t.join }
266
273
  end
267
-
274
+
268
275
  it "should allow setting of yardoc_file in separate threads" do
269
276
  barrier = 0
277
+ mutex = Mutex.new
270
278
  threads = []
271
- threads << Thread.new do
279
+ threads << Thread.new do
272
280
  Registry.yardoc_file.should == '.yardoc'
273
281
  Registry.yardoc_file = 'foo'
274
- barrier += 1
275
- while barrier == 1 do end
282
+ mutex.synchronize { barrier += 1 }
283
+ while barrier == 1 do
284
+ s = "barrier = 1, spinning"
285
+ end
276
286
  Registry.yardoc_file.should == 'foo'
277
287
  end
278
288
  threads << Thread.new do
279
- while barrier == 0 do end
289
+ while barrier == 0 do
290
+ s = "barrier = 0, spinning"
291
+ end
280
292
  Registry.yardoc_file.should == '.yardoc'
281
- barrier += 1
293
+ mutex.synchronize { barrier += 1 }
282
294
  Registry.yardoc_file = 'foo2'
283
295
  end
284
296
  threads.each {|t| t.join }
@@ -30,12 +30,20 @@ describe YARD::Templates::Helpers::HtmlHelper do
30
30
  end
31
31
  end
32
32
 
33
+ it "should support utf8 as an encoding value for utf-8" do
34
+ type = 'utf8'
35
+ ENV.should_receive(:[]).with('LANG').and_return(type) if RUBY18
36
+ Encoding.default_external.should_receive(:name).and_return(type) if defined?(Encoding)
37
+ charset.should == 'utf-8'
38
+ end
39
+
33
40
  it "should take file encoding if there is a file" do
34
41
  @file = OpenStruct.new(:contents => 'foo'.force_encoding('sjis'))
35
42
  charset.should == 'Shift_JIS' # not the correct charset name, but good enough
36
43
  end if RUBY19
37
44
 
38
45
  it "should take file encoding if there is a file" do
46
+ ENV.stub!(:[]).with('LANG').and_return('utf-8') if RUBY18
39
47
  @file = OpenStruct.new(:contents => 'foo')
40
48
  charset.should == 'utf-8'
41
49
  end if RUBY18
@@ -110,6 +118,7 @@ describe YARD::Templates::Helpers::HtmlHelper do
110
118
  end
111
119
 
112
120
  it "should include file and htmlify it" do
121
+ load_markup_provider(:rdoc)
113
122
  File.should_receive(:file?).with('foo.rdoc').and_return(true)
114
123
  File.should_receive(:read).with('foo.rdoc').and_return('= HI')
115
124
  htmlify("{include:file:foo.rdoc}", :rdoc).gsub(/\s+/, '').should == "<p><h1>HI</h1></p>"
@@ -119,7 +128,18 @@ describe YARD::Templates::Helpers::HtmlHelper do
119
128
  log.enter_level(Logger::FATAL) do
120
129
  pending 'This test depends on markdown' unless markup_class(:markdown)
121
130
  end
122
- htmlify('http://example.com', :markdown).should include('<a href="http://example.com"')
131
+ htmlify('http://example.com', :markdown).chomp.should ==
132
+ '<p><a href="http://example.com">http://example.com</a></p>'
133
+ end
134
+
135
+ it "should not autolink URLs inside of {} (markdown specific)" do
136
+ log.enter_level(Logger::FATAL) do
137
+ pending 'This test depends on markdown' unless markup_class(:markdown)
138
+ end
139
+ htmlify('{http://example.com Title}', :markdown).chomp.should =~
140
+ %r{<p><a href="http://example.com".*>Title</a></p>}
141
+ htmlify('{http://example.com}', :markdown).chomp.should =~
142
+ %r{<p><a href="http://example.com".*>http://example.com</a></p>}
123
143
  end
124
144
  end
125
145
 
@@ -390,14 +410,30 @@ describe YARD::Templates::Helpers::HtmlHelper do
390
410
  :multitype => "- (Type, ...) <strong>foo</strong>",
391
411
  :void => "- (void) <strong>foo</strong>",
392
412
  :hide_void => "- <strong>foo</strong>",
393
- :block => "- (Object) <strong>foo</strong> {|a, b, c| ... }"
413
+ :block => "- (Object) <strong>foo</strong> {|a, b, c| ... }",
414
+ :empty_overload => '- (String) <strong>foobar</strong>'
394
415
  }
395
416
  end
396
417
 
397
418
  def format_types(types, brackets = false) types.join(", ") end
398
- def signature(obj) super(obj, false).strip end
419
+ def signature(obj, link = false) super(obj, link).strip end
399
420
 
400
421
  it_should_behave_like "signature"
422
+
423
+ it "should link to regular method if overload name does not have the same method name" do
424
+ YARD.parse_string <<-eof
425
+ class Foo
426
+ # @overload bar(a, b, c)
427
+ def foo; end
428
+ end
429
+ eof
430
+ serializer = mock(:serializer)
431
+ serializer.stub!(:serialized_path).with(Registry.at('Foo')).and_return('')
432
+ stub!(:serializer).and_return(serializer)
433
+ stub!(:object).and_return(Registry.at('Foo'))
434
+ signature(Registry.at('Foo#foo').tag(:overload), true).should ==
435
+ "<a href=\"#foo-instance_method\" title=\"#bar (instance method)\">- <strong>bar</strong>(a, b, c) </a>"
436
+ end
401
437
  end
402
438
 
403
439
  describe '#html_syntax_highlight' do
@@ -108,4 +108,14 @@ shared_examples_for "signature" do
108
108
  eof
109
109
  signature(Registry.at('#foo')).should == @results[:block]
110
110
  end
111
+
112
+ it "should use regular return tag if the @overload is empty" do
113
+ YARD.parse_string <<-'eof'
114
+ # @overload foobar
115
+ # Hello world
116
+ # @return [String]
117
+ def foo; end
118
+ eof
119
+ signature(Registry.at('#foo').tag(:overload)).should == @results[:empty_overload]
120
+ end
111
121
  end
@@ -20,7 +20,8 @@ describe YARD::Templates::Helpers::TextHelper do
20
20
  :multitype => "root.foo -> (Type, ...)",
21
21
  :void => "root.foo -> void",
22
22
  :hide_void => "root.foo",
23
- :block => "root.foo {|a, b, c| ... } -> Object"
23
+ :block => "root.foo {|a, b, c| ... } -> Object",
24
+ :empty_overload => 'root.foobar -> String'
24
25
  }
25
26
  end
26
27
 
@@ -30,11 +30,11 @@ describe YARD::Templates::Engine.template(:default, :onefile) do
30
30
  def bar; end
31
31
  end
32
32
  eof
33
+ readme = CodeObjects::ExtraFileObject.new('README',
34
+ "# This is a code comment\n\n# Top of file\n\n\nclass C; end")
33
35
  Templates::Engine.generate Registry.all(:class),
34
36
  :serializer => StringSerializer.new(files, string),
35
- :onefile => true, :format => :html, :files => [
36
- CodeObjects::ExtraFileObject.new('README',
37
- "# This is a code comment\n\n# Top of file\n\n\nclass C; end"),
37
+ :onefile => true, :format => :html, :readme => readme, :files => [readme,
38
38
  CodeObjects::ExtraFileObject.new('LICENSE', 'This is a license!')
39
39
  ]
40
40
  files.should == ['index.html']
@@ -2,8 +2,6 @@ include Helpers::ModuleHelper
2
2
 
3
3
  def init
4
4
  options[:objects] = objects = run_verifier(options[:objects])
5
- options[:files] = ([options[:readme]] + options[:files]).uniq.compact
6
- options[:readme] = options[:files].first
7
5
 
8
6
  return serialize_onefile if options[:onefile]
9
7
  generate_assets
@@ -17,6 +17,7 @@ end
17
17
  private
18
18
 
19
19
  def parse_top_comments_from_file
20
+ return @readme.contents unless @readme.filename =~ /\.rb$/
20
21
  data = ""
21
22
  tokens = TokenList.new(@readme.contents)
22
23
  tokens.each do |token|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: yard
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.7.1
5
+ version: 0.7.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Loren Segal
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-18 00:00:00 -04:00
13
+ date: 2011-06-14 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -207,6 +207,7 @@ files:
207
207
  - lib/yard/verifier.rb
208
208
  - lib/yard.rb
209
209
  - spec/cli/command_parser_spec.rb
210
+ - spec/cli/command_spec.rb
210
211
  - spec/cli/config_spec.rb
211
212
  - spec/cli/diff_spec.rb
212
213
  - spec/cli/gems_spec.rb
@@ -529,7 +530,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
529
530
  requirements: []
530
531
 
531
532
  rubyforge_project: yard
532
- rubygems_version: 1.3.8
533
+ rubygems_version: 1.3.9.1
533
534
  signing_key:
534
535
  specification_version: 3
535
536
  summary: Documentation tool for consistent and usable documentation in Ruby.