yard 0.8.1 → 0.8.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 (65) hide show
  1. data/ChangeLog +192 -0
  2. data/README.md +9 -2
  3. data/Rakefile +8 -14
  4. data/lib/yard.rb +1 -1
  5. data/lib/yard/autoload.rb +3 -2
  6. data/lib/yard/cli/graph.rb +28 -10
  7. data/lib/yard/cli/yardoc.rb +4 -1
  8. data/lib/yard/code_objects/proxy.rb +22 -17
  9. data/lib/yard/docstring_parser.rb +7 -7
  10. data/lib/yard/globals.rb +2 -2
  11. data/lib/yard/handlers/base.rb +3 -2
  12. data/lib/yard/handlers/c/handler_methods.rb +1 -0
  13. data/lib/yard/handlers/c/init_handler.rb +7 -5
  14. data/lib/yard/handlers/c/override_comment_handler.rb +9 -1
  15. data/lib/yard/handlers/ruby/class_condition_handler.rb +4 -2
  16. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +4 -2
  17. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -6
  18. data/lib/yard/handlers/ruby/mixin_handler.rb +3 -3
  19. data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
  20. data/lib/yard/i18n/locale.rb +50 -0
  21. data/lib/yard/i18n/text.rb +110 -9
  22. data/lib/yard/logging.rb +99 -8
  23. data/lib/yard/parser/c/c_parser.rb +1 -1
  24. data/lib/yard/parser/source_parser.rb +5 -4
  25. data/lib/yard/registry.rb +20 -12
  26. data/lib/yard/registry_store.rb +6 -1
  27. data/lib/yard/rubygems/doc_manager.rb +9 -5
  28. data/lib/yard/serializers/yardoc_serializer.rb +1 -0
  29. data/lib/yard/server/commands/base.rb +3 -2
  30. data/lib/yard/server/doc_server_serializer.rb +2 -0
  31. data/lib/yard/server/templates/default/method_details/html/permalink.erb +4 -0
  32. data/lib/yard/server/templates/default/method_details/html/setup.rb +4 -0
  33. data/lib/yard/tags/default_factory.rb +12 -4
  34. data/lib/yard/tags/directives.rb +1 -0
  35. data/lib/yard/templates/engine.rb +13 -6
  36. data/lib/yard/templates/template_options.rb +8 -1
  37. data/spec/cli/graph_spec.rb +10 -0
  38. data/spec/cli/yri_spec.rb +12 -2
  39. data/spec/code_objects/proxy_spec.rb +19 -3
  40. data/spec/handlers/c/class_handler_spec.rb +1 -2
  41. data/spec/handlers/c/init_handler_spec.rb +11 -0
  42. data/spec/handlers/c/override_comment_handler_spec.rb +3 -0
  43. data/spec/handlers/class_condition_handler_spec.rb +5 -0
  44. data/spec/handlers/dsl_handler_spec.rb +1 -0
  45. data/spec/handlers/examples/class_condition_handler_001.rb.txt +8 -0
  46. data/spec/handlers/mixin_handler_spec.rb +2 -1
  47. data/spec/i18n/locale_spec.rb +62 -0
  48. data/spec/i18n/text_spec.rb +144 -35
  49. data/spec/logging_spec.rb +21 -0
  50. data/spec/parser/c_parser_spec.rb +36 -0
  51. data/spec/parser/source_parser_spec.rb +11 -8
  52. data/spec/registry_spec.rb +26 -0
  53. data/spec/rubygems/doc_manager_spec.rb +112 -0
  54. data/spec/tags/default_factory_spec.rb +8 -2
  55. data/spec/tags/directives_spec.rb +7 -0
  56. data/spec/templates/examples/module001.html +0 -4
  57. data/spec/templates/examples/module002.html +0 -1
  58. data/spec/templates/examples/module003.html +0 -1
  59. data/spec/templates/examples/module004.html +171 -172
  60. data/spec/templates/module_spec.rb +4 -0
  61. data/templates/default/fulldoc/html/js/app.js +24 -18
  62. data/templates/default/fulldoc/html/setup.rb +5 -1
  63. data/templates/default/module/html/attribute_details.erb +1 -2
  64. metadata +9 -4
  65. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +0 -17
@@ -0,0 +1,112 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.join(YARD::ROOT, 'rubygems_plugin')
3
+ require 'fileutils'
4
+
5
+ describe Gem::DocManager do
6
+ before do
7
+ # Ensure filesystem integrity
8
+ FileUtils.stub(:mkdir_p)
9
+ FileUtils.stub(:rm_rf)
10
+ Dir.stub(:chdir)
11
+
12
+ YARD::CLI::Yardoc.stub(:run)
13
+
14
+ @spec_file = File.join(YARD::ROOT, '../yard.gemspec')
15
+ @spec = Gem::SourceIndex.load_specification(@spec_file)
16
+ @spec.has_yardoc = false # no yardoc docs for now
17
+ @yardopts = File.join(@spec.full_gem_path, '.yardopts')
18
+ @doc = Gem::DocManager.new(@spec)
19
+ @doc.stub(:install_ri_yard_orig)
20
+ @doc.stub(:install_rdoc_yard_orig)
21
+ end
22
+
23
+ def runs; YARD::CLI::Yardoc.should_receive(:run) end
24
+
25
+ describe '.load_yardoc' do
26
+ it "should properly load YARD" do
27
+ Gem::DocManager.should_receive(:require) do |path|
28
+ File.expand_path(path).should == YARD::ROOT + '/yard'
29
+ end
30
+ Gem::DocManager.load_yardoc
31
+ end
32
+ end
33
+
34
+ describe '#install_ri_yard' do
35
+ def install
36
+ msg = "Building YARD (yri) index for #{@spec.full_name}..."
37
+ @doc.should_receive(:say).with(msg)
38
+ @doc.install_ri_yard
39
+ end
40
+
41
+ it "should pass --quiet to all documentation" do
42
+ runs.with('-c', '-n', '--quiet', 'lib')
43
+ install
44
+ end
45
+
46
+ it "should pass extra_rdoc_files to documentation" do
47
+ @spec.extra_rdoc_files = %w(README LICENSE)
48
+ runs.with('-c', '-n', '--quiet', 'lib', '-', 'README', 'LICENSE')
49
+ install
50
+ end
51
+
52
+ it "should add --backtrace if Gem.configuration.backtrace" do
53
+ Gem.configuration.backtrace = true
54
+ runs.with('-c', '-n', '--quiet', '--backtrace', 'lib')
55
+ install
56
+ Gem.configuration.backtrace = false
57
+ end
58
+
59
+ it "should add require_paths if there is no .yardopts" do
60
+ File.should_receive(:file?).with(@yardopts).and_return(true)
61
+ runs.with('-c', '-n', '--quiet')
62
+ install
63
+ end
64
+
65
+ it "should add extra_rdoc_files if there is no .yardopts" do
66
+ @spec.extra_rdoc_files = %w(README LICENSE)
67
+ File.should_receive(:file?).with(@yardopts).and_return(true)
68
+ runs.with('-c', '-n', '--quiet')
69
+ install
70
+ end
71
+
72
+ it "should switch to directory before running command" do
73
+ old = Dir.pwd
74
+ Dir.should_receive(:chdir).with(@spec.full_gem_path)
75
+ Dir.should_receive(:chdir).with(old)
76
+ install
77
+ end
78
+
79
+ it "should ensure that directory is switched back at end of command in failure" do
80
+ old = Dir.pwd
81
+ Dir.should_receive(:chdir).with(@spec.full_gem_path)
82
+ Dir.should_receive(:chdir).with(old)
83
+ @doc.ui.errs.should_receive(:puts).with(/ERROR:\s*While generating documentation/)
84
+ @doc.ui.errs.should_receive(:puts).with(/MESSAGE:\s*foo/)
85
+ @doc.ui.errs.should_receive(:puts).with(/YARDOC args:\s*-c -n --quiet lib/)
86
+ @doc.ui.errs.should_receive(:puts).with("(continuing with the rest of the installation)")
87
+ YARD::CLI::Yardoc.should_receive(:run).and_raise(RuntimeError.new("foo"))
88
+ install
89
+ end
90
+
91
+ it "should handle permission errors" do
92
+ YARD::CLI::Yardoc.should_receive(:run).and_raise(Errno::EACCES.new("- dir"))
93
+ lambda { install }.should raise_error(Gem::FilePermissionError)
94
+ end
95
+ end
96
+
97
+ describe '#install_rdoc_yard' do
98
+ def install
99
+ msg = "Installing YARD documentation for #{@spec.full_name}..."
100
+ @doc.should_receive(:say).with(msg)
101
+ @doc.install_rdoc_yard
102
+ end
103
+
104
+ it "should add -o outdir when generating docs" do
105
+ File.should_receive(:file?).with(@yardopts).and_return(true)
106
+ @spec.has_yardoc = true
107
+ doc_dir = File.join(@doc.instance_variable_get("@doc_dir"), 'rdoc')
108
+ runs.with('-o', doc_dir, '--quiet')
109
+ install
110
+ end
111
+ end
112
+ end
@@ -26,8 +26,14 @@ describe YARD::Tags::DefaultFactory do
26
26
  parse_types('[#foo]').should == [nil, ['#foo'], '']
27
27
  end
28
28
 
29
- it "should handle ducktypes with special method names" do
30
- parse_types('[#foo=]').should == [nil, ['#foo='], '']
29
+ %w(#foo= #<< #<=> #>> #== #=== Array<#<=>> Array<#==>).each do |meth|
30
+ it "should handle ducktypes with special method name #{meth}" do
31
+ parse_types("[#{meth}]").should == [nil, [meth], '']
32
+ end
33
+ end
34
+
35
+ it "should only parse #ducktypes inside brackets" do
36
+ parse_types("#ducktype").should == [nil, nil, '#ducktype']
31
37
  end
32
38
 
33
39
  it "should return the text before and after the type list" do
@@ -239,6 +239,13 @@ describe YARD::Tags::MethodDirective do
239
239
  end
240
240
  end
241
241
 
242
+ it "should define parameters from signature" do
243
+ YARD.parse_string <<-eof
244
+ # @!method foo(a, b, c = nil)
245
+ eof
246
+ Registry.at('#foo').parameters.should == [[:a, nil], [:b, nil], [:c, 'nil']]
247
+ end
248
+
242
249
  it "should be able to define method with module scope (module function)" do
243
250
  YARD.parse_string <<-eof
244
251
  # @!method foo
@@ -355,7 +355,6 @@ and newlines.
355
355
 
356
356
 
357
357
  <span id="attr1=-instance_method"></span>
358
- <span id="attr1-instance_method"></span>
359
358
  <div class="method_details first">
360
359
  <h3 class="signature first" id="attr1-instance_method">
361
360
 
@@ -394,7 +393,6 @@ end</pre>
394
393
 
395
394
 
396
395
  <span id=""></span>
397
- <span id="attr2-instance_method"></span>
398
396
  <div class="method_details ">
399
397
  <h3 class="signature " id="attr2-instance_method">
400
398
 
@@ -433,7 +431,6 @@ end</pre>
433
431
 
434
432
 
435
433
  <span id="attr3=-instance_method"></span>
436
- <span id="attr3-instance_method"></span>
437
434
  <div class="method_details ">
438
435
  <h3 class="signature " id="attr3-instance_method">
439
436
 
@@ -542,7 +539,6 @@ end</pre>
542
539
  </div>
543
540
 
544
541
 
545
- <span id="attr4=-instance_method"></span>
546
542
  <span id=""></span>
547
543
  <div class="method_details ">
548
544
  <h3 class="signature " id="attr4=-instance_method">
@@ -170,7 +170,6 @@
170
170
 
171
171
 
172
172
  <span id="foo_attr=-instance_method"></span>
173
- <span id="foo_attr-instance_method"></span>
174
173
  <div class="method_details first">
175
174
  <h3 class="signature first" id="foo_attr-instance_method">
176
175
 
@@ -114,7 +114,6 @@
114
114
 
115
115
 
116
116
  <span id=""></span>
117
- <span id="bar-instance_method"></span>
118
117
  <div class="method_details first">
119
118
  <h3 class="signature first" id="bar-instance_method">
120
119
 
@@ -1,44 +1,44 @@
1
1
  <h1>Class: A
2
-
3
-
4
-
2
+
3
+
4
+
5
5
  </h1>
6
6
 
7
7
  <dl class="box">
8
-
8
+
9
9
  <dt class="r1">Inherits:</dt>
10
10
  <dd class="r1">
11
11
  <span class="inheritName">Object</span>
12
-
12
+
13
13
  <ul class="fullTree">
14
14
  <li>Object</li>
15
-
15
+
16
16
  <li class="next">A</li>
17
-
17
+
18
18
  </ul>
19
19
  <a href="#" class="inheritanceTree">show all</a>
20
-
20
+
21
21
  </dd>
22
-
23
-
24
-
25
-
22
+
23
+
24
+
25
+
26
26
  <dt class="r2">Extended by:</dt>
27
27
  <dd class="r2">Bar</dd>
28
-
29
-
30
-
31
-
28
+
29
+
30
+
31
+
32
32
  <dt class="r1">Includes:</dt>
33
33
  <dd class="r1">BarFooBar, Baz::ABC, Baz::XYZ, Foo</dd>
34
-
35
-
36
-
37
-
38
-
34
+
35
+
36
+
37
+
38
+
39
39
  <dt class="r2 last">Defined in:</dt>
40
40
  <dd class="r2 last">(stdin)</dd>
41
-
41
+
42
42
  </dl>
43
43
  <div class="clear"></div>
44
44
 
@@ -48,214 +48,213 @@
48
48
 
49
49
  <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
50
50
  <ul class="summary">
51
-
51
+
52
52
  <li class="public ">
53
53
  <span class="summary_signature">
54
-
54
+
55
55
  <a title="#bar_attr (instance method)">- <strong>bar_attr</strong> </a>
56
+
56
57
 
57
-
58
-
58
+
59
59
  </span>
60
-
60
+
61
61
  <span class="note title not_defined_here">
62
62
  included
63
63
  from Foo
64
64
  </span>
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
77
  <span class="summary_desc"><div class='inline'>Docs for bar_attr.</div></span>
78
-
78
+
79
79
  </li>
80
80
 
81
-
81
+
82
82
  </ul>
83
83
 
84
84
 
85
85
 
86
86
 
87
-
87
+
88
88
  <h2>
89
89
  Booya
90
90
  <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
91
91
  </h2>
92
92
 
93
93
  <ul class="summary">
94
-
94
+
95
95
  <li class="public ">
96
96
  <span class="summary_signature">
97
-
97
+
98
98
  <a title="#baz (class method)">+ <strong>baz</strong> </a>
99
+
99
100
 
100
-
101
-
101
+
102
102
  </span>
103
-
103
+
104
104
  <span class="note title not_defined_here">
105
105
  extended
106
106
  from Bar
107
107
  </span>
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
117
  <span class="summary_desc"><div class='inline'>Docs for baz in Booya group.</div></span>
118
-
118
+
119
119
  </li>
120
120
 
121
-
121
+
122
122
  <li class="public ">
123
123
  <span class="summary_signature">
124
-
124
+
125
125
  <a title="#baz_abc (instance method)">- <strong>baz_abc</strong> </a>
126
+
126
127
 
127
-
128
-
128
+
129
129
  </span>
130
-
130
+
131
131
  <span class="note title not_defined_here">
132
132
  included
133
133
  from Baz::ABC
134
134
  </span>
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
144
  <span class="summary_desc"><div class='inline'></div></span>
145
-
145
+
146
146
  </li>
147
147
 
148
-
148
+
149
149
  </ul>
150
-
150
+
151
151
  <h2>
152
152
  Instance Method Summary
153
153
  <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
154
154
  </h2>
155
155
 
156
156
  <ul class="summary">
157
-
157
+
158
158
  <li class="public ">
159
159
  <span class="summary_signature">
160
-
160
+
161
161
  <a title="#foo (instance method)">- <strong>foo</strong> </a>
162
+
162
163
 
163
-
164
-
164
+
165
165
  </span>
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
175
  <span class="summary_desc"><div class='inline'>This method is in A.</div></span>
176
-
176
+
177
177
  </li>
178
178
 
179
-
179
+
180
180
  <li class="public ">
181
181
  <span class="summary_signature">
182
-
182
+
183
183
  <a title="#xyz (instance method)">- <strong>xyz</strong> </a>
184
+
184
185
 
185
-
186
-
186
+
187
187
  </span>
188
-
188
+
189
189
  <span class="note title not_defined_here">
190
190
  included
191
191
  from Foo
192
192
  </span>
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
202
  <span class="summary_desc"><div class='inline'>Docs for xyz.</div></span>
203
-
203
+
204
204
  </li>
205
205
 
206
-
206
+
207
207
  </ul>
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
223
  <h3 class="inherited">Methods included from Baz::XYZ</h3>
224
224
  <p class="inherited">#baz_xyz</p>
225
225
 
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
234
  <h3 class="inherited">Methods included from BarFooBar</h3>
235
235
  <p class="inherited">#bar_foo_bar</p>
236
236
 
237
-
238
-
237
+
238
+
239
239
  <div id="instance_attr_details" class="attr_details">
240
240
  <h2>Instance Attribute Details</h2>
241
-
242
-
241
+
242
+
243
243
  <span id="bar_attr=-instance_method"></span>
244
- <span id="bar_attr-instance_method"></span>
245
244
  <div class="method_details first">
246
245
  <h3 class="signature first" id="bar_attr-instance_method">
246
+
247
+ - <strong>bar_attr</strong>
248
+
247
249
 
248
- - <strong>bar_attr</strong>
249
-
250
-
251
-
252
-
250
+
253
251
 
252
+
254
253
  <span class="not_defined_here">
255
254
  Originally defined in module
256
255
  Foo
257
256
  </span>
258
-
257
+
259
258
  </h3><div class="docstring">
260
259
  <div class="discussion">
261
260
  Docs for bar_attr
@@ -263,32 +262,32 @@
263
262
  </div>
264
263
  </div>
265
264
  <div class="tags">
266
-
265
+
267
266
 
268
267
  </div>
269
268
  </div>
270
-
269
+
271
270
  </div>
272
271
 
273
272
 
274
273
  <div id="class_method_details" class="method_details_list">
275
274
  <h2>Class Method Details</h2>
276
275
 
277
-
276
+
278
277
  <div class="method_details first">
279
278
  <h3 class="signature first" id="baz-class_method">
279
+
280
+ + <strong>baz</strong>
281
+
280
282
 
281
- + <strong>baz</strong>
282
-
283
-
284
-
285
-
283
+
286
284
 
285
+
287
286
  <span class="not_defined_here">
288
287
  Originally defined in module
289
288
  Bar
290
289
  </span>
291
-
290
+
292
291
  </h3><div class="docstring">
293
292
  <div class="discussion">
294
293
  Docs for baz in Booya group
@@ -296,43 +295,43 @@
296
295
  </div>
297
296
  </div>
298
297
  <div class="tags">
299
-
298
+
300
299
 
301
300
  </div>
302
301
  </div>
303
-
302
+
304
303
  </div>
305
304
 
306
305
  <div id="instance_method_details" class="method_details_list">
307
306
  <h2>Instance Method Details</h2>
308
307
 
309
-
308
+
310
309
  <div class="method_details first">
311
310
  <h3 class="signature first" id="baz_abc-instance_method">
311
+
312
+ - <strong>baz_abc</strong>
313
+
312
314
 
313
- - <strong>baz_abc</strong>
314
-
315
-
316
-
317
-
315
+
318
316
 
317
+
319
318
  <span class="not_defined_here">
320
319
  Originally defined in module
321
320
  Baz::ABC
322
321
  </span>
323
-
322
+
324
323
  </h3>
325
324
  </div>
326
-
325
+
327
326
  <div class="method_details ">
328
327
  <h3 class="signature " id="foo-instance_method">
328
+
329
+ - <strong>foo</strong>
330
+
329
331
 
330
- - <strong>foo</strong>
331
-
332
-
333
-
334
-
332
+
335
333
 
334
+
336
335
  </h3><div class="docstring">
337
336
  <div class="discussion">
338
337
  This method is in A
@@ -340,7 +339,7 @@
340
339
  </div>
341
340
  </div>
342
341
  <div class="tags">
343
-
342
+
344
343
 
345
344
  </div><table class="source_code">
346
345
  <tr>
@@ -358,21 +357,21 @@ def foo; end</pre>
358
357
  </tr>
359
358
  </table>
360
359
  </div>
361
-
360
+
362
361
  <div class="method_details ">
363
362
  <h3 class="signature " id="xyz-instance_method">
363
+
364
+ - <strong>xyz</strong>
365
+
364
366
 
365
- - <strong>xyz</strong>
366
-
367
-
368
-
369
-
367
+
370
368
 
369
+
371
370
  <span class="not_defined_here">
372
371
  Originally defined in module
373
372
  Foo
374
373
  </span>
375
-
374
+
376
375
  </h3><div class="docstring">
377
376
  <div class="discussion">
378
377
  Docs for xyz
@@ -380,9 +379,9 @@ def foo; end</pre>
380
379
  </div>
381
380
  </div>
382
381
  <div class="tags">
383
-
382
+
384
383
 
385
384
  </div>
386
385
  </div>
387
-
386
+
388
387
  </div>