voloko-sdoc 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/rdoc/History.txt +254 -0
  2. data/rdoc/Manifest.txt +126 -0
  3. data/rdoc/README.txt +47 -0
  4. data/rdoc/RI.txt +58 -0
  5. data/rdoc/Rakefile +70 -0
  6. data/rdoc/bin/rdoc +35 -0
  7. data/rdoc/bin/ri +5 -0
  8. data/rdoc/lib/rdoc/alias.rb +54 -0
  9. data/rdoc/lib/rdoc/anon_class.rb +10 -0
  10. data/rdoc/lib/rdoc/any_method.rb +190 -0
  11. data/rdoc/lib/rdoc/attr.rb +79 -0
  12. data/rdoc/lib/rdoc/cache.rb +41 -0
  13. data/rdoc/lib/rdoc/class_module.rb +87 -0
  14. data/rdoc/lib/rdoc/code_object.rb +152 -0
  15. data/rdoc/lib/rdoc/code_objects.rb +23 -0
  16. data/rdoc/lib/rdoc/constant.rb +36 -0
  17. data/rdoc/lib/rdoc/context.rb +712 -0
  18. data/rdoc/lib/rdoc/diagram.rb +340 -0
  19. data/rdoc/lib/rdoc/dot.rb +249 -0
  20. data/rdoc/lib/rdoc/generator/darkfish.rb +455 -0
  21. data/rdoc/lib/rdoc/generator/markup.rb +194 -0
  22. data/rdoc/lib/rdoc/generator/ri.rb +230 -0
  23. data/rdoc/lib/rdoc/generator/template/darkfish/classpage.rhtml +281 -0
  24. data/rdoc/lib/rdoc/generator/template/darkfish/filepage.rhtml +112 -0
  25. data/rdoc/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  26. data/rdoc/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  27. data/rdoc/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  28. data/rdoc/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  29. data/rdoc/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  30. data/rdoc/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  31. data/rdoc/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  32. data/rdoc/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  33. data/rdoc/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  34. data/rdoc/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  35. data/rdoc/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  36. data/rdoc/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  37. data/rdoc/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  38. data/rdoc/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  39. data/rdoc/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  40. data/rdoc/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  41. data/rdoc/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  42. data/rdoc/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  43. data/rdoc/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  44. data/rdoc/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  45. data/rdoc/lib/rdoc/generator/template/darkfish/index.rhtml +64 -0
  46. data/rdoc/lib/rdoc/generator/template/darkfish/js/darkfish.js +116 -0
  47. data/rdoc/lib/rdoc/generator/template/darkfish/js/jquery.js +32 -0
  48. data/rdoc/lib/rdoc/generator/template/darkfish/js/quicksearch.js +114 -0
  49. data/rdoc/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +10 -0
  50. data/rdoc/lib/rdoc/generator/template/darkfish/rdoc.css +696 -0
  51. data/rdoc/lib/rdoc/generator.rb +8 -0
  52. data/rdoc/lib/rdoc/ghost_method.rb +8 -0
  53. data/rdoc/lib/rdoc/include.rb +39 -0
  54. data/rdoc/lib/rdoc/known_classes.rb +68 -0
  55. data/rdoc/lib/rdoc/markup/attribute_manager.rb +311 -0
  56. data/rdoc/lib/rdoc/markup/formatter.rb +25 -0
  57. data/rdoc/lib/rdoc/markup/fragments.rb +377 -0
  58. data/rdoc/lib/rdoc/markup/inline.rb +126 -0
  59. data/rdoc/lib/rdoc/markup/lines.rb +156 -0
  60. data/rdoc/lib/rdoc/markup/preprocess.rb +80 -0
  61. data/rdoc/lib/rdoc/markup/to_flow.rb +211 -0
  62. data/rdoc/lib/rdoc/markup/to_html.rb +406 -0
  63. data/rdoc/lib/rdoc/markup/to_html_crossref.rb +140 -0
  64. data/rdoc/lib/rdoc/markup/to_latex.rb +328 -0
  65. data/rdoc/lib/rdoc/markup/to_test.rb +53 -0
  66. data/rdoc/lib/rdoc/markup/to_texinfo.rb +73 -0
  67. data/rdoc/lib/rdoc/markup.rb +378 -0
  68. data/rdoc/lib/rdoc/meta_method.rb +8 -0
  69. data/rdoc/lib/rdoc/normal_class.rb +18 -0
  70. data/rdoc/lib/rdoc/normal_module.rb +34 -0
  71. data/rdoc/lib/rdoc/options.rb +542 -0
  72. data/rdoc/lib/rdoc/parser/c.rb +678 -0
  73. data/rdoc/lib/rdoc/parser/perl.rb +165 -0
  74. data/rdoc/lib/rdoc/parser/ruby.rb +2904 -0
  75. data/rdoc/lib/rdoc/parser/simple.rb +39 -0
  76. data/rdoc/lib/rdoc/parser.rb +138 -0
  77. data/rdoc/lib/rdoc/rdoc.rb +375 -0
  78. data/rdoc/lib/rdoc/require.rb +32 -0
  79. data/rdoc/lib/rdoc/ri/cache.rb +187 -0
  80. data/rdoc/lib/rdoc/ri/descriptions.rb +156 -0
  81. data/rdoc/lib/rdoc/ri/display.rb +340 -0
  82. data/rdoc/lib/rdoc/ri/driver.rb +828 -0
  83. data/rdoc/lib/rdoc/ri/formatter.rb +654 -0
  84. data/rdoc/lib/rdoc/ri/paths.rb +93 -0
  85. data/rdoc/lib/rdoc/ri/reader.rb +106 -0
  86. data/rdoc/lib/rdoc/ri/util.rb +79 -0
  87. data/rdoc/lib/rdoc/ri/writer.rb +68 -0
  88. data/rdoc/lib/rdoc/ri.rb +8 -0
  89. data/rdoc/lib/rdoc/single_class.rb +8 -0
  90. data/rdoc/lib/rdoc/stats.rb +178 -0
  91. data/rdoc/lib/rdoc/task.rb +276 -0
  92. data/rdoc/lib/rdoc/tokenstream.rb +33 -0
  93. data/rdoc/lib/rdoc/top_level.rb +242 -0
  94. data/rdoc/lib/rdoc.rb +398 -0
  95. metadata +1 -1
@@ -0,0 +1,455 @@
1
+ #!ruby
2
+ # vim: noet ts=2 sts=8 sw=2
3
+
4
+ require 'rubygems'
5
+ gem 'rdoc', '>= 2.4' unless defined? $rdoc_rakefile
6
+
7
+ require 'pp'
8
+ require 'pathname'
9
+ require 'fileutils'
10
+ require 'erb'
11
+ require 'yaml'
12
+
13
+ require 'rdoc/rdoc'
14
+ require 'rdoc/generator'
15
+ require 'rdoc/generator/markup'
16
+
17
+ #
18
+ # Darkfish RDoc HTML Generator
19
+ #
20
+ # $Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
21
+ #
22
+ # == Author/s
23
+ # * Michael Granger (ged@FaerieMUD.org)
24
+ #
25
+ # == Contributors
26
+ # * Mahlon E. Smith (mahlon@martini.nu)
27
+ # * Eric Hodel (drbrain@segment7.net)
28
+ #
29
+ # == License
30
+ #
31
+ # Copyright (c) 2007, 2008, Michael Granger. All rights reserved.
32
+ #
33
+ # Redistribution and use in source and binary forms, with or without
34
+ # modification, are permitted provided that the following conditions are met:
35
+ #
36
+ # * Redistributions of source code must retain the above copyright notice,
37
+ # this list of conditions and the following disclaimer.
38
+ #
39
+ # * Redistributions in binary form must reproduce the above copyright notice,
40
+ # this list of conditions and the following disclaimer in the documentation
41
+ # and/or other materials provided with the distribution.
42
+ #
43
+ # * Neither the name of the author/s, nor the names of the project's
44
+ # contributors may be used to endorse or promote products derived from this
45
+ # software without specific prior written permission.
46
+ #
47
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
48
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
51
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
53
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
54
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
55
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57
+ #
58
+ class RDoc::Generator::Darkfish
59
+
60
+ RDoc::RDoc.add_generator( self )
61
+
62
+ include ERB::Util
63
+
64
+ # Subversion rev
65
+ SVNRev = %$Rev: 52 $
66
+
67
+ # Subversion ID
68
+ SVNId = %$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
69
+
70
+ # Path to this file's parent directory. Used to find templates and other
71
+ # resources.
72
+ GENERATOR_DIR = File.join 'rdoc', 'generator'
73
+
74
+ # Release Version
75
+ VERSION = '1.1.6'
76
+
77
+ # Directory where generated classes live relative to the root
78
+ CLASS_DIR = nil
79
+
80
+ # Directory where generated files live relative to the root
81
+ FILE_DIR = nil
82
+
83
+
84
+ #################################################################
85
+ ### C L A S S M E T H O D S
86
+ #################################################################
87
+
88
+ ### Standard generator factory method
89
+ def self::for( options )
90
+ new( options )
91
+ end
92
+
93
+
94
+ #################################################################
95
+ ### I N S T A N C E M E T H O D S
96
+ #################################################################
97
+
98
+ ### Initialize a few instance variables before we start
99
+ def initialize( options )
100
+ @options = options
101
+ @options.diagram = false
102
+
103
+ template = @options.template || 'darkfish'
104
+
105
+ template_dir = $LOAD_PATH.map do |path|
106
+ File.join path, GENERATOR_DIR, 'template', template
107
+ end.find do |dir|
108
+ File.directory? dir
109
+ end
110
+
111
+ raise RDoc::Error, "could not find template #{template.inspect}" unless
112
+ template_dir
113
+
114
+ @template_dir = Pathname.new File.expand_path(template_dir)
115
+
116
+ @files = nil
117
+ @classes = nil
118
+
119
+ @basedir = Pathname.pwd.expand_path
120
+ end
121
+
122
+ ######
123
+ public
124
+ ######
125
+
126
+ # The output directory
127
+ attr_reader :outputdir
128
+
129
+
130
+ ### Output progress information if debugging is enabled
131
+ def debug_msg( *msg )
132
+ return unless $DEBUG_RDOC
133
+ $stderr.puts( *msg )
134
+ end
135
+
136
+ def class_dir
137
+ CLASS_DIR
138
+ end
139
+
140
+ def file_dir
141
+ FILE_DIR
142
+ end
143
+
144
+ ### Create the directories the generated docs will live in if
145
+ ### they don't already exist.
146
+ def gen_sub_directories
147
+ @outputdir.mkpath
148
+ end
149
+
150
+ ### Copy over the stylesheet into the appropriate place in the output
151
+ ### directory.
152
+ def write_style_sheet
153
+ debug_msg "Copying static files"
154
+ options = { :verbose => $DEBUG_RDOC, :noop => $dryrun }
155
+
156
+ FileUtils.cp @template_dir + 'rdoc.css', '.', options
157
+
158
+ Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
159
+ next if File.directory? path
160
+ next if path =~ /#{File::SEPARATOR}\./
161
+
162
+ dst = Pathname.new(path).relative_path_from @template_dir
163
+
164
+ # I suck at glob
165
+ dst_dir = dst.dirname
166
+ FileUtils.mkdir_p dst_dir, options unless File.exist? dst_dir
167
+
168
+ FileUtils.cp @template_dir + path, dst, options
169
+ end
170
+ end
171
+
172
+ ### Build the initial indices and output objects
173
+ ### based on an array of TopLevel objects containing
174
+ ### the extracted information.
175
+ def generate( top_levels )
176
+ @outputdir = Pathname.new( @options.op_dir ).expand_path( @basedir )
177
+
178
+ @files = top_levels.sort
179
+ @classes = RDoc::TopLevel.all_classes_and_modules.sort
180
+ @methods = @classes.map { |m| m.method_list }.flatten.sort
181
+ @modsort = get_sorted_module_list( @classes )
182
+
183
+ # Now actually write the output
184
+ write_style_sheet
185
+ generate_index
186
+ generate_class_files
187
+ generate_file_files
188
+
189
+ rescue StandardError => err
190
+ debug_msg "%s: %s\n %s" % [ err.class.name, err.message, err.backtrace.join("\n ") ]
191
+ raise
192
+ end
193
+
194
+ #########
195
+ protected
196
+ #########
197
+
198
+ ### Return a list of the documented modules sorted by salience first, then
199
+ ### by name.
200
+ def get_sorted_module_list( classes )
201
+ nscounts = classes.inject({}) do |counthash, klass|
202
+ top_level = klass.full_name.gsub( /::.*/, '' )
203
+ counthash[top_level] ||= 0
204
+ counthash[top_level] += 1
205
+
206
+ counthash
207
+ end
208
+
209
+ # Sort based on how often the top level namespace occurs, and then on the
210
+ # name of the module -- this works for projects that put their stuff into
211
+ # a namespace, of course, but doesn't hurt if they don't.
212
+ classes.sort_by do |klass|
213
+ top_level = klass.full_name.gsub( /::.*/, '' )
214
+ [
215
+ nscounts[ top_level ] * -1,
216
+ klass.full_name
217
+ ]
218
+ end.select do |klass|
219
+ klass.document_self
220
+ end
221
+ end
222
+
223
+ ### Generate an index page which lists all the classes which
224
+ ### are documented.
225
+ def generate_index
226
+ debug_msg "Rendering the index page..."
227
+
228
+ templatefile = @template_dir + 'index.rhtml'
229
+ template_src = templatefile.read
230
+ template = ERB.new( template_src, nil, '<>' )
231
+ template.filename = templatefile.to_s
232
+ context = binding()
233
+
234
+ output = nil
235
+
236
+ begin
237
+ output = template.result( context )
238
+ rescue NoMethodError => err
239
+ raise RDoc::Error, "Error while evaluating %s: %s (at %p)" % [
240
+ templatefile,
241
+ err.message,
242
+ eval( "_erbout[-50,50]", context )
243
+ ], err.backtrace
244
+ end
245
+
246
+ outfile = @basedir + @options.op_dir + 'index.html'
247
+ unless $dryrun
248
+ debug_msg "Outputting to %s" % [outfile.expand_path]
249
+ outfile.open( 'w', 0644 ) do |fh|
250
+ fh.print( output )
251
+ end
252
+ else
253
+ debug_msg "Would have output to %s" % [outfile.expand_path]
254
+ end
255
+ end
256
+
257
+ ### Generate a documentation file for each class
258
+ def generate_class_files
259
+ debug_msg "Generating class documentation in #@outputdir"
260
+ templatefile = @template_dir + 'classpage.rhtml'
261
+
262
+ @classes.each do |klass|
263
+ debug_msg " working on %s (%s)" % [ klass.full_name, klass.path ]
264
+ outfile = @outputdir + klass.path
265
+ rel_prefix = @outputdir.relative_path_from( outfile.dirname )
266
+ svninfo = self.get_svninfo( klass )
267
+
268
+ debug_msg " rendering #{outfile}"
269
+ self.render_template( templatefile, binding(), outfile )
270
+ end
271
+ end
272
+
273
+ ### Generate a documentation file for each file
274
+ def generate_file_files
275
+ debug_msg "Generating file documentation in #@outputdir"
276
+ templatefile = @template_dir + 'filepage.rhtml'
277
+
278
+ @files.each do |file|
279
+ outfile = @outputdir + file.path
280
+ debug_msg " working on %s (%s)" % [ file.full_name, outfile ]
281
+ rel_prefix = @outputdir.relative_path_from( outfile.dirname )
282
+ context = binding()
283
+
284
+ debug_msg " rendering #{outfile}"
285
+ self.render_template( templatefile, binding(), outfile )
286
+ end
287
+ end
288
+
289
+
290
+ ### Return a string describing the amount of time in the given number of
291
+ ### seconds in terms a human can understand easily.
292
+ def time_delta_string( seconds )
293
+ return 'less than a minute' if seconds < 1.minute
294
+ return (seconds / 1.minute).to_s + ' minute' + (seconds/60 == 1 ? '' : 's') if seconds < 50.minutes
295
+ return 'about one hour' if seconds < 90.minutes
296
+ return (seconds / 1.hour).to_s + ' hours' if seconds < 18.hours
297
+ return 'one day' if seconds < 1.day
298
+ return 'about one day' if seconds < 2.days
299
+ return (seconds / 1.day).to_s + ' days' if seconds < 1.week
300
+ return 'about one week' if seconds < 2.week
301
+ return (seconds / 1.week).to_s + ' weeks' if seconds < 3.months
302
+ return (seconds / 1.month).to_s + ' months' if seconds < 1.year
303
+ return (seconds / 1.year).to_s + ' years'
304
+ end
305
+
306
+
307
+ # %q$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $"
308
+ SVNID_PATTERN = /
309
+ \$Id:\s
310
+ (\S+)\s # filename
311
+ (\d+)\s # rev
312
+ (\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD)
313
+ (\d{2}:\d{2}:\d{2}Z)\s # Time (HH:MM:SSZ)
314
+ (\w+)\s # committer
315
+ \$$
316
+ /x
317
+
318
+ ### Try to extract Subversion information out of the first constant whose value looks like
319
+ ### a subversion Id tag. If no matching constant is found, and empty hash is returned.
320
+ def get_svninfo( klass )
321
+ constants = klass.constants or return {}
322
+
323
+ constants.find {|c| c.value =~ SVNID_PATTERN } or return {}
324
+
325
+ filename, rev, date, time, committer = $~.captures
326
+ commitdate = Time.parse( date + ' ' + time )
327
+
328
+ return {
329
+ :filename => filename,
330
+ :rev => Integer( rev ),
331
+ :commitdate => commitdate,
332
+ :commitdelta => time_delta_string( Time.now.to_i - commitdate.to_i ),
333
+ :committer => committer,
334
+ }
335
+ end
336
+
337
+
338
+ ### Load and render the erb template in the given +templatefile+ within the
339
+ ### specified +context+ (a Binding object) and write it out to +outfile+.
340
+ ### Both +templatefile+ and +outfile+ should be Pathname-like objects.
341
+
342
+ def render_template( templatefile, context, outfile )
343
+ template_src = templatefile.read
344
+ template = ERB.new( template_src, nil, '<>' )
345
+ template.filename = templatefile.to_s
346
+
347
+ output = begin
348
+ template.result( context )
349
+ rescue NoMethodError => err
350
+ raise RDoc::Error, "Error while evaluating %s: %s (at %p)" % [
351
+ templatefile.to_s,
352
+ err.message,
353
+ eval( "_erbout[-50,50]", context )
354
+ ], err.backtrace
355
+ end
356
+
357
+ unless $dryrun
358
+ outfile.dirname.mkpath
359
+ outfile.open( 'w', 0644 ) do |ofh|
360
+ ofh.print( output )
361
+ end
362
+ else
363
+ debug_msg " would have written %d bytes to %s" %
364
+ [ output.length, outfile ]
365
+ end
366
+ end
367
+
368
+ end # Roc::Generator::Darkfish
369
+
370
+ # :stopdoc:
371
+
372
+ ### Time constants
373
+ module TimeConstantMethods # :nodoc:
374
+
375
+ ### Number of seconds (returns receiver unmodified)
376
+ def seconds
377
+ return self
378
+ end
379
+ alias_method :second, :seconds
380
+
381
+ ### Returns number of seconds in <receiver> minutes
382
+ def minutes
383
+ return self * 60
384
+ end
385
+ alias_method :minute, :minutes
386
+
387
+ ### Returns the number of seconds in <receiver> hours
388
+ def hours
389
+ return self * 60.minutes
390
+ end
391
+ alias_method :hour, :hours
392
+
393
+ ### Returns the number of seconds in <receiver> days
394
+ def days
395
+ return self * 24.hours
396
+ end
397
+ alias_method :day, :days
398
+
399
+ ### Return the number of seconds in <receiver> weeks
400
+ def weeks
401
+ return self * 7.days
402
+ end
403
+ alias_method :week, :weeks
404
+
405
+ ### Returns the number of seconds in <receiver> fortnights
406
+ def fortnights
407
+ return self * 2.weeks
408
+ end
409
+ alias_method :fortnight, :fortnights
410
+
411
+ ### Returns the number of seconds in <receiver> months (approximate)
412
+ def months
413
+ return self * 30.days
414
+ end
415
+ alias_method :month, :months
416
+
417
+ ### Returns the number of seconds in <receiver> years (approximate)
418
+ def years
419
+ return (self * 365.25.days).to_i
420
+ end
421
+ alias_method :year, :years
422
+
423
+
424
+ ### Returns the Time <receiver> number of seconds before the
425
+ ### specified +time+. E.g., 2.hours.before( header.expiration )
426
+ def before( time )
427
+ return time - self
428
+ end
429
+
430
+
431
+ ### Returns the Time <receiver> number of seconds ago. (e.g.,
432
+ ### expiration > 2.hours.ago )
433
+ def ago
434
+ return self.before( ::Time.now )
435
+ end
436
+
437
+
438
+ ### Returns the Time <receiver> number of seconds after the given +time+.
439
+ ### E.g., 10.minutes.after( header.expiration )
440
+ def after( time )
441
+ return time + self
442
+ end
443
+
444
+ # Reads best without arguments: 10.minutes.from_now
445
+ def from_now
446
+ return self.after( ::Time.now )
447
+ end
448
+ end # module TimeConstantMethods
449
+
450
+
451
+ # Extend Numeric with time constants
452
+ class Numeric # :nodoc:
453
+ include TimeConstantMethods
454
+ end
455
+
@@ -0,0 +1,194 @@
1
+ require 'rdoc/code_objects'
2
+ require 'rdoc/generator'
3
+ require 'rdoc/markup/to_html_crossref'
4
+
5
+ ##
6
+ # Handle common HTML markup tasks for various CodeObjects
7
+
8
+ module RDoc::Generator::Markup
9
+
10
+ ##
11
+ # Generates a relative URL from this object's path to +target_path+
12
+
13
+ def aref_to(target_path)
14
+ RDoc::Markup::ToHtml.gen_relative_url path, target_path
15
+ end
16
+
17
+ ##
18
+ # Generates a relative URL from +from_path+ to this object's path
19
+
20
+ def as_href(from_path)
21
+ RDoc::Markup::ToHtml.gen_relative_url from_path, path
22
+ end
23
+
24
+ ##
25
+ # Handy wrapper for marking up this object's comment
26
+
27
+ def description
28
+ markup @comment
29
+ end
30
+
31
+ ##
32
+ # RDoc::Markup formatter object
33
+
34
+ def formatter
35
+ return @formatter if defined? @formatter
36
+
37
+ show_hash = RDoc::RDoc.current.options.show_hash
38
+ this = RDoc::Context === self ? self : @parent
39
+ @formatter = RDoc::Markup::ToHtmlCrossref.new this.path, this, show_hash
40
+ end
41
+
42
+ ##
43
+ # Convert a string in markup format into HTML.
44
+
45
+ def markup(str, remove_para = false)
46
+ return '' unless str
47
+
48
+ # Convert leading comment markers to spaces, but only if all non-blank
49
+ # lines have them
50
+ if str =~ /^(?>\s*)[^\#]/ then
51
+ content = str
52
+ else
53
+ content = str.gsub(/^\s*(#+)/) { $1.tr '#', ' ' }
54
+ end
55
+
56
+ res = formatter.convert content
57
+
58
+ if remove_para then
59
+ res.sub!(/^<p>/, '')
60
+ res.sub!(/<\/p>$/, '')
61
+ end
62
+
63
+ res
64
+ end
65
+
66
+ ##
67
+ # Build a webcvs URL starting for the given +url+ with +full_path+ appended
68
+ # as the destination path. If +url+ contains '%s' +full_path+ will be
69
+ # sprintf'd into +url+ instead.
70
+
71
+ def cvs_url(url, full_path)
72
+ if /%s/ =~ url then
73
+ sprintf url, full_path
74
+ else
75
+ url + full_path
76
+ end
77
+ end
78
+
79
+ end
80
+
81
+ class RDoc::AnyMethod
82
+
83
+ include RDoc::Generator::Markup
84
+
85
+ ##
86
+ # Prepend +src+ with line numbers. Relies on the first line of a source
87
+ # code listing having:
88
+ #
89
+ # # File xxxxx, line dddd
90
+
91
+ def add_line_numbers(src)
92
+ if src =~ /\A.*, line (\d+)/ then
93
+ first = $1.to_i - 1
94
+ last = first + src.count("\n")
95
+ size = last.to_s.length
96
+
97
+ line = first
98
+ src.gsub!(/^/) do
99
+ res = if line == first then
100
+ " " * (size + 2)
101
+ else
102
+ "%#{size}d: " % line
103
+ end
104
+
105
+ line += 1
106
+ res
107
+ end
108
+ end
109
+ end
110
+
111
+ ##
112
+ # Turns the method's token stream into HTML
113
+
114
+ def markup_code
115
+ return '' unless @token_stream
116
+
117
+ src = ""
118
+
119
+ @token_stream.each do |t|
120
+ next unless t
121
+ # style = STYLE_MAP[t.class]
122
+ style = case t
123
+ when RDoc::RubyToken::TkCONSTANT then "ruby-constant"
124
+ when RDoc::RubyToken::TkKW then "ruby-keyword kw"
125
+ when RDoc::RubyToken::TkIVAR then "ruby-ivar"
126
+ when RDoc::RubyToken::TkOp then "ruby-operator"
127
+ when RDoc::RubyToken::TkId then "ruby-identifier"
128
+ when RDoc::RubyToken::TkNode then "ruby-node"
129
+ when RDoc::RubyToken::TkCOMMENT then "ruby-comment cmt"
130
+ when RDoc::RubyToken::TkREGEXP then "ruby-regexp re"
131
+ when RDoc::RubyToken::TkSTRING then "ruby-value str"
132
+ when RDoc::RubyToken::TkVal then "ruby-value"
133
+ else
134
+ nil
135
+ end
136
+
137
+ text = CGI.escapeHTML(t.text)
138
+
139
+ if style
140
+ src << "<span class=\"#{style}\">#{text}</span>"
141
+ else
142
+ src << text
143
+ end
144
+ end
145
+
146
+ add_line_numbers src if RDoc::RDoc.current.options.include_line_numbers
147
+
148
+ src
149
+ end
150
+
151
+ end
152
+
153
+ class RDoc::Attr
154
+
155
+ include RDoc::Generator::Markup
156
+
157
+ end
158
+
159
+ class RDoc::Constant
160
+
161
+ include RDoc::Generator::Markup
162
+
163
+ end
164
+
165
+ class RDoc::Context
166
+
167
+ include RDoc::Generator::Markup
168
+
169
+ end
170
+
171
+ class RDoc::Context::Section
172
+
173
+ include RDoc::Generator::Markup
174
+
175
+ end
176
+
177
+ class RDoc::TopLevel
178
+
179
+ ##
180
+ # Returns a URL for this source file on some web repository. Use the -W
181
+ # command line option to set.
182
+
183
+ def cvs_url
184
+ url = RDoc::RDoc.current.options.webcvs
185
+
186
+ if /%s/ =~ url then
187
+ url % @absolute_name
188
+ else
189
+ url + @absolute_name
190
+ end
191
+ end
192
+
193
+ end
194
+