Skip to content

Commit dfb71ee

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 dfb71ee

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
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: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ class RDoc::Context::Section
3737

3838
attr_reader :title
3939

40+
##
41+
# The RDoc::Store for this object.
42+
43+
attr_reader :store
44+
4045
##
4146
# Creates a new section with +title+ and +comment+
4247

43-
def initialize(parent, title, comment)
48+
def initialize(parent, title, comment, store = nil)
4449
@parent = parent
4550
@title = title ? title.strip : title
51+
@store = store
4652

4753
@comments = []
4854

@@ -67,6 +73,7 @@ def add_comment(comment)
6773
extracted_comment = extract_comment(c)
6874
@comments << extracted_comment unless extracted_comment.empty?
6975
end
76+
set_comment!
7077
end
7178

7279
##
@@ -151,7 +158,7 @@ def marshal_dump
151158
[
152159
MARSHAL_VERSION,
153160
@title,
154-
parse,
161+
to_document,
155162
]
156163
end
157164

@@ -163,13 +170,14 @@ def marshal_load(array)
163170

164171
@title = array[1]
165172
@comments = array[2].parts.map { |doc| RDoc::Comment.from_document(doc) }
173+
set_comment!
166174
end
167175

168176
##
169177
# Parses +comment_location+ into an RDoc::Markup::Document composed of
170178
# multiple RDoc::Markup::Documents with their file set.
171179

172-
def parse
180+
def to_document
173181
RDoc::Markup::Document.new(*@comments.map(&:parse))
174182
end
175183

@@ -182,6 +190,12 @@ def plain_html
182190
@title || 'Top Section'
183191
end
184192

193+
def markup(comment)
194+
# Don't try to format the default section. We don't have a store yet.
195+
return "" if comment.nil? || comment.empty?
196+
super(normalize_comment(comment.text))
197+
end
198+
185199
##
186200
# Removes a comment from this section if it is from the same file as
187201
# +comment+
@@ -190,6 +204,18 @@ def remove_comment(target_comment)
190204
@comments.delete_if do |stored_comment|
191205
stored_comment.file == target_comment.file
192206
end
207+
set_comment!
193208
end
194209

210+
private
211+
212+
def set_comment!
213+
if @comments.any?
214+
donor = @comments[0]
215+
@language = donor.language
216+
@comment = RDoc::Comment.new(@comments.map(&:text).join, donor.location)
217+
else
218+
@comment = nil
219+
end
220+
end
195221
end

test/rdoc/rdoc_context_section_test.rb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,41 @@ def test_add_comment
2626
s = @S.new klass, 'section', c1
2727

2828
assert_empty s.comments
29+
assert_nil s.comment
2930

3031
s.add_comment nil
3132

3233
assert_empty s.comments
34+
assert_nil s.comment
3335

3436
s.add_comment c2
3537

3638
assert_equal [c2], s.comments
39+
assert_equal c2, s.comment
3740

3841
s.add_comment c3
3942

4043
assert_equal [c2, c3], s.comments
44+
assert_equal comment(c2.text + c3.text, file1), s.comment
45+
end
46+
47+
def test_description
48+
file1 = @store.add_file 'file1.rb'
49+
klass = file1.add_class RDoc::NormalClass, 'Klass'
50+
51+
52+
c1 = comment "# :section: section\n", file1, :ruby
53+
c2 = comment "# hello\n", file1, :ruby
54+
c3 = comment "# <tt>world</tt>\n", file1, :ruby
55+
56+
s = @S.new klass, 'section', c1, @store
57+
assert_equal '', s.description
58+
59+
s.add_comment c2
60+
assert_equal "\n<p>hello</p>\n", s.description
61+
62+
s.add_comment c3
63+
assert_equal "\n<p>hello <code>world</code></p>\n", s.description
4164
end
4265

4366
def test_aref
@@ -86,7 +109,7 @@ def test_marshal_dump
86109
expected = doc RDoc::Comment.new('comment', @top_level).parse
87110

88111
assert_equal 'section', loaded.title
89-
assert_equal expected, loaded.parse
112+
assert_equal expected, loaded.to_document
90113
assert_nil loaded.parent, 'parent is set manually'
91114
end
92115

@@ -112,7 +135,7 @@ def test_marshal_load_version_0
112135
expected = doc RDoc::Comment.new('comment', @top_level).parse
113136

114137
assert_equal 'section', loaded.title
115-
assert_equal expected, loaded.parse
138+
assert_equal expected, loaded.to_document
116139
assert_nil loaded.parent, 'parent is set manually'
117140
end
118141

@@ -139,7 +162,7 @@ def test_remove_comment_document
139162

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

142-
assert_equal doc(other_comment.parse), loaded.parse
165+
assert_equal doc(other_comment.parse), loaded.to_document
143166
end
144167

145168
end

0 commit comments

Comments
 (0)