@@ -53,38 +53,15 @@ class RDoc::Generator::Darkfish
5353
5454 include ERB ::Util
5555
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-
6656 # Path to this file's parent directory. Used to find templates and other
6757 # resources.
6858
6959 GENERATOR_DIR = File . join 'rdoc' , 'generator'
7060
61+ ##
7162 # Release Version
7263
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'
8865
8966 ##
9067 # Initialize a few instance variables before we start
@@ -93,6 +70,7 @@ def initialize options
9370 @options = options
9471
9572 @template_dir = Pathname . new options . template_dir
73+ @template_cache = { }
9674
9775 @files = nil
9876 @classes = nil
@@ -113,12 +91,20 @@ def debug_msg *msg
11391 $stderr. puts ( *msg )
11492 end
11593
94+ ##
95+ # Directory where generated class HTML files live relative to the output
96+ # dir.
97+
11698 def class_dir
117- CLASS_DIR
99+ nil
118100 end
119101
102+ ##
103+ # Directory where generated class HTML files live relative to the output
104+ # dir.
105+
120106 def file_dir
121- FILE_DIR
107+ nil
122108 end
123109
124110 ##
@@ -229,9 +215,10 @@ def generate_class_files
229215
230216 @classes . each do |klass |
231217 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 )
235222
236223 debug_msg " rendering #{ out_file } "
237224 render_template template_file , out_file do |io | binding end
@@ -249,7 +236,8 @@ def generate_file_files
249236 @files . each do |file |
250237 out_file = @outputdir + file . path
251238 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 )
253241
254242 debug_msg " rendering #{ out_file } "
255243 render_template template_file , out_file do |io | binding end
@@ -317,7 +305,7 @@ def get_svninfo klass
317305 # An io will be yielded which must be captured by binding in the caller.
318306
319307 def render_template template_file , out_file # :yield: io
320- template_src = template_file . read
308+ template = template_for template_file
321309
322310 unless @options . dry_run then
323311 debug_msg "Outputting to %s" % [ out_file . expand_path ]
@@ -326,15 +314,11 @@ def render_template template_file, out_file # :yield: io
326314 out_file . open 'w' , 0644 do |io |
327315 io . set_encoding @options . encoding if Object . const_defined? :Encoding
328316
329- template = RDoc ::ERBIO . new template_src , nil , '<>' , 'io'
330-
331317 context = yield io
332318
333319 template_result template , context , template_file
334320 end
335321 else
336- template = ERB . new template_src , nil , '<>'
337-
338322 context = yield nil
339323
340324 output = template_result template , context , template_file
@@ -359,5 +343,20 @@ def template_result template, context, template_file
359343 ] , e . backtrace
360344 end
361345
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+
362361end
363362
0 commit comments