summaryrefslogtreecommitdiff
path: root/lib/rdoc/code_object/context
diff options
context:
space:
mode:
authorStan Lo <stan.lo@shopify.com>2025-05-22 22:49:04 +0100
committerTakashi Kokubun <takashikkbn@gmail.com>2025-05-22 15:04:47 -0700
commit03eb777c69d64aa4941891a784c1fd67b44ea42c (patch)
tree56dfbf2ce8dd8fe33fa9f34465489529e38c9897 /lib/rdoc/code_object/context
parentca1ea9578485c27daac1e16107cb48551a58d8ad (diff)
Sync RDoc 6.14.0
Diffstat (limited to 'lib/rdoc/code_object/context')
-rw-r--r--lib/rdoc/code_object/context/section.rb90
1 files changed, 16 insertions, 74 deletions
diff --git a/lib/rdoc/code_object/context/section.rb b/lib/rdoc/code_object/context/section.rb
index aecd4e0213..ff4d5a60d8 100644
--- a/lib/rdoc/code_object/context/section.rb
+++ b/lib/rdoc/code_object/context/section.rb
@@ -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
@@ -116,8 +103,6 @@ class RDoc::Context::Section
end
comment
- when RDoc::Markup::Document then
- comment
else
raise TypeError, "unknown comment #{comment.inspect}"
end
@@ -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