diff options
Diffstat (limited to 'lib/rdoc/parser.rb')
-rw-r--r-- | lib/rdoc/parser.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 794fad00e9..6855cfcfc5 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -63,10 +63,31 @@ class RDoc::Parser end ## + # Shamelessly stolen from the ptools gem (since RDoc cannot depend on + # the gem). + + def self.binary?(file) + s = (File.read(file, File.stat(file).blksize) || "").split(//) + ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30 + end + private_class_method :binary? + + ## # Return a parser that can handle a particular extension def self.can_parse(file_name) - RDoc::Parser.parsers.find { |regexp, parser| regexp =~ file_name }.last + parser = RDoc::Parser.parsers.find { |regexp,| regexp =~ file_name }.last + + # + # The default parser should *NOT* parse binary files. + # + if parser == RDoc::Parser::Simple then + if binary? file_name then + return nil + end + end + + return parser end ## |