summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-01 22:24:53 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-01 22:24:53 +0000
commitf242cefc68e8755493a50aaf2a30943e85994d6d (patch)
tree362fd2e2ba34b31191f64b0bf49be2137c6396ff /lib/rdoc
parent2ba9cdcee6b0b97999c74c6fb19cdae08edd0e25 (diff)
* lib/rdoc/parser.rb: Parse files with a -*- rdoc -*- modeline
* test/rdoc/test_rdoc_parser.rb: Test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/parser.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb
index b51f7868ea..1d4d0675b8 100644
--- a/lib/rdoc/parser.rb
+++ b/lib/rdoc/parser.rb
@@ -138,13 +138,34 @@ class RDoc::Parser
# The default parser must not parse binary files
ext_name = File.extname file_name
return parser if ext_name.empty?
- return if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/
+ if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/ then
+ case check_modeline file_name
+ when 'rdoc' then # continue
+ else return nil
+ end
+ end
parser
rescue Errno::EACCES
end
##
+ # Returns the file type from the modeline in +file_name+
+
+ def self.check_modeline file_name
+ line = open file_name do |io|
+ io.gets
+ end
+
+ line =~ /-\*-(.*?)-\*-/
+
+ return nil unless type = $1
+
+ type.strip.downcase
+ rescue ArgumentError # invalid byte sequence, etc.
+ end
+
+ ##
# Finds and instantiates the correct parser for the given +file_name+ and
# +content+.