ruby-changes:26092
From: drbrain <ko1@a...>
Date: Mon, 3 Dec 2012 07:56:51 +0900 (JST)
Subject: [ruby-changes:26092] drbrain:r38149 (trunk): * lib/rdoc/parser.rb: Improved modeline support. Patch by nobu.
drbrain 2012-12-03 07:52:57 +0900 (Mon, 03 Dec 2012) New Revision: 38149 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38149 Log: * lib/rdoc/parser.rb: Improved modeline support. Patch by nobu. * test/rdoc/test_rdoc_parser.rb: Test for above. Modified files: trunk/ChangeLog trunk/lib/rdoc/parser.rb trunk/test/rdoc/test_rdoc_parser.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38148) +++ ChangeLog (revision 38149) @@ -1,3 +1,8 @@ +Mon Dec 3 07:52:41 2012 Eric Hodel <drbrain@s...> + + * 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@m...> * ext/bigdecimal/bigdecimal.c (BigDecimal_new): stop checking string Index: lib/rdoc/parser.rb =================================================================== --- lib/rdoc/parser.rb (revision 38148) +++ lib/rdoc/parser.rb (revision 38149) @@ -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 @@ 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 Index: test/rdoc/test_rdoc_parser.rb =================================================================== --- test/rdoc/test_rdoc_parser.rb (revision 38148) +++ test/rdoc/test_rdoc_parser.rb (revision 38149) @@ -1,3 +1,5 @@ +# -*- coding: us-ascii -*- + require 'rdoc/test_case' class TestRDocParser < RDoc::TestCase @@ -111,6 +113,20 @@ 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.#{$$}" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/