diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/rdoc/parser.rb | 11 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser.rb | 16 |
3 files changed, 30 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Mon Dec 3 07:52:41 2012 Eric Hodel <drbrain@segment7.net> + + * lib/rdoc/parser.rb: Improved modeline support. Patch by nobu. + * test/rdoc/test_rdoc_parser.rb: Test for above. + Sun Dec 3 00:06:00 2012 Kenta Murata <mrkn@mrkn.jp> * ext/bigdecimal/bigdecimal.c (BigDecimal_new): stop checking string diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 1d4d0675b8..bf9ab77218 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -1,3 +1,5 @@ +# -*- coding: us-ascii -*- + ## # A parser is simple a class that subclasses RDoc::Parser and implements #scan # to fill in an RDoc::TopLevel with parsed data. @@ -157,11 +159,16 @@ class RDoc::Parser io.gets end - line =~ /-\*-(.*?)-\*-/ + /-\*-\s*(.*?\S)\s*-\*-/ =~ line return nil unless type = $1 - type.strip.downcase + if /;/ =~ type then + return nil unless /(?:\s|\A)mode:\s*([^\s;]+)/i =~ type + type = $1 + end + + type.downcase rescue ArgumentError # invalid byte sequence, etc. end diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb index 628d1bd1da..1058323457 100644 --- a/test/rdoc/test_rdoc_parser.rb +++ b/test/rdoc/test_rdoc_parser.rb @@ -1,3 +1,5 @@ +# -*- coding: us-ascii -*- + require 'rdoc/test_case' class TestRDocParser < RDoc::TestCase @@ -111,6 +113,20 @@ class TestRDocParser < RDoc::TestCase File.unlink readme_ext end + def test_check_modeline_with_other + readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}" + + open readme_ext, 'w' do |io| + io.puts "# README.EXT - -*- mode: RDoc; indent-tabs-mode: nil -*-" + io.puts + io.puts "This document explains how to make extension libraries for Ruby." + end + + assert_equal 'rdoc', @RP.check_modeline(readme_ext) + ensure + File.unlink readme_ext + end + def test_check_modeline_no_modeline readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}" |