yard 0.2.0

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.

data/lib/yard.rb ADDED
@@ -0,0 +1,3 @@
1
+ YARD_VERSION = "0.2.0"
2
+ require File.dirname(__FILE__) + '/namespace'
3
+ require File.dirname(__FILE__) + '/source_parser'
@@ -0,0 +1,455 @@
1
+ <% class_methods = @object.class_methods.select {|k,m| m.visibility == :public }.sort %>
2
+ <% instance_methods = @object.instance_methods.select {|k,m| m.visibility == :public && k != 'initialize' && k != 'method_missing' }.sort %>
3
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
9
+ <title>Ruby documentation: <%= @object.path %></title>
10
+ <style>
11
+ .topdoc * dt {
12
+ font-weight: bold;
13
+ }
14
+ .fulldoc {
15
+ margin-left: 37px;
16
+ }
17
+ .fulldoc * dt {
18
+ font-weight: bold;
19
+ }
20
+ h1 { color: #000; }
21
+ td { padding: 3px; }
22
+ </style>
23
+ <base target="_self" />
24
+ </head>
25
+ <body>
26
+ <h1>Class <%= @object.path %></h1>
27
+ <pre>
28
+ <% spaces = 0 %>
29
+ <% @object.superclasses.reverse.each do |superclass| %>
30
+ <%= (" " * spaces) + (spaces > 0 ? "+--" : "") + link_to_path(superclass) + "\n" %>
31
+ <% spaces += (spaces == 0 ? 2 : 4) %>
32
+ <%= (" " * spaces) + "|\n" %>
33
+ <% end %>
34
+ <%= (" " * spaces ) + "+--" + @object.path %>
35
+ </pre>
36
+
37
+ <% unless @object.mixins.empty? %>
38
+ <p>
39
+ <strong>All Included Modules:</strong><br />
40
+ <%= "&nbsp;" * 7 %><%= @object.mixins.collect {|m| link_to_path(m, @object) }.join(", ") %>
41
+ </p>
42
+ <% end %>
43
+
44
+ <hr />
45
+
46
+ <% if @object.docstring %>
47
+ <div class="topdoc">
48
+ <% if @object.tag("deprecated") %>
49
+ <p><strong>Deprecated.</strong> <em><%= @object.tag("deprecated").text %></em></p>
50
+ <% end %>
51
+ <p>
52
+ <%= to_html @object.docstring %>
53
+ </p>
54
+ <% unless @object.tags.empty? %>
55
+ <dl>
56
+ <% if @object.tag("author") %>
57
+ <dt>Author:</dt>
58
+ <dd><%= to_html @object.tag("author").text %></dd>
59
+ <% end %>
60
+ <% if @object.tag("since") %>
61
+ <dt>Since:</dt>
62
+ <dd><%= to_html @object.tag("since").text %></dd>
63
+ <% end %>
64
+ <% unless @object.tags("see").empty? %>
65
+ <dt>See Also:</dt>
66
+ <dd><%= @object.tags("see").collect {|t| "<tt>#{link_to_path(t.text, @object)}</tt>" }.join(", ") %></dd>
67
+ <% end %>
68
+ </dl>
69
+ <% end %>
70
+ </div>
71
+ <hr />
72
+ <% end %>
73
+
74
+ <% unless @object[:attributes].empty? %>
75
+ <h1>Attributes</h1>
76
+ <p style="line-height:20px">
77
+ <% @object[:attributes].sort.each do |name, rw| %>
78
+ <tt><%= name %> [<%= [(rw[:read] ? "R" : nil), (rw[:write] ? "W" : nil)].compact.join(", ") %>]</tt><br />
79
+ <% end %>
80
+ </p>
81
+ <% end %>
82
+
83
+ <% displayed_constants = false %>
84
+ <% unless @object.constants.empty? %>
85
+ <h1>Constants</h1><% displayed_constants = true %>
86
+ <dl>
87
+ <% @object.constants.each do |name, constant| %>
88
+ <dt id="const-<%= name %>"><pre><%= constant.full_source.gsub(/\s+/,' ') %></pre></dt>
89
+ <dd><%= to_html constant.docstring %></dd>
90
+ <% end %>
91
+ </dl>
92
+ <% end %>
93
+
94
+ <% @object.inheritance_tree.each do |name| %>
95
+ <% superclass = Namespace.at(name) or next %>
96
+ <% unless (consts = superclass.constants).empty? %>
97
+ <% unless displayed_constants %><h1>Constants</h1><% end %>
98
+ <p><table border="1" width="100%">
99
+ <tr background="#ddddff">
100
+ <th>Constants <%= superclass.type == :module ? "included" : "inherited" %> from <%= link_to_path(superclass.path) %></th>
101
+ </tr>
102
+ <tr>
103
+ <td><%= consts.collect {|m| "<tt>" + link_to_path(m.first, superclass.path) + "</tt>" }.join(", ") %></td>
104
+ </tr>
105
+ </table></p>
106
+ <% end %>
107
+ <% end %>
108
+
109
+ <% displayed_cvars = false %>
110
+ <% unless @object.class_variables.empty? %>
111
+ <h1>Class Variables</h1><% displayed_cvars = true %>
112
+ <dl>
113
+ <% @object.class_variables.each do |name, cvar| %>
114
+ <dt><pre><%= cvar.source.gsub(/\s+/,' ') %></pre></dt>
115
+ <dd><%= to_html cvar.docstring %></dd>
116
+ <% end %>
117
+ </dl>
118
+ <% end %>
119
+
120
+ <% @object.superclasses.each do |name| %>
121
+ <% superclass = Namespace.at(name) or next %>
122
+ <% unless (consts = superclass.class_variables.sort).empty? %>
123
+ <% unless displayed_cvars %><h1>Constants</h1><% end %>
124
+ <p><table border="1" width="100%">
125
+ <tr background="#ddddff">
126
+ <th>Class Variables inherited from <%= link_to_path(superclass.path) %></th>
127
+ </tr>
128
+ <tr>
129
+ <td><%= consts.reject {|name, cvar| @object.class_variables.has_key? name }.
130
+ collect {|name, cvar| "<tt>" + link_to_path(cvar, nil, name) + "</tt>" }.join(", ") %></td>
131
+ </tr>
132
+ </table></p>
133
+ <% end %>
134
+ <% end %>
135
+
136
+ <% if method = @object.instance_methods['initialize'] %>
137
+ <h1>Constructor Summary</h1>
138
+ <tt>
139
+ <%= method.source.gsub(/\Adef\s+/, '') %>
140
+ <% unless method.tags("yieldparam").empty? %>
141
+ {|<%= method.tags("yieldparam").collect {|t| t.name }.join(", ") %>| ... }
142
+ <% end %>
143
+ </tt>
144
+
145
+ <div id="instance_method-initialize" class="fulldoc">
146
+ <% if method.tag("deprecated") %>
147
+ <p><strong>Deprecated.</strong> <em><%= to_html method.tag("deprecated").text %></em></p>
148
+ <% end %>
149
+ <% if method.tag("yield") %>
150
+ <p><strong>Yields Block.</strong> <em><%= to_html method.tag("yield").text %></em></p>
151
+ <% end %>
152
+ <p>
153
+ <%= to_html method.docstring %>
154
+ </p>
155
+ <% unless method.tags.empty? %>
156
+ <dl>
157
+ <% unless method.tags("param").empty? %>
158
+ <dt>Parameters:</dt>
159
+ <dd>
160
+ <% method.tags("param").each do |tag| %>
161
+ <% unless tag.types.empty? %>
162
+ [<%= tag.types.collect {|t| "<tt>" + link_to_path(t,@object) + "</tt>" }.join(", ") %>]
163
+ <% end %>
164
+ <tt><%= tag.name %></tt> <%= "- " + to_html(tag.text) if tag.text %><br />
165
+ <% end %>
166
+ </dd>
167
+ <% end %>
168
+ <% unless method.tags("yieldparam").empty? %>
169
+ <dt>Yield Parameters:</dt>
170
+ <dd>
171
+ <% method.tags("yieldparam").each do |tag| %>
172
+ <% unless tag.types.empty? %>
173
+ [<%= tag.types.collect {|t| "<tt>#{link_to_path(t,@object)}</tt>" }.join(", ") %>]
174
+ <% end %>
175
+ <tt><%= tag.name %></tt> <%= "- " + to_html(tag.text) if tag.text %><br />
176
+ <% end %>
177
+ </dd>
178
+ <% end %>
179
+ <% if method.has_tag?("return") %>
180
+ <dt>Returns:</dt>
181
+ <dd><%= to_html method.tag("return").text %></dd>
182
+ <% end %>
183
+ <% unless method.tags("raise").empty? %>
184
+ <dt>Raises:</dt>
185
+ <dd>
186
+ <% method.tags("raise").each do |tag| %>
187
+ <tt><%= link_to_path(tag.name, @object) %></tt> <%= "- " + to_html(tag.text) if tag.text %><br />
188
+ <% end %>
189
+ </dd>
190
+ <% end %>
191
+
192
+ <% if method.tag("since") %>
193
+ <dt>Since:</dt>
194
+ <dd><%= to_html method.tag("since").text %></dd>
195
+ <% end %>
196
+ <% unless method.tags("see").empty? %>
197
+ <dt>See Also:</dt>
198
+ <dd><%= method.tags("see").collect {|t| "<tt>#{link_to_path(t.text, @object)}</tt>" }.join(", ") %></dd>
199
+ <% end %>
200
+ </dl>
201
+ <% end %>
202
+ </div>
203
+ </div>
204
+ <% else %>
205
+ <% @object.inheritance_tree.each do |name| %>
206
+ <% superclass = Namespace.at(name) or next %>
207
+ <% if method = superclass.instance_methods['initialize'] %>
208
+ <h1>Constructor Summary</h1>
209
+ <p>
210
+ <em>This class inherits a constructor from <tt><%= link_to_path(method.path, nil, method.parent.path) %></tt></em>
211
+ </p>
212
+ <% break %>
213
+ <% end %>
214
+ <% end %>
215
+ <% end %>
216
+
217
+ <% if method = @object.instance_methods['method_missing'] %>
218
+ <h1>Dynamic Method Handling</h1>
219
+ <p><em>This class handles dynamic methods through the <tt>method_missing</tt> method</em></p>
220
+ <tt>
221
+ <%= method.source.gsub(/\Adef\s+/, '') %>
222
+ <% unless method.tags("yieldparam").empty? %>
223
+ {|<%= method.tags("yieldparam").collect {|t| t.name }.join(", ") %>| ... }
224
+ <% end %>
225
+ </tt>
226
+
227
+ <div id="instance_method-method_missing" class="fulldoc">
228
+ <% if method.tag("deprecated") %>
229
+ <p><strong>Deprecated.</strong> <em><%= to_html method.tag("deprecated").text %></em></p>
230
+ <% end %>
231
+ <% if method.tag("yield") %>
232
+ <p><strong>Yields Block.</strong> <em><%= to_html method.tag("yield").text %></em></p>
233
+ <% end %>
234
+ <p>
235
+ <%= to_html method.docstring %>
236
+ </p>
237
+ <% unless method.tags.empty? %>
238
+ <dl>
239
+ <% unless method.tags("param").empty? %>
240
+ <dt>Parameters:</dt>
241
+ <dd>
242
+ <% method.tags("param").each do |tag| %>
243
+ <% unless tag.types.empty? %>
244
+ [<%= tag.types.collect {|t| "<tt>#{link_to_path(t,@object)}</tt>" }.join(", ") %>]
245
+ <% end %>
246
+ <tt><%= tag.name %></tt> <%= "- " + to_html(tag.text) if tag.text %><br />
247
+ <% end %>
248
+ </dd>
249
+ <% end %>
250
+ <% unless method.tags("yieldparam").empty? %>
251
+ <dt>Yield Parameters:</dt>
252
+ <dd>
253
+ <% method.tags("yieldparam").each do |tag| %>
254
+ <% unless tag.types.empty? %>
255
+ [<%= tag.types.collect {|t| "<tt>#{link_to_path(t,@object)}</tt>" }.join(", ") %>]
256
+ <% end %>
257
+ <tt><%= tag.name %></tt> <%= "- " + to_html(tag.text) if tag.text %><br />
258
+ <% end %>
259
+ </dd>
260
+ <% end %>
261
+ <% if method.has_tag?("return") %>
262
+ <dt>Returns:</dt>
263
+ <dd><%= to_html method.tag("return").text %></dd>
264
+ <% end %>
265
+ <% unless method.tags("raise").empty? %>
266
+ <dt>Raises:</dt>
267
+ <dd>
268
+ <% method.tags("raise").each do |tag| %>
269
+ <tt><%= link_to_path(tag.name, @object) %></tt> <%= "- " + to_html(tag.text) if tag.text %><br />
270
+ <% end %>
271
+ </dd>
272
+ <% end %>
273
+
274
+ <% if method.tag("since") %>
275
+ <dt>Since:</dt>
276
+ <dd><%= to_html method.tag("since").text %></dd>
277
+ <% end %>
278
+ <% unless method.tags("see").empty? %>
279
+ <dt>See Also:</dt>
280
+ <dd><%= method.tags("see").collect {|t| "<tt>#{link_to_path(t.text, @object)}</tt>" }.join(", ") %></dd>
281
+ <% end %>
282
+ </dl>
283
+ <% end %>
284
+ </div>
285
+
286
+ <% else %>
287
+ <% @object.inheritance_tree.each do |name| %>
288
+ <% superclass = Namespace.at(name) or next %>
289
+ <% if method = superclass.instance_methods['method_missing'] %>
290
+ <h1>Dynamic Method Handling</h1>
291
+ <p>
292
+ <em>
293
+ This class handles dynamic methods through the
294
+ <tt>
295
+ <%= link_to_path(method.path, nil, 'method_missing') %></tt> method in
296
+ the <%= superclass.type %> <tt><%= link_to_path(superclass.path) %></tt>
297
+ </tt>
298
+ </em>
299
+ </p>
300
+ <% break %>
301
+ <% end %>
302
+ <% end %>
303
+ <% end %>
304
+
305
+ <% displayed_public_meth_summary = false %>
306
+ <% [:class, :instance].each do |scope| %>
307
+ <% unless eval("#{scope}_methods").empty? %>
308
+ <% displayed_public_meth_summary = true %>
309
+ <h1>Public <%= scope.to_s.capitalize %> Method Summary</h1>
310
+ <table border="1" width="100%">
311
+ <% eval("#{scope}_methods").each do |name, method| %>
312
+ <tr>
313
+ <td width="70" align="right" valign="top">
314
+ <small>
315
+ <% if method.tag("return") && method.tag("return").types %>
316
+ <%= method.tag("return").types.collect {|t| link_to_path(t, @object) }.join(", ") %>
317
+ <% else %>
318
+ <%= YARD::ClassObject::BASE_OBJECT %>
319
+ <% end %>
320
+ </small>
321
+ </td>
322
+ <td>
323
+ <tt>
324
+ <%= method.source.sub(/\Adef\s+\S+?(\(|\s|;|$)/, link_to_path(method.path, nil, method.name) + '\1') if method.source %>
325
+ <% unless method.tags("yieldparam").empty? %>
326
+ {|<%= method.tags("yieldparam").collect {|t| t.name }.join(", ") %>| ... }
327
+ <% end %>
328
+ </tt><br />
329
+ <%= ("&nbsp;" * 5) + to_html(method.docstring.sub(/(\.|\n).+/m,'')) + "." if method.docstring && !method.docstring.empty? %>
330
+ <% if method.tag("deprecated") %>
331
+ <br /><strong>Deprecated.</strong> <em><%= method.tag("deprecated").text %></em>
332
+ <% end %>
333
+ </td>
334
+ </tr>
335
+ <% end %>
336
+ </table>
337
+ <% end %>
338
+
339
+ <% @object.inheritance_tree.each do |name| %>
340
+ <% superclass = Namespace.at(name) or next %>
341
+ <% unless (meths = superclass.send("#{scope}_methods").select {|k,m| m.visibility == :public }).empty? %>
342
+ <% unless displayed_public_meth_summary %>
343
+ <h1>Public <%= scope.to_s.capitalize %> Method Summary</h1>
344
+ <% end %>
345
+ <p><table border="1" width="100%">
346
+ <tr background="#ddddff">
347
+ <th>
348
+ Public <%= scope %> methods <%= superclass.type == :module ? "included" : "inherited" %>
349
+ from <%= link_to_path(superclass.path) %>
350
+ </th>
351
+ </tr>
352
+ <tr>
353
+ <td><%= meths.reject {|name, m| @object.send("#{scope}_methods").has_key? name }.
354
+ collect {|name, m| "<tt>" + link_to_path(superclass.path + (scope == :instance ? "#" : "::") +
355
+ name, nil, name) + "</tt>" }.join(", ") %></td>
356
+ </tr>
357
+ </table></p>
358
+ <% end %>
359
+ <% end %>
360
+ <% end %>
361
+
362
+ <% [:class, :instance].each do |scope| %>
363
+ <% unless eval("#{scope}_methods").empty? %>
364
+ <h1>Public <%= scope.to_s.capitalize %> Method Details</h1>
365
+ <% eval("#{scope}_methods").each do |name, method| %>
366
+ <div id="<%= scope %>_method-<%= name %>">
367
+ <h3><%= name %></h3>
368
+ <%
369
+ if method.tag("return") && !method.tag("return").types.empty?
370
+ type = method.tag("return").types.collect {|t| link_to_path(t, @object) }.join(", ")
371
+ type = "[#{type}]" if method.tag("return").types.size > 1
372
+ else
373
+ type = YARD::ClassObject::BASE_OBJECT
374
+ end
375
+ %>
376
+ <tt>
377
+ <%= method.source.gsub(/\Adef/, "#{method.visibility} " + type) if method.source %>
378
+ <% unless method.tags("yieldparam").empty? %>
379
+ {|<%= method.tags("yieldparam").collect {|t| t.name }.join(", ") %>| ... }
380
+ <% end %>
381
+ </tt>
382
+ <div class="fulldoc">
383
+ <% if method.tag("deprecated") %>
384
+ <p><strong>Deprecated.</strong> <em><%= to_html method.tag("deprecated").text %></em></p>
385
+ <% end %>
386
+ <% if method.tag("yield") %>
387
+ <p><strong>Yields Block.</strong> <em><%= to_html method.tag("yield").text %></em></p>
388
+ <% end %>
389
+ <p>
390
+ <%= to_html method.docstring %>
391
+ </p>
392
+ <dl>
393
+ <% @object.inheritance_tree.each do |name| %>
394
+ <% superclass = Namespace.at(name) or next %>
395
+ <% if (override = superclass.send("#{scope}_methods")[method.name]) %>
396
+ <dt>Overrides:
397
+ <dd>
398
+ <tt><%= link_to_path(override.path, nil, override.name) %></tt>
399
+ in <%= superclass.type %> <tt><%= link_to_path(superclass.path) %></tt>
400
+ </dd>
401
+ <% break %>
402
+ <% end %>
403
+ <% end %>
404
+ <% unless method.tags("param").empty? %>
405
+ <dt>Parameters:</dt>
406
+ <dd>
407
+ <% method.tags("param").each do |tag| %>
408
+ <% unless tag.types.empty? %>
409
+ [<%= tag.types.collect {|t| "<tt>#{link_to_path(t,@object)}</tt>" }.join(", ") %>]
410
+ <% end %>
411
+ <tt><%= tag.name %></tt> <%= "- " + to_html(tag.text) if tag.text %><br />
412
+ <% end %>
413
+ </dd>
414
+ <% end %>
415
+ <% unless method.tags("yieldparam").empty? %>
416
+ <dt>Yield Parameters:</dt>
417
+ <dd>
418
+ <% method.tags("yieldparam").each do |tag| %>
419
+ <% unless tag.types.empty? %>
420
+ [<%= tag.types.collect {|t| "<tt>#{link_to_path(t,@object)}</tt>" }.join(", ") %>]
421
+ <% end %>
422
+ <tt><%= tag.name %></tt> <%= "- " + to_html(tag.text) if tag.text %><br />
423
+ <% end %>
424
+ </dd>
425
+ <% end %>
426
+ <% if method.has_tag?("return") %>
427
+ <dt>Returns:</dt>
428
+ <dd><%= to_html method.tag("return").text %></dd>
429
+ <% end %>
430
+ <% unless method.tags("raise").empty? %>
431
+ <dt>Raises:</dt>
432
+ <dd>
433
+ <% method.tags("raise").each do |tag| %>
434
+ <tt><%= link_to_path(tag.name, @object) %></tt> <%= "- " + to_html(tag.text) if tag.text %><br />
435
+ <% end %>
436
+ </dd>
437
+ <% end %>
438
+
439
+ <% if method.tag("since") %>
440
+ <dt>Since:</dt>
441
+ <dd><%= to_html method.tag("since").text %></dd>
442
+ <% end %>
443
+ <% unless method.tags("see").empty? %>
444
+ <dt>See Also:</dt>
445
+ <dd><%= method.tags("see").collect {|t| "<tt>#{link_to_path(t.text, @object)}</tt>" }.join(", ") %></dd>
446
+ <% end %>
447
+ </dl>
448
+ </div>
449
+ </div>
450
+ <hr />
451
+ <% end %>
452
+ <% end %>
453
+ <% end %>
454
+ </body>
455
+ </html>