@@ -53,38 +53,15 @@ class RDoc::Generator::Darkfish
53
53
54
54
include ERB ::Util
55
55
56
- ##
57
- # Subversion rev
58
-
59
- SVNRev = %$Rev: 52 $
60
-
61
- ##
62
- # Subversion ID
63
-
64
- SVNId = %$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
65
-
66
56
# Path to this file's parent directory. Used to find templates and other
67
57
# resources.
68
58
69
59
GENERATOR_DIR = File . join 'rdoc' , 'generator'
70
60
61
+ ##
71
62
# Release Version
72
63
73
- VERSION = '1.1.6'
74
-
75
- # Directory where generated classes live relative to the root
76
-
77
- CLASS_DIR = nil
78
-
79
- # Directory where generated files live relative to the root
80
-
81
- FILE_DIR = nil
82
-
83
- # Standard generator factory method
84
-
85
- def self . for options
86
- new options
87
- end
64
+ VERSION = '2'
88
65
89
66
##
90
67
# Initialize a few instance variables before we start
@@ -93,6 +70,7 @@ def initialize options
93
70
@options = options
94
71
95
72
@template_dir = Pathname . new options . template_dir
73
+ @template_cache = { }
96
74
97
75
@files = nil
98
76
@classes = nil
@@ -113,12 +91,20 @@ def debug_msg *msg
113
91
$stderr. puts ( *msg )
114
92
end
115
93
94
+ ##
95
+ # Directory where generated class HTML files live relative to the output
96
+ # dir.
97
+
116
98
def class_dir
117
- CLASS_DIR
99
+ nil
118
100
end
119
101
102
+ ##
103
+ # Directory where generated class HTML files live relative to the output
104
+ # dir.
105
+
120
106
def file_dir
121
- FILE_DIR
107
+ nil
122
108
end
123
109
124
110
##
@@ -229,9 +215,10 @@ def generate_class_files
229
215
230
216
@classes . each do |klass |
231
217
debug_msg " working on %s (%s)" % [ klass . full_name , klass . path ]
232
- out_file = @outputdir + klass . path
233
- rel_prefix = @outputdir . relative_path_from out_file . dirname
234
- svninfo = self . get_svninfo klass
218
+ out_file = @outputdir + klass . path
219
+ # suppress 1.9.3 warning
220
+ rel_prefix = rel_prefix = @outputdir . relative_path_from ( out_file . dirname )
221
+ svninfo = svninfo = self . get_svninfo ( klass )
235
222
236
223
debug_msg " rendering #{ out_file } "
237
224
render_template template_file , out_file do |io | binding end
@@ -249,7 +236,8 @@ def generate_file_files
249
236
@files . each do |file |
250
237
out_file = @outputdir + file . path
251
238
debug_msg " working on %s (%s)" % [ file . full_name , out_file ]
252
- rel_prefix = @outputdir . relative_path_from out_file . dirname
239
+ # suppress 1.9.3 warning
240
+ rel_prefix = rel_prefix = @outputdir . relative_path_from ( out_file . dirname )
253
241
254
242
debug_msg " rendering #{ out_file } "
255
243
render_template template_file , out_file do |io | binding end
@@ -317,7 +305,7 @@ def get_svninfo klass
317
305
# An io will be yielded which must be captured by binding in the caller.
318
306
319
307
def render_template template_file , out_file # :yield: io
320
- template_src = template_file . read
308
+ template = template_for template_file
321
309
322
310
unless @options . dry_run then
323
311
debug_msg "Outputting to %s" % [ out_file . expand_path ]
@@ -326,15 +314,11 @@ def render_template template_file, out_file # :yield: io
326
314
out_file . open 'w' , 0644 do |io |
327
315
io . set_encoding @options . encoding if Object . const_defined? :Encoding
328
316
329
- template = RDoc ::ERBIO . new template_src , nil , '<>' , 'io'
330
-
331
317
context = yield io
332
318
333
319
template_result template , context , template_file
334
320
end
335
321
else
336
- template = ERB . new template_src , nil , '<>'
337
-
338
322
context = yield nil
339
323
340
324
output = template_result template , context , template_file
@@ -359,5 +343,20 @@ def template_result template, context, template_file
359
343
] , e . backtrace
360
344
end
361
345
346
+ ##
347
+ # Retrieves a cache template for +file+, if present, or fills the cache.
348
+
349
+ def template_for file
350
+ template = @template_cache [ file ]
351
+
352
+ return template if template
353
+
354
+ klass = @options . dry_run ? ERB : RDoc ::ERBIO
355
+
356
+ template = klass . new file . read , nil , '<>'
357
+ @template_cache [ file ] = template
358
+ template
359
+ end
360
+
362
361
end
363
362
0 commit comments