diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-07 07:07:12 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-07 07:07:12 +0000 |
commit | 60f2c9cf5bea6dd99fac50c460eab4809cc30b01 (patch) | |
tree | ab40b4f7be3ff6d9fc8aede6b90e1aa9dded0aff /lib/rdoc | |
parent | ca9f7009db8aea70af3dd58cb6c7de0010844d22 (diff) | |
download | ruby-60f2c9cf5bea6dd99fac50c460eab4809cc30b01.tar.gz |
Upgrade to RDoc 3.5.3. Fixes [Bug #4376]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r-- | lib/rdoc/encoding.rb | 15 | ||||
-rw-r--r-- | lib/rdoc/generator/darkfish.rb | 35 | ||||
-rw-r--r-- | lib/rdoc/markup/pre_process.rb | 2 | ||||
-rw-r--r-- | lib/rdoc/text.rb | 26 |
4 files changed, 62 insertions, 16 deletions
diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb index 8483aabbc6..cfe1ba7725 100644 --- a/lib/rdoc/encoding.rb +++ b/lib/rdoc/encoding.rb @@ -12,8 +12,11 @@ module RDoc::Encoding # # The content will be converted to the +encoding+. If the file cannot be # converted a warning will be printed and nil will be returned. + # + # If +force_transcode+ is true the document will be transcoded and any + # unknown character in the target encoding will be replaced with '?' - def self.read_file filename, encoding + def self.read_file filename, encoding, force_transcode = false content = open filename, "rb" do |f| f.read end utf8 = content.sub!(/\A\xef\xbb\xbf/, '') @@ -50,8 +53,14 @@ module RDoc::Encoding warn "unknown encoding name \"#{$1}\" for #{filename}, skipping" nil rescue Encoding::UndefinedConversionError => e - warn "unable to convert #{e.message} for #{filename}, skipping" - nil + if force_transcode then + content.force_encoding orig_encoding + content.encode! encoding, :undef => :replace, :replace => '?' + content + else + warn "unable to convert #{e.message} for #{filename}, skipping" + nil + end rescue Errno::EISDIR, Errno::ENOENT nil end diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index 57873468e4..299e6b7dec 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -46,7 +46,7 @@ require 'rdoc/generator/markup' # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# + class RDoc::Generator::Darkfish RDoc::RDoc.add_generator self @@ -162,9 +162,9 @@ class RDoc::Generator::Darkfish generate_class_files generate_file_files - rescue StandardError => err + rescue => e debug_msg "%s: %s\n %s" % [ - err.class.name, err.message, err.backtrace.join("\n ") + e.class.name, e.message, e.backtrace.join("\n ") ] raise @@ -208,6 +208,12 @@ class RDoc::Generator::Darkfish out_file = @basedir + @options.op_dir + 'index.html' render_template template_file, out_file do |io| binding end + rescue => e + error = RDoc::Error.new \ + "error generating index.html: #{e.message} (#{e.class})" + error.set_backtrace e.backtrace + + raise error end ## @@ -216,9 +222,12 @@ class RDoc::Generator::Darkfish def generate_class_files template_file = @template_dir + 'classpage.rhtml' return unless template_file.exist? - debug_msg "Generating class documentation in #@outputdir" + debug_msg "Generating class documentation in #{@outputdir}" + + current = nil @classes.each do |klass| + current = klass debug_msg " working on %s (%s)" % [klass.full_name, klass.path] out_file = @outputdir + klass.path # suppress 1.9.3 warning @@ -228,6 +237,12 @@ class RDoc::Generator::Darkfish debug_msg " rendering #{out_file}" render_template template_file, out_file do |io| binding end end + rescue => e + error = RDoc::Error.new \ + "error generating #{current.path}: #{e.message} (#{e.class})" + error.set_backtrace e.backtrace + + raise error end ## @@ -236,17 +251,25 @@ class RDoc::Generator::Darkfish def generate_file_files template_file = @template_dir + 'filepage.rhtml' return unless template_file.exist? - debug_msg "Generating file documentation in #@outputdir" + debug_msg "Generating file documentation in #{@outputdir}" + + out_file = nil @files.each do |file| out_file = @outputdir + file.path - debug_msg " working on %s (%s)" % [ file.full_name, out_file ] + debug_msg " working on %s (%s)" % [file.full_name, out_file] # suppress 1.9.3 warning rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname) debug_msg " rendering #{out_file}" render_template template_file, out_file do |io| binding end end + rescue => e + error = + RDoc::Error.new "error generating #{out_file}: #{e.message} (#{e.class})" + error.set_backtrace e.backtrace + + raise error end ## diff --git a/lib/rdoc/markup/pre_process.rb b/lib/rdoc/markup/pre_process.rb index e59bd227b7..ccc2688050 100644 --- a/lib/rdoc/markup/pre_process.rb +++ b/lib/rdoc/markup/pre_process.rb @@ -120,7 +120,7 @@ class RDoc::Markup::PreProcess return '' end - content = RDoc::Encoding.read_file full_name, encoding + content = RDoc::Encoding.read_file full_name, encoding, true # strip magic comment content = content.sub(/\A# .*coding[=:].*$/, '').lstrip diff --git a/lib/rdoc/text.rb b/lib/rdoc/text.rb index 501871c8df..adbc630cf1 100644 --- a/lib/rdoc/text.rb +++ b/lib/rdoc/text.rb @@ -46,7 +46,9 @@ module RDoc::Text text.each_line do |line| line.gsub!(/^(.{8}*?)([^\t\r\n]{0,7})\t/) do - "#{$1}#{$2}#{' ' * (8 - $2.size)}" + r = "#{$1}#{$2}#{' ' * (8 - $2.size)}" + r.force_encoding text.encoding if Object.const_defined? :Encoding + r end until line !~ /\t/ expanded << line @@ -69,8 +71,11 @@ module RDoc::Text flush = [] + empty = '' + empty.force_encoding text.encoding if Object.const_defined? :Encoding + text.each_line do |line| - line[/^ {0,#{indent}}/] = '' + line[/^ {0,#{indent}}/] = empty flush << line end @@ -158,11 +163,20 @@ http://rubyforge.org/tracker/?atid=2472&group_id=627&func=browse # Strips /* */ style comments def strip_stars text + encoding = text.encoding if Object.const_defined? :Encoding + text = text.gsub %r%Document-method:\s+[\w:.#]+%, '' - text.sub! %r%/\*+% do " " * $&.length end - text.sub! %r%\*+/% do " " * $&.length end - text.gsub! %r%^[ \t]*\*%m do " " * $&.length end - text.gsub(/^\s+$/, '') + + space = ' ' + space.force_encoding encoding if encoding + + text.sub! %r%/\*+% do space * $&.length end + text.sub! %r%\*+/% do space * $&.length end + text.gsub! %r%^[ \t]*\*%m do space * $&.length end + + empty = '' + empty.force_encoding encoding if encoding + text.gsub(/^\s+$/, empty) end ## |