rdoc 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rdoc might be problematic. Click here for more details.
- data.tar.gz.sig +0 -0
- data/.autotest +14 -0
- data/History.txt +27 -0
- data/Manifest.txt +29 -9
- data/Rakefile +2 -0
- data/bin/rdoc +13 -2
- data/lib/rdoc.rb +11 -3
- data/lib/rdoc/alias.rb +54 -0
- data/lib/rdoc/anon_class.rb +10 -0
- data/lib/rdoc/any_method.rb +190 -0
- data/lib/rdoc/attr.rb +79 -0
- data/lib/rdoc/cache.rb +11 -2
- data/lib/rdoc/class_module.rb +87 -0
- data/lib/rdoc/code_object.rb +152 -0
- data/lib/rdoc/code_objects.rb +18 -1118
- data/lib/rdoc/constant.rb +36 -0
- data/lib/rdoc/context.rb +712 -0
- data/lib/rdoc/diagram.rb +8 -8
- data/lib/rdoc/generator.rb +3 -1140
- data/lib/rdoc/generator/darkfish.rb +107 -133
- data/lib/rdoc/generator/markup.rb +194 -0
- data/lib/rdoc/generator/ri.rb +4 -2
- data/lib/rdoc/generator/template/darkfish/classpage.rhtml +92 -113
- data/lib/rdoc/generator/template/darkfish/filepage.rhtml +33 -35
- data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -15
- data/lib/rdoc/ghost_method.rb +8 -0
- data/lib/rdoc/include.rb +39 -0
- data/lib/rdoc/markup/attribute_manager.rb +46 -0
- data/lib/rdoc/markup/formatter.rb +11 -0
- data/lib/rdoc/markup/fragments.rb +42 -2
- data/lib/rdoc/markup/inline.rb +29 -4
- data/lib/rdoc/markup/lines.rb +4 -0
- data/lib/rdoc/markup/preprocess.rb +4 -0
- data/lib/rdoc/markup/to_flow.rb +27 -1
- data/lib/rdoc/markup/to_html.rb +33 -33
- data/lib/rdoc/markup/to_html_crossref.rb +4 -11
- data/lib/rdoc/markup/to_latex.rb +31 -31
- data/lib/rdoc/markup/to_test.rb +3 -0
- data/lib/rdoc/markup/to_texinfo.rb +18 -14
- data/lib/rdoc/meta_method.rb +8 -0
- data/lib/rdoc/normal_class.rb +18 -0
- data/lib/rdoc/normal_module.rb +34 -0
- data/lib/rdoc/options.rb +26 -159
- data/lib/rdoc/parser/c.rb +16 -8
- data/lib/rdoc/parser/ruby.rb +16 -10
- data/lib/rdoc/parser/simple.rb +1 -1
- data/lib/rdoc/rdoc.rb +50 -34
- data/lib/rdoc/require.rb +32 -0
- data/lib/rdoc/ri/descriptions.rb +1 -1
- data/lib/rdoc/ri/driver.rb +4 -4
- data/lib/rdoc/ri/formatter.rb +70 -32
- data/lib/rdoc/single_class.rb +8 -0
- data/lib/rdoc/top_level.rb +232 -0
- data/test/test_rdoc_any_method.rb +10 -0
- data/test/test_rdoc_code_object.rb +80 -0
- data/test/test_rdoc_constant.rb +15 -0
- data/test/test_rdoc_context.rb +250 -0
- data/test/test_rdoc_include.rb +17 -0
- data/test/test_rdoc_markup.rb +13 -2
- data/test/test_rdoc_markup_to_html.rb +22 -0
- data/test/test_rdoc_markup_to_html_crossref.rb +50 -115
- data/test/test_rdoc_normal_module.rb +26 -0
- data/test/test_rdoc_parser_c.rb +33 -0
- data/test/test_rdoc_parser_ruby.rb +54 -36
- data/test/test_rdoc_require.rb +25 -0
- data/test/test_rdoc_ri_default_display.rb +2 -1
- data/test/test_rdoc_ri_html_formatter.rb +141 -0
- data/test/test_rdoc_top_level.rb +85 -0
- data/test/xref_data.rb +46 -0
- data/test/xref_test_case.rb +48 -0
- metadata +42 -13
- metadata.gz.sig +0 -0
- data/lib/rdoc/generator/html.rb +0 -456
- data/lib/rdoc/generator/html/common.rb +0 -24
- data/lib/rdoc/generator/html/html.rb +0 -769
- data/lib/rdoc/generator/html/one_page_html.rb +0 -122
- data/lib/rdoc/generator/xml.rb +0 -124
- data/lib/rdoc/generator/xml/rdf.rb +0 -113
- data/lib/rdoc/generator/xml/xml.rb +0 -123
- data/lib/rdoc/parser/f95.rb +0 -1835
- data/lib/rdoc/template.rb +0 -68
@@ -1,7 +1,8 @@
|
|
1
1
|
#!ruby
|
2
|
+
# vim: noet ts=2 sts=8 sw=2
|
2
3
|
|
3
4
|
require 'rubygems'
|
4
|
-
gem 'rdoc', '>= 2.
|
5
|
+
gem 'rdoc', '>= 2.4' unless defined? $rdoc_rakefile
|
5
6
|
|
6
7
|
require 'pp'
|
7
8
|
require 'pathname'
|
@@ -10,8 +11,8 @@ require 'erb'
|
|
10
11
|
require 'yaml'
|
11
12
|
|
12
13
|
require 'rdoc/rdoc'
|
13
|
-
require 'rdoc/generator
|
14
|
-
require 'rdoc/generator/
|
14
|
+
require 'rdoc/generator'
|
15
|
+
require 'rdoc/generator/markup'
|
15
16
|
|
16
17
|
#
|
17
18
|
# Darkfish RDoc HTML Generator
|
@@ -54,7 +55,7 @@ require 'rdoc/generator/html'
|
|
54
55
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
55
56
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
56
57
|
#
|
57
|
-
class RDoc::Generator::Darkfish
|
58
|
+
class RDoc::Generator::Darkfish
|
58
59
|
|
59
60
|
RDoc::RDoc.add_generator( self )
|
60
61
|
|
@@ -62,13 +63,13 @@ class RDoc::Generator::Darkfish < RDoc::Generator::XML
|
|
62
63
|
|
63
64
|
# Subversion rev
|
64
65
|
SVNRev = %$Rev: 52 $
|
65
|
-
|
66
|
+
|
66
67
|
# Subversion ID
|
67
68
|
SVNId = %$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
|
68
69
|
|
69
70
|
# Path to this file's parent directory. Used to find templates and other
|
70
71
|
# resources.
|
71
|
-
GENERATOR_DIR =
|
72
|
+
GENERATOR_DIR = File.join 'rdoc', 'generator'
|
72
73
|
|
73
74
|
# Release Version
|
74
75
|
VERSION = '1.1.6'
|
@@ -96,43 +97,55 @@ class RDoc::Generator::Darkfish < RDoc::Generator::XML
|
|
96
97
|
|
97
98
|
### Initialize a few instance variables before we start
|
98
99
|
def initialize( options )
|
99
|
-
@
|
100
|
-
@
|
101
|
-
|
102
|
-
@files = []
|
103
|
-
@classes = []
|
104
|
-
@hyperlinks = {}
|
100
|
+
@options = options
|
101
|
+
@options.diagram = false
|
105
102
|
|
106
|
-
|
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
|
107
110
|
|
108
|
-
|
109
|
-
|
111
|
+
raise RDoc::Error, "could not find template #{template.inspect}" unless
|
112
|
+
template_dir
|
110
113
|
|
111
|
-
|
114
|
+
@template_dir = Pathname.new File.expand_path(template_dir)
|
115
|
+
|
116
|
+
@files = nil
|
117
|
+
@classes = nil
|
118
|
+
|
119
|
+
@basedir = Pathname.pwd.expand_path
|
112
120
|
end
|
113
|
-
|
114
|
-
|
121
|
+
|
115
122
|
######
|
116
123
|
public
|
117
124
|
######
|
118
125
|
|
119
126
|
# The output directory
|
120
127
|
attr_reader :outputdir
|
121
|
-
|
122
|
-
|
128
|
+
|
129
|
+
|
123
130
|
### Output progress information if debugging is enabled
|
124
131
|
def debug_msg( *msg )
|
125
|
-
return unless $
|
132
|
+
return unless $DEBUG_RDOC
|
126
133
|
$stderr.puts( *msg )
|
127
134
|
end
|
128
|
-
|
129
|
-
|
135
|
+
|
136
|
+
def class_dir
|
137
|
+
CLASS_DIR
|
138
|
+
end
|
139
|
+
|
140
|
+
def file_dir
|
141
|
+
FILE_DIR
|
142
|
+
end
|
143
|
+
|
130
144
|
### Create the directories the generated docs will live in if
|
131
145
|
### they don't already exist.
|
132
146
|
def gen_sub_directories
|
133
147
|
@outputdir.mkpath
|
134
148
|
end
|
135
|
-
|
136
149
|
|
137
150
|
### Copy over the stylesheet into the appropriate place in the
|
138
151
|
### output directory.
|
@@ -143,92 +156,63 @@ class RDoc::Generator::Darkfish < RDoc::Generator::XML
|
|
143
156
|
FileUtils.cp_r( @template_dir + path, '.', :verbose => $DEBUG, :noop => $dryrun )
|
144
157
|
end
|
145
158
|
end
|
146
|
-
|
147
|
-
|
159
|
+
|
160
|
+
|
148
161
|
|
149
162
|
### Build the initial indices and output objects
|
150
163
|
### based on an array of TopLevel objects containing
|
151
|
-
### the extracted information.
|
152
|
-
def generate(
|
164
|
+
### the extracted information.
|
165
|
+
def generate( top_levels )
|
153
166
|
@outputdir = Pathname.new( @options.op_dir ).expand_path( @basedir )
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
167
|
+
|
168
|
+
@files = top_levels.sort
|
169
|
+
@classes = RDoc::TopLevel.all_classes_and_modules.sort
|
170
|
+
@methods = @classes.map { |m| m.method_list }.flatten.sort
|
171
|
+
@modsort = get_sorted_module_list( @classes )
|
159
172
|
|
160
173
|
# Now actually write the output
|
161
|
-
|
174
|
+
write_style_sheet
|
175
|
+
generate_index
|
176
|
+
generate_class_files
|
177
|
+
generate_file_files
|
162
178
|
|
163
179
|
rescue StandardError => err
|
164
180
|
debug_msg "%s: %s\n %s" % [ err.class.name, err.message, err.backtrace.join("\n ") ]
|
165
181
|
raise
|
166
182
|
end
|
167
183
|
|
168
|
-
|
169
|
-
### No-opped
|
170
|
-
def load_html_template # :nodoc:
|
171
|
-
end
|
172
|
-
|
173
|
-
|
174
|
-
### Generate output
|
175
|
-
def generate_xhtml( options, files, classes )
|
176
|
-
files = gen_into( @files )
|
177
|
-
classes = gen_into( @classes )
|
178
|
-
|
179
|
-
# Make a hash of class info keyed by class name
|
180
|
-
classes_by_classname = classes.inject({}) {|hash, classinfo|
|
181
|
-
hash[ classinfo[:full_name] ] = classinfo
|
182
|
-
hash[ classinfo[:full_name] ][:outfile] =
|
183
|
-
classinfo[:full_name].gsub( /::/, '/' ) + '.html'
|
184
|
-
hash
|
185
|
-
}
|
186
|
-
|
187
|
-
# Make a hash of file info keyed by path
|
188
|
-
files_by_path = files.inject({}) {|hash, fileinfo|
|
189
|
-
hash[ fileinfo[:full_path] ] = fileinfo
|
190
|
-
hash[ fileinfo[:full_path] ][:outfile] = fileinfo[:full_path] + '.html'
|
191
|
-
hash
|
192
|
-
}
|
193
|
-
|
194
|
-
self.write_style_sheet
|
195
|
-
self.generate_index( options, files_by_path, classes_by_classname )
|
196
|
-
self.generate_class_files( options, files_by_path, classes_by_classname )
|
197
|
-
self.generate_file_files( options, files_by_path, classes_by_classname )
|
198
|
-
end
|
199
|
-
|
200
|
-
|
201
|
-
|
202
184
|
#########
|
203
185
|
protected
|
204
186
|
#########
|
205
187
|
|
206
|
-
### Return a list of the documented modules sorted by salience first, then
|
188
|
+
### Return a list of the documented modules sorted by salience first, then
|
189
|
+
### by name.
|
207
190
|
def get_sorted_module_list( classes )
|
208
|
-
nscounts = classes.
|
209
|
-
|
210
|
-
counthash[
|
211
|
-
counthash[
|
212
|
-
|
191
|
+
nscounts = classes.inject({}) do |counthash, klass|
|
192
|
+
top_level = klass.full_name.gsub( /::.*/, '' )
|
193
|
+
counthash[top_level] ||= 0
|
194
|
+
counthash[top_level] += 1
|
195
|
+
|
213
196
|
counthash
|
214
197
|
end
|
215
198
|
|
216
|
-
# Sort based on how often the
|
217
|
-
# of the module -- this works for projects that put their stuff into
|
218
|
-
# namespace, of course, but doesn't hurt if they don't.
|
219
|
-
|
220
|
-
|
199
|
+
# Sort based on how often the top level namespace occurs, and then on the
|
200
|
+
# name of the module -- this works for projects that put their stuff into
|
201
|
+
# a namespace, of course, but doesn't hurt if they don't.
|
202
|
+
classes.sort_by do |klass|
|
203
|
+
top_level = klass.full_name.gsub( /::.*/, '' )
|
221
204
|
[
|
222
|
-
nscounts[
|
223
|
-
|
205
|
+
nscounts[ top_level ] * -1,
|
206
|
+
klass.full_name
|
224
207
|
]
|
208
|
+
end.select do |klass|
|
209
|
+
klass.document_self
|
225
210
|
end
|
226
211
|
end
|
227
|
-
|
228
|
-
|
212
|
+
|
229
213
|
### Generate an index page which lists all the classes which
|
230
214
|
### are documented.
|
231
|
-
def generate_index
|
215
|
+
def generate_index
|
232
216
|
debug_msg "Rendering the index page..."
|
233
217
|
|
234
218
|
templatefile = @template_dir + 'index.rhtml'
|
@@ -237,16 +221,16 @@ class RDoc::Generator::Darkfish < RDoc::Generator::XML
|
|
237
221
|
template.filename = templatefile.to_s
|
238
222
|
context = binding()
|
239
223
|
|
240
|
-
modsort = self.get_sorted_module_list( classes )
|
241
224
|
output = nil
|
225
|
+
|
242
226
|
begin
|
243
227
|
output = template.result( context )
|
244
228
|
rescue NoMethodError => err
|
245
|
-
raise "Error while evaluating %s: %s (at %p)" % [
|
229
|
+
raise RDoc::Error, "Error while evaluating %s: %s (at %p)" % [
|
246
230
|
templatefile,
|
247
231
|
err.message,
|
248
232
|
eval( "_erbout[-50,50]", context )
|
249
|
-
]
|
233
|
+
], err.backtrace
|
250
234
|
end
|
251
235
|
|
252
236
|
outfile = @basedir + @options.op_dir + 'index.html'
|
@@ -260,40 +244,30 @@ class RDoc::Generator::Darkfish < RDoc::Generator::XML
|
|
260
244
|
end
|
261
245
|
end
|
262
246
|
|
263
|
-
|
264
|
-
|
265
|
-
### Generate a documentation file for each class present in the
|
266
|
-
### given hash of +classes+.
|
267
|
-
def generate_class_files( options, files, classes )
|
247
|
+
### Generate a documentation file for each class
|
248
|
+
def generate_class_files
|
268
249
|
debug_msg "Generating class documentation in #@outputdir"
|
269
250
|
templatefile = @template_dir + 'classpage.rhtml'
|
270
|
-
outputdir = @outputdir
|
271
251
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
rel_prefix = outputdir.relative_path_from( outfile.dirname )
|
278
|
-
svninfo = self.get_svninfo( classinfo )
|
252
|
+
@classes.each do |klass|
|
253
|
+
debug_msg " working on %s (%s)" % [ klass.full_name, klass.path ]
|
254
|
+
outfile = @outputdir + klass.path
|
255
|
+
rel_prefix = @outputdir.relative_path_from( outfile.dirname )
|
256
|
+
svninfo = self.get_svninfo( klass )
|
279
257
|
|
280
258
|
debug_msg " rendering #{outfile}"
|
281
259
|
self.render_template( templatefile, binding(), outfile )
|
282
260
|
end
|
283
261
|
end
|
284
262
|
|
285
|
-
|
286
|
-
|
287
|
-
### given hash of +files+.
|
288
|
-
def generate_file_files( options, files, classes )
|
263
|
+
### Generate a documentation file for each file
|
264
|
+
def generate_file_files
|
289
265
|
debug_msg "Generating file documentation in #@outputdir"
|
290
266
|
templatefile = @template_dir + 'filepage.rhtml'
|
291
267
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
outfile = @outputdir + fileinfo[:outfile]
|
296
|
-
debug_msg " working on %s (%s)" % [ path, outfile ]
|
268
|
+
@files.each do |file|
|
269
|
+
outfile = @outputdir + file.path
|
270
|
+
debug_msg " working on %s (%s)" % [ file.full_name, outfile ]
|
297
271
|
rel_prefix = @outputdir.relative_path_from( outfile.dirname )
|
298
272
|
context = binding()
|
299
273
|
|
@@ -306,7 +280,7 @@ class RDoc::Generator::Darkfish < RDoc::Generator::XML
|
|
306
280
|
### Return a string describing the amount of time in the given number of
|
307
281
|
### seconds in terms a human can understand easily.
|
308
282
|
def time_delta_string( seconds )
|
309
|
-
return 'less than a minute' if seconds < 1.minute
|
283
|
+
return 'less than a minute' if seconds < 1.minute
|
310
284
|
return (seconds / 1.minute).to_s + ' minute' + (seconds/60 == 1 ? '' : 's') if seconds < 50.minutes
|
311
285
|
return 'about one hour' if seconds < 90.minutes
|
312
286
|
return (seconds / 1.hour).to_s + ' hours' if seconds < 18.hours
|
@@ -322,7 +296,7 @@ class RDoc::Generator::Darkfish < RDoc::Generator::XML
|
|
322
296
|
|
323
297
|
# %q$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $"
|
324
298
|
SVNID_PATTERN = /
|
325
|
-
\$Id:\s
|
299
|
+
\$Id:\s
|
326
300
|
(\S+)\s # filename
|
327
301
|
(\d+)\s # rev
|
328
302
|
(\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD)
|
@@ -333,15 +307,14 @@ class RDoc::Generator::Darkfish < RDoc::Generator::XML
|
|
333
307
|
|
334
308
|
### Try to extract Subversion information out of the first constant whose value looks like
|
335
309
|
### a subversion Id tag. If no matching constant is found, and empty hash is returned.
|
336
|
-
def get_svninfo(
|
337
|
-
return {}
|
338
|
-
|
339
|
-
|
340
|
-
constants.find {|c| c[:value] =~ SVNID_PATTERN } or return {}
|
310
|
+
def get_svninfo( klass )
|
311
|
+
constants = klass.constants or return {}
|
312
|
+
|
313
|
+
constants.find {|c| c.value =~ SVNID_PATTERN } or return {}
|
341
314
|
|
342
315
|
filename, rev, date, time, committer = $~.captures
|
343
316
|
commitdate = Time.parse( date + ' ' + time )
|
344
|
-
|
317
|
+
|
345
318
|
return {
|
346
319
|
:filename => filename,
|
347
320
|
:rev => Integer( rev ),
|
@@ -352,23 +325,24 @@ class RDoc::Generator::Darkfish < RDoc::Generator::XML
|
|
352
325
|
end
|
353
326
|
|
354
327
|
|
355
|
-
### Load and render the erb template in the given +templatefile+ within the
|
356
|
-
### +context+ (a Binding object) and write it out to +outfile+.
|
357
|
-
### +outfile+ should be Pathname-like objects.
|
328
|
+
### Load and render the erb template in the given +templatefile+ within the
|
329
|
+
### specified +context+ (a Binding object) and write it out to +outfile+.
|
330
|
+
### Both +templatefile+ and +outfile+ should be Pathname-like objects.
|
331
|
+
|
358
332
|
def render_template( templatefile, context, outfile )
|
359
333
|
template_src = templatefile.read
|
360
334
|
template = ERB.new( template_src, nil, '<>' )
|
361
335
|
template.filename = templatefile.to_s
|
362
336
|
|
363
337
|
output = begin
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
338
|
+
template.result( context )
|
339
|
+
rescue NoMethodError => err
|
340
|
+
raise RDoc::Error, "Error while evaluating %s: %s (at %p)" % [
|
341
|
+
templatefile.to_s,
|
342
|
+
err.message,
|
343
|
+
eval( "_erbout[-50,50]", context )
|
344
|
+
], err.backtrace
|
345
|
+
end
|
372
346
|
|
373
347
|
unless $dryrun
|
374
348
|
outfile.dirname.mkpath
|
@@ -387,7 +361,7 @@ end # Roc::Generator::Darkfish
|
|
387
361
|
|
388
362
|
### Time constants
|
389
363
|
module TimeConstantMethods # :nodoc:
|
390
|
-
|
364
|
+
|
391
365
|
### Number of seconds (returns receiver unmodified)
|
392
366
|
def seconds
|
393
367
|
return self
|
@@ -398,7 +372,7 @@ module TimeConstantMethods # :nodoc:
|
|
398
372
|
def minutes
|
399
373
|
return self * 60
|
400
374
|
end
|
401
|
-
alias_method :minute, :minutes
|
375
|
+
alias_method :minute, :minutes
|
402
376
|
|
403
377
|
### Returns the number of seconds in <receiver> hours
|
404
378
|
def hours
|
@@ -437,14 +411,14 @@ module TimeConstantMethods # :nodoc:
|
|
437
411
|
alias_method :year, :years
|
438
412
|
|
439
413
|
|
440
|
-
### Returns the Time <receiver> number of seconds before the
|
414
|
+
### Returns the Time <receiver> number of seconds before the
|
441
415
|
### specified +time+. E.g., 2.hours.before( header.expiration )
|
442
416
|
def before( time )
|
443
417
|
return time - self
|
444
418
|
end
|
445
|
-
|
446
419
|
|
447
|
-
|
420
|
+
|
421
|
+
### Returns the Time <receiver> number of seconds ago. (e.g.,
|
448
422
|
### expiration > 2.hours.ago )
|
449
423
|
def ago
|
450
424
|
return self.before( ::Time.now )
|
@@ -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
|
+
|