Skip to content

Commit 9b52af3

Browse files
committed
Fix sections not displaying their text
There were a few things wrong that made this not work: * Formatting expects `@comment` but there is only `@comments` * The parse method used for marshaling overwrote the markdown parse method * `@store` was not present, which the formatter requires
1 parent 23bccee commit 9b52af3

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

lib/rdoc/code_object/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def add_section(title, comment = nil)
587587
if section = @sections[title] then
588588
section.add_comment comment if comment
589589
else
590-
section = Section.new self, title, comment
590+
section = Section.new self, title, comment, @store
591591
@sections[title] = section
592592
end
593593

lib/rdoc/code_object/context/section.rb

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ class RDoc::Context::Section
1717

1818
MARSHAL_VERSION = 0 # :nodoc:
1919

20-
##
21-
# Section comment
22-
23-
attr_reader :comment
24-
2520
##
2621
# Section comments
2722

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

3833
attr_reader :title
3934

35+
##
36+
# The RDoc::Store for this object.
37+
38+
attr_reader :store
39+
4040
##
4141
# Creates a new section with +title+ and +comment+
4242

43-
def initialize(parent, title, comment)
43+
def initialize(parent, title, comment, store = nil)
4444
@parent = parent
4545
@title = title ? title.strip : title
46+
@store = store
4647

4748
@comments = []
4849

@@ -151,7 +152,7 @@ def marshal_dump
151152
[
152153
MARSHAL_VERSION,
153154
@title,
154-
parse,
155+
to_document,
155156
]
156157
end
157158

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

172-
def parse
173+
def to_document
173174
RDoc::Markup::Document.new(*@comments.map(&:parse))
174175
end
175176

@@ -182,6 +183,23 @@ def plain_html
182183
@title || 'Top Section'
183184
end
184185

186+
##
187+
# Section comment
188+
189+
def comment
190+
return nil if @comments.empty?
191+
RDoc::Comment.from_document(to_document)
192+
end
193+
194+
def description
195+
return '' if @comments.empty?
196+
markup comment
197+
end
198+
199+
def language
200+
@comments.first&.language
201+
end
202+
185203
##
186204
# Removes a comment from this section if it is from the same file as
187205
# +comment+

test/rdoc/rdoc_context_section_test.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ def test_add_comment
4040
assert_equal [c2, c3], s.comments
4141
end
4242

43+
def test_description
44+
file1 = @store.add_file 'file1.rb'
45+
klass = file1.add_class RDoc::NormalClass, 'Klass'
46+
47+
48+
c1 = comment "# :section: section\n", file1, :ruby
49+
c2 = comment "# hello\n", file1, :ruby
50+
c3 = comment "# <tt>world</tt>\n", file1, :ruby
51+
52+
s = @S.new klass, 'section', c1, @store
53+
assert_equal '', s.description
54+
55+
s.add_comment c2
56+
assert_equal "\n<p>hello</p>\n", s.description
57+
58+
s.add_comment c3
59+
assert_equal "\n<p>hello</p>\n\n<p><code>world</code></p>\n", s.description
60+
end
61+
4362
def test_aref
4463
assert_equal 'section', @s.aref
4564

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

88107
assert_equal 'section', loaded.title
89-
assert_equal expected, loaded.parse
108+
assert_equal expected, loaded.to_document
90109
assert_nil loaded.parent, 'parent is set manually'
91110
end
92111

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

114133
assert_equal 'section', loaded.title
115-
assert_equal expected, loaded.parse
134+
assert_equal expected, loaded.to_document
116135
assert_nil loaded.parent, 'parent is set manually'
117136
end
118137

@@ -139,7 +158,7 @@ def test_remove_comment_document
139158

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

142-
assert_equal doc(other_comment.parse), loaded.parse
161+
assert_equal doc(other_comment.parse), loaded.to_document
143162
end
144163

145164
end

0 commit comments

Comments
 (0)