summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-07 22:23:38 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-07 22:23:38 +0000
commitba6ae341bab83dfc7a624c5bf20d8d162dacaff9 (patch)
tree540581a54cefcdc817577f646f09372f7e9936d1 /lib/rdoc
parentbf51c067b92361007a57909c539591d3d00cdbd8 (diff)
* lib/rdoc/*, test/rdoc/*: Update rdoc-5.0.0.beta2
Fixed ri parse defect with left-hand matched classes. https://github.com/rdoc/rdoc/pull/420 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/code_object.rb4
-rw-r--r--lib/rdoc/comment.rb3
-rw-r--r--lib/rdoc/encoding.rb75
-rw-r--r--lib/rdoc/generator/darkfish.rb6
-rw-r--r--lib/rdoc/generator/json_index.rb3
-rw-r--r--lib/rdoc/markup/parser.rb18
-rw-r--r--lib/rdoc/options.rb38
-rw-r--r--lib/rdoc/parser/ruby.rb5
-rw-r--r--lib/rdoc/parser/simple.rb3
-rw-r--r--lib/rdoc/rdoc.gemspec3
-rw-r--r--lib/rdoc/rdoc.rb23
-rw-r--r--lib/rdoc/ri/driver.rb3
-rw-r--r--lib/rdoc/ri/paths.rb3
-rw-r--r--lib/rdoc/ri/task.rb1
-rw-r--r--lib/rdoc/rubygems_hook.rb2
-rw-r--r--lib/rdoc/task.rb2
-rw-r--r--lib/rdoc/test_case.rb4
-rw-r--r--lib/rdoc/text.rb29
18 files changed, 74 insertions, 151 deletions
diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb
index dc195cc6acc..21aa2b09f5d 100644
--- a/lib/rdoc/code_object.rb
+++ b/lib/rdoc/code_object.rb
@@ -150,8 +150,7 @@ class RDoc::CodeObject
else
# HACK correct fix is to have #initialize create @comment
# with the correct encoding
- if String === @comment and
- Object.const_defined? :Encoding and @comment.empty? then
+ if String === @comment and @comment.empty? then
@comment.force_encoding comment.encoding
end
@comment
@@ -427,4 +426,3 @@ class RDoc::CodeObject
end
end
-
diff --git a/lib/rdoc/comment.rb b/lib/rdoc/comment.rb
index ebff7422336..c655763b3ea 100644
--- a/lib/rdoc/comment.rb
+++ b/lib/rdoc/comment.rb
@@ -200,7 +200,7 @@ class RDoc::Comment
def remove_private
# Workaround for gsub encoding for Ruby 1.9.2 and earlier
empty = ''
- empty.force_encoding @text.encoding if Object.const_defined? :Encoding
+ empty.force_encoding @text.encoding
@text = @text.gsub(%r%^\s*([#*]?)--.*?^\s*(\1)\+\+\n?%m, empty)
@text = @text.sub(%r%^\s*[#*]?--.*%m, '')
@@ -227,4 +227,3 @@ class RDoc::Comment
end
end
-
diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb
index 10568279379..44881d043c0 100644
--- a/lib/rdoc/encoding.rb
+++ b/lib/rdoc/encoding.rb
@@ -25,43 +25,41 @@ module RDoc::Encoding
RDoc::Encoding.set_encoding content
- if Object.const_defined? :Encoding then
- begin
- encoding ||= Encoding.default_external
- orig_encoding = content.encoding
-
- if not orig_encoding.ascii_compatible? then
- content.encode! encoding
- elsif utf8 then
- content.force_encoding Encoding::UTF_8
- content.encode! encoding
- else
- # assume the content is in our output encoding
- content.force_encoding encoding
- end
-
- unless content.valid_encoding? then
- # revert and try to transcode
- content.force_encoding orig_encoding
- content.encode! encoding
- end
-
- unless content.valid_encoding? then
- warn "unable to convert #{filename} to #{encoding}, skipping"
- content = nil
- end
- rescue Encoding::InvalidByteSequenceError,
- Encoding::UndefinedConversionError => e
- if force_transcode then
- content.force_encoding orig_encoding
- content.encode!(encoding,
- :invalid => :replace, :undef => :replace,
- :replace => '?')
- return content
- else
- warn "unable to convert #{e.message} for #{filename}, skipping"
- return nil
- end
+ begin
+ encoding ||= Encoding.default_external
+ orig_encoding = content.encoding
+
+ if not orig_encoding.ascii_compatible? then
+ content.encode! encoding
+ elsif utf8 then
+ content.force_encoding Encoding::UTF_8
+ content.encode! encoding
+ else
+ # assume the content is in our output encoding
+ content.force_encoding encoding
+ end
+
+ unless content.valid_encoding? then
+ # revert and try to transcode
+ content.force_encoding orig_encoding
+ content.encode! encoding
+ end
+
+ unless content.valid_encoding? then
+ warn "unable to convert #{filename} to #{encoding}, skipping"
+ content = nil
+ end
+ rescue Encoding::InvalidByteSequenceError,
+ Encoding::UndefinedConversionError => e
+ if force_transcode then
+ content.force_encoding orig_encoding
+ content.encode!(encoding,
+ :invalid => :replace, :undef => :replace,
+ :replace => '?')
+ return content
+ else
+ warn "unable to convert #{e.message} for #{filename}, skipping"
+ return nil
end
end
@@ -103,11 +101,8 @@ module RDoc::Encoding
remove_frozen_string_literal string
- return unless Object.const_defined? :Encoding
-
enc = Encoding.find name
string.force_encoding enc if enc
end
end
-
diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb
index 18394a2c34c..e961518fcc3 100644
--- a/lib/rdoc/generator/darkfish.rb
+++ b/lib/rdoc/generator/darkfish.rb
@@ -698,7 +698,7 @@ class RDoc::Generator::Darkfish
out_file.dirname.mkpath
out_file.open 'w', 0644 do |io|
- io.set_encoding @options.encoding if Object.const_defined? :Encoding
+ io.set_encoding @options.encoding
@context = yield io
@@ -744,8 +744,7 @@ class RDoc::Generator::Darkfish
erbout = 'io'
else
template = file.read
- template = template.encode @options.encoding if
- Object.const_defined? :Encoding
+ template = template.encode @options.encoding
file_var = File.basename(file).sub(/\..*/, '')
@@ -758,4 +757,3 @@ class RDoc::Generator::Darkfish
end
end
-
diff --git a/lib/rdoc/generator/json_index.rb b/lib/rdoc/generator/json_index.rb
index 624a2e512ee..931438b3c33 100644
--- a/lib/rdoc/generator/json_index.rb
+++ b/lib/rdoc/generator/json_index.rb
@@ -142,7 +142,7 @@ class RDoc::Generator::JsonIndex
FileUtils.mkdir_p index_file.dirname, :verbose => $DEBUG_RDOC
index_file.open 'w', 0644 do |io|
- io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
+ io.set_encoding Encoding::UTF_8
io.write 'var search_data = '
JSON.dump data, io, 0
@@ -295,4 +295,3 @@ class RDoc::Generator::JsonIndex
end
end
-
diff --git a/lib/rdoc/markup/parser.rb b/lib/rdoc/markup/parser.rb
index 2f8b7628e27..22cca204200 100644
--- a/lib/rdoc/markup/parser.rb
+++ b/lib/rdoc/markup/parser.rb
@@ -79,8 +79,6 @@ class RDoc::Markup::Parser
@binary_input = nil
@current_token = nil
@debug = false
- @have_encoding = Object.const_defined? :Encoding
- @have_byteslice = ''.respond_to? :byteslice
@input = nil
@input_encoding = nil
@line = 0
@@ -324,15 +322,7 @@ class RDoc::Markup::Parser
# The character offset for the input string at the given +byte_offset+
def char_pos byte_offset
- if @have_byteslice then
- @input.byteslice(0, byte_offset).length
- elsif @have_encoding then
- matched = @binary_input[0, byte_offset]
- matched.force_encoding @input_encoding
- matched.length
- else
- byte_offset
- end
+ @input.byteslice(0, byte_offset).length
end
##
@@ -430,11 +420,6 @@ class RDoc::Markup::Parser
@line_pos = 0
@input = input.dup
- if @have_encoding and not @have_byteslice then
- @input_encoding = @input.encoding
- @binary_input = @input.force_encoding Encoding::BINARY
- end
-
@s = StringScanner.new input
end
@@ -556,4 +541,3 @@ class RDoc::Markup::Parser
end
end
-
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index 17b0bb105dd..2bc7474eb0c 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -379,23 +379,15 @@ class RDoc::Options
@visibility = :protected
@webcvs = nil
@write_options = false
-
- if Object.const_defined? :Encoding then
- @encoding = Encoding::UTF_8
- @charset = @encoding.name
- else
- @encoding = nil
- @charset = 'UTF-8'
- end
+ @encoding = Encoding::UTF_8
+ @charset = @encoding.name
end
def init_with map # :nodoc:
init_ivars
encoding = map['encoding']
- @encoding = if Object.const_defined? :Encoding then
- encoding ? Encoding.find(encoding) : encoding
- end
+ @encoding = encoding ? Encoding.find(encoding) : encoding
@charset = map['charset']
@exclude = map['exclude']
@@ -689,19 +681,16 @@ Usage: #{opt.program_name} [options] [names...]
opt.separator "Parsing options:"
opt.separator nil
- if Object.const_defined? :Encoding then
- opt.on("--encoding=ENCODING", "-e", Encoding.list.map { |e| e.name },
- "Specifies the output encoding. All files",
- "read will be converted to this encoding.",
- "The default encoding is UTF-8.",
- "--encoding is preferred over --charset") do |value|
- @encoding = Encoding.find value
- @charset = @encoding.name # may not be valid value
- end
-
- opt.separator nil
- end
+ opt.on("--encoding=ENCODING", "-e", Encoding.list.map { |e| e.name },
+ "Specifies the output encoding. All files",
+ "read will be converted to this encoding.",
+ "The default encoding is UTF-8.",
+ "--encoding is preferred over --charset") do |value|
+ @encoding = Encoding.find value
+ @charset = @encoding.name # may not be valid value
+ end
+ opt.separator nil
opt.on("--locale=NAME",
"Specifies the output locale.") do |value|
@@ -1242,11 +1231,10 @@ Usage: #{opt.program_name} [options] [names...]
RDoc.load_yaml
open '.rdoc_options', 'w' do |io|
- io.set_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
+ io.set_encoding Encoding::UTF_8
YAML.dump self, io
end
end
end
-
diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb
index ac7094f4888..c30dbf0f4ee 100644
--- a/lib/rdoc/parser/ruby.rb
+++ b/lib/rdoc/parser/ruby.rb
@@ -170,9 +170,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
@prev_seek = nil
@markup = @options.markup
@track_visibility = :nodoc != @options.visibility
-
- @encoding = nil
- @encoding = @options.encoding if Object.const_defined? :Encoding
+ @encoding = @options.encoding
reset
end
@@ -2158,4 +2156,3 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
end
-
diff --git a/lib/rdoc/parser/simple.rb b/lib/rdoc/parser/simple.rb
index 73bb7bdffb9..f2ab27a92e7 100644
--- a/lib/rdoc/parser/simple.rb
+++ b/lib/rdoc/parser/simple.rb
@@ -52,11 +52,10 @@ class RDoc::Parser::Simple < RDoc::Parser
def remove_private_comment comment
# Workaround for gsub encoding for Ruby 1.9.2 and earlier
empty = ''
- empty.force_encoding comment.encoding if Object.const_defined? :Encoding
+ empty.force_encoding comment.encoding
comment = comment.gsub(%r%^--\n.*?^\+\+\n?%m, empty)
comment.sub(%r%^--\n.*%m, empty)
end
end
-
diff --git a/lib/rdoc/rdoc.gemspec b/lib/rdoc/rdoc.gemspec
index 606021f8b1c..74d7a152bd1 100644
--- a/lib/rdoc/rdoc.gemspec
+++ b/lib/rdoc/rdoc.gemspec
@@ -6,8 +6,7 @@ Gem::Specification.new do |s|
s.name = "rdoc"
s.version = RDoc::VERSION
- s.required_rubygems_version = Gem::Requirement.new(">= 1.3") if
- s.respond_to? :required_rubygems_version=
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3")
s.require_paths = ["lib"]
s.authors = [
diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb
index 89ba6619aa8..ec50d8eba57 100644
--- a/lib/rdoc/rdoc.rb
+++ b/lib/rdoc/rdoc.rb
@@ -340,10 +340,8 @@ option)
# Parses +filename+ and returns an RDoc::TopLevel
def parse_file filename
- if Object.const_defined? :Encoding then
- encoding = @options.encoding
- filename = filename.encode encoding
- end
+ encoding = @options.encoding
+ filename = filename.encode encoding
@stats.add_file filename
@@ -553,16 +551,14 @@ end
begin
require 'rubygems'
- if Gem.respond_to? :find_files then
- rdoc_extensions = Gem.find_files 'rdoc/discover'
+ rdoc_extensions = Gem.find_files 'rdoc/discover'
- rdoc_extensions.each do |extension|
- begin
- load extension
- rescue => e
- warn "error loading #{extension.inspect}: #{e.message} (#{e.class})"
- warn "\t#{e.backtrace.join "\n\t"}" if $DEBUG
- end
+ rdoc_extensions.each do |extension|
+ begin
+ load extension
+ rescue => e
+ warn "error loading #{extension.inspect}: #{e.message} (#{e.class})"
+ warn "\t#{e.backtrace.join "\n\t"}" if $DEBUG
end
end
rescue LoadError
@@ -572,4 +568,3 @@ end
require 'rdoc/generator/darkfish'
require 'rdoc/generator/ri'
require 'rdoc/generator/pot'
-
diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb
index 3bd0e50d84a..7942406ceb8 100644
--- a/lib/rdoc/ri/driver.rb
+++ b/lib/rdoc/ri/driver.rb
@@ -908,7 +908,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
def expand_class klass
ary = classes.keys.grep(Regexp.new("\\A#{klass.gsub(/(?=::|\z)/, '[^:]*')}\\z"))
- raise NotFoundError, klass if ary.length != 1
+ raise NotFoundError, klass if ary.length != 1 && ary.first != klass
ary.first
end
@@ -1480,4 +1480,3 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the
end
end
-
diff --git a/lib/rdoc/ri/paths.rb b/lib/rdoc/ri/paths.rb
index 41529a3e0d5..94db2216a26 100644
--- a/lib/rdoc/ri/paths.rb
+++ b/lib/rdoc/ri/paths.rb
@@ -82,8 +82,6 @@ module RDoc::RI::Paths
# ri documentation.
def self.gemdirs filter = :latest
- require 'rubygems' unless defined?(Gem)
-
ri_paths = {}
all = Gem::Specification.map do |spec|
@@ -185,4 +183,3 @@ module RDoc::RI::Paths
end
end
-
diff --git a/lib/rdoc/ri/task.rb b/lib/rdoc/ri/task.rb
index d45f0c664c3..cc0a85d4b76 100644
--- a/lib/rdoc/ri/task.rb
+++ b/lib/rdoc/ri/task.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: false
-require 'rubygems'
begin
gem 'rdoc'
rescue Gem::LoadError
diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb
index f6aeb845983..e2afb1fa910 100644
--- a/lib/rdoc/rubygems_hook.rb
+++ b/lib/rdoc/rubygems_hook.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: false
-require 'rubygems'
require 'rubygems/user_interaction'
require 'fileutils'
require 'rdoc'
@@ -251,4 +250,3 @@ class RDoc::RubygemsHook
end
end
-
diff --git a/lib/rdoc/task.rb b/lib/rdoc/task.rb
index 0577677054e..1074de01971 100644
--- a/lib/rdoc/task.rb
+++ b/lib/rdoc/task.rb
@@ -22,7 +22,6 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-require 'rubygems'
begin
gem 'rdoc'
rescue Gem::LoadError
@@ -328,4 +327,3 @@ module Rake
end
# :startdoc:
-
diff --git a/lib/rdoc/test_case.rb b/lib/rdoc/test_case.rb
index 3b928f2f3dd..7c80ecdf9c8 100644
--- a/lib/rdoc/test_case.rb
+++ b/lib/rdoc/test_case.rb
@@ -1,6 +1,4 @@
# frozen_string_literal: false
-require 'rubygems'
-
begin
gem 'minitest', '~> 4.0' unless defined?(Test::Unit)
rescue NoMethodError, Gem::LoadError
@@ -41,8 +39,6 @@ class RDoc::TestCase < MiniTest::Unit::TestCase
@top_level = nil
- @have_encoding = Object.const_defined? :Encoding
-
@RM = RDoc::Markup
RDoc::Markup::PreProcess.reset
diff --git a/lib/rdoc/text.rb b/lib/rdoc/text.rb
index b40c89806a6..a38bb921ad3 100644
--- a/lib/rdoc/text.rb
+++ b/lib/rdoc/text.rb
@@ -52,7 +52,7 @@ module RDoc::Text
:open_squote => encode_fallback('‘', encoding, '\''),
:trademark => encode_fallback('®', encoding, '(r)'),
}
- end if Object.const_defined? :Encoding
+ end
##
# Transcodes +character+ to +encoding+ with a +fallback+ character.
@@ -71,7 +71,7 @@ module RDoc::Text
text.each_line do |line|
nil while line.gsub!(/(?:\G|\r)((?:.{8})*?)([^\t\r\n]{0,7})\t/) do
r = "#{$1}#{$2}#{' ' * (8 - $2.size)}"
- r.force_encoding text.encoding if Object.const_defined? :Encoding
+ r.force_encoding text.encoding
r
end
@@ -93,7 +93,7 @@ module RDoc::Text
end
empty = ''
- empty.force_encoding text.encoding if Object.const_defined? :Encoding
+ empty.force_encoding text.encoding
text.gsub(/^ {0,#{indent}}/, empty)
end
@@ -160,7 +160,7 @@ module RDoc::Text
return text if text =~ /^(?>\s*)[^\#]/
empty = ''
- empty.force_encoding text.encoding if Object.const_defined? :Encoding
+ empty.force_encoding text.encoding
text.gsub(/^\s*(#+)/) { $1.tr '#', ' ' }.gsub(/^\s+$/, empty)
end
@@ -178,7 +178,7 @@ module RDoc::Text
def strip_stars text
return text unless text =~ %r%/\*.*\*/%m
- encoding = text.encoding if Object.const_defined? :Encoding
+ encoding = text.encoding
text = text.gsub %r%Document-method:\s+[\w:.#=!?]+%, ''
@@ -199,24 +199,9 @@ module RDoc::Text
# trademark symbols in +text+ to properly encoded characters.
def to_html text
- if Object.const_defined? :Encoding then
- html = ''.encode text.encoding
+ html = ''.encode text.encoding
- encoded = RDoc::Text::TO_HTML_CHARACTERS[text.encoding]
- else
- html = ''
- encoded = {
- :close_dquote => '”',
- :close_squote => '’',
- :copyright => '©',
- :ellipsis => '…',
- :em_dash => '—',
- :en_dash => '–',
- :open_dquote => '“',
- :open_squote => '‘',
- :trademark => '®',
- }
- end
+ encoded = RDoc::Text::TO_HTML_CHARACTERS[text.encoding]
s = StringScanner.new text
insquotes = false