Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rdoc/code_object/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def add_section(title, comment = nil)
if section = @sections[title] then
section.add_comment comment if comment
else
section = Section.new self, title, comment
section = Section.new self, title, comment, @store
@sections[title] = section
end

Expand Down
34 changes: 26 additions & 8 deletions lib/rdoc/code_object/context/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ class RDoc::Context::Section

MARSHAL_VERSION = 0 # :nodoc:

##
# Section comment

attr_reader :comment

##
# Section comments

Expand All @@ -37,12 +32,18 @@ class RDoc::Context::Section

attr_reader :title

##
# The RDoc::Store for this object.

attr_reader :store

##
# Creates a new section with +title+ and +comment+

def initialize(parent, title, comment)
def initialize(parent, title, comment, store = nil)
@parent = parent
@title = title ? title.strip : title
@store = store

@comments = []

Expand Down Expand Up @@ -151,7 +152,7 @@ def marshal_dump
[
MARSHAL_VERSION,
@title,
parse,
to_document,
]
end

Expand All @@ -169,7 +170,7 @@ def marshal_load(array)
# Parses +comment_location+ into an RDoc::Markup::Document composed of
# multiple RDoc::Markup::Documents with their file set.

def parse
def to_document
RDoc::Markup::Document.new(*@comments.map(&:parse))
end

Expand All @@ -182,6 +183,23 @@ def plain_html
@title || 'Top Section'
end

##
# Section comment

def comment
return nil if @comments.empty?
RDoc::Comment.from_document(to_document)
end

def description
return '' if @comments.empty?
markup comment
end

def language
@comments.first&.language
end

##
# Removes a comment from this section if it is from the same file as
# +comment+
Expand Down
25 changes: 22 additions & 3 deletions test/rdoc/rdoc_context_section_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ def test_add_comment
assert_equal [c2, c3], s.comments
end

def test_description
file1 = @store.add_file 'file1.rb'
klass = file1.add_class RDoc::NormalClass, 'Klass'


c1 = comment "# :section: section\n", file1, :ruby
c2 = comment "# hello\n", file1, :ruby
c3 = comment "# <tt>world</tt>\n", file1, :ruby

s = @S.new klass, 'section', c1, @store
assert_equal '', s.description

s.add_comment c2
assert_equal "\n<p>hello</p>\n", s.description

s.add_comment c3
assert_equal "\n<p>hello</p>\n\n<p><code>world</code></p>\n", s.description
end

def test_aref
assert_equal 'section', @s.aref

Expand Down Expand Up @@ -86,7 +105,7 @@ def test_marshal_dump
expected = doc RDoc::Comment.new('comment', @top_level).parse

assert_equal 'section', loaded.title
assert_equal expected, loaded.parse
assert_equal expected, loaded.to_document
assert_nil loaded.parent, 'parent is set manually'
end

Expand All @@ -112,7 +131,7 @@ def test_marshal_load_version_0
expected = doc RDoc::Comment.new('comment', @top_level).parse

assert_equal 'section', loaded.title
assert_equal expected, loaded.parse
assert_equal expected, loaded.to_document
assert_nil loaded.parent, 'parent is set manually'
end

Expand All @@ -139,7 +158,7 @@ def test_remove_comment_document

loaded.remove_comment comment('bogus', @top_level)

assert_equal doc(other_comment.parse), loaded.parse
assert_equal doc(other_comment.parse), loaded.to_document
end

end