Sync RDoc 6.14.0

This commit is contained in:
Stan Lo 2025-05-22 22:49:04 +01:00 committed by Takashi Kokubun
parent ca1ea95784
commit 03eb777c69
185 changed files with 2008 additions and 1655 deletions

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'cgi/util'
require 'cgi/escape'
##
# A section of documentation like:
@ -39,7 +39,7 @@ class RDoc::Context::Section
##
# Creates a new section with +title+ and +comment+
def initialize parent, title, comment
def initialize(parent, title, comment)
@parent = parent
@title = title ? title.strip : title
@ -51,7 +51,7 @@ class RDoc::Context::Section
##
# Sections are equal when they have the same #title
def == other
def ==(other)
self.class === other and @title == other.title
end
@ -60,20 +60,11 @@ class RDoc::Context::Section
##
# Adds +comment+ to this section
def add_comment comment
comment = extract_comment comment
return if comment.empty?
case comment
when RDoc::Comment then
@comments << comment
when RDoc::Markup::Document then
@comments.concat comment.parts
when Array then
@comments.concat comment
else
raise TypeError, "unknown comment type: #{comment.inspect}"
def add_comment(comment)
comments = Array(comment)
comments.each do |c|
extracted_comment = extract_comment(c)
@comments << extracted_comment unless extracted_comment.empty?
end
end
@ -95,12 +86,8 @@ class RDoc::Context::Section
# # :section: The title
# # The body
def extract_comment comment
def extract_comment(comment)
case comment
when Array then
comment.map do |c|
extract_comment c
end
when nil
RDoc::Comment.new ''
when RDoc::Comment then
@ -115,8 +102,6 @@ class RDoc::Context::Section
end
end
comment
when RDoc::Markup::Document then
comment
else
raise TypeError, "unknown comment #{comment.inspect}"
@ -135,20 +120,7 @@ class RDoc::Context::Section
# The files comments in this section come from
def in_files
return [] if @comments.empty?
case @comments
when Array then
@comments.map do |comment|
comment.file
end
when RDoc::Markup::Document then
@comment.parts.map do |document|
document.file
end
else
raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
end
@comments.map(&:file)
end
##
@ -166,11 +138,11 @@ class RDoc::Context::Section
##
# De-serializes this Section. The section parent must be restored manually.
def marshal_load array
def marshal_load(array)
@parent = nil
@title = array[1]
@comments = array[2]
@comments = array[2].parts.map { |doc| RDoc::Comment.from_document(doc) }
end
##
@ -178,26 +150,7 @@ class RDoc::Context::Section
# multiple RDoc::Markup::Documents with their file set.
def parse
case @comments
when String then
super
when Array then
docs = @comments.map do |comment, location|
doc = super comment
doc.file = location if location
doc
end
RDoc::Markup::Document.new(*docs)
when RDoc::Comment then
doc = super @comments.text, comments.format
doc.file = @comments.location
doc
when RDoc::Markup::Document then
return @comments
else
raise ArgumentError, "unknown comment class #{comments.class}"
end
RDoc::Markup::Document.new(*@comments.map(&:parse))
end
##
@ -213,20 +166,9 @@ class RDoc::Context::Section
# Removes a comment from this section if it is from the same file as
# +comment+
def remove_comment comment
return if @comments.empty?
case @comments
when Array then
@comments.delete_if do |my_comment|
my_comment.file == comment.file
end
when RDoc::Markup::Document then
@comments.parts.delete_if do |document|
document.file == comment.file.name
end
else
raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
def remove_comment(target_comment)
@comments.delete_if do |stored_comment|
stored_comment.file == target_comment.file
end
end