Skip to content

Commit

Permalink
Fixed table of contents display in HTML
Browse files Browse the repository at this point in the history
RDoc::ClassModule#documented? now checks comment_location.
  • Loading branch information
drbrain committed Dec 12, 2012
1 parent fe89ec5 commit 9a4d076
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
5 changes: 3 additions & 2 deletions History.rdoc
Expand Up @@ -10,7 +10,7 @@ Notable feature additions are markdown support and an WEBrick servlet that can
serve HTML from an ri store. (This means that RubyGems 2.0+ no longer needs
to build HTML documentation when installing gems.)

* Minor enhancements:
* Minor enhancements
* Added --page-dir option to give pretty names for a FAQ, guides, or other
documentation you write that is not stored in the project root. For
example, with the following layout:
Expand All @@ -24,9 +24,10 @@ to build HTML documentation when installing gems.)
at the top level in HTML output and you can access them with
`ri your_gem:syntax` and `ri your_gem:conversion`.

* Bug fixes:
* Bug fixes
* Fully qualified names for constants declared from the top level are now
attached to their class or module properly.
* Fixed table of contents display in HTML output for classes and modules.

=== 4.0.0.preview2 / 2012-12-01

Expand Down
10 changes: 9 additions & 1 deletion lib/rdoc/class_module.rb
Expand Up @@ -184,7 +184,7 @@ def clear_comment
# Appends +comment+ to the current comment, but separated by a rule. Works
# more like <tt>+=</tt>.

def comment= comment
def comment= comment # :nodoc:
comment = case comment
when RDoc::Comment then
comment.normalize
Expand Down Expand Up @@ -216,6 +216,14 @@ def document_self_or_methods
document_self || method_list.any?{ |m| m.document_self }
end

##
# Does this class or module have a comment with content or is
# #received_nodoc true?

def documented?
super or !@comment_location.empty?
end

##
# Iterates the ancestors of this class or module for which an
# RDoc::ClassModule exists.
Expand Down
@@ -1,4 +1,10 @@
<% table = current.parse(current.comment).table_of_contents
<% comment = if current.respond_to? :comment_location then
current.comment_location
else
current.comment
end
table = current.parse(comment).table_of_contents

if table.length > 1 then %>
<div id="table-of-contents">
<nav class="section">
Expand Down
Expand Up @@ -30,7 +30,7 @@
<li class="<%= klass.type %>">
<a href="<%= klass.path %>"><%= klass.full_name %></a>
<% table = []
table.concat klass.parse(klass.comment).table_of_contents
table.concat klass.parse(klass.comment_location).table_of_contents
table.concat klass.section_contents

unless table.empty? then %>
Expand Down
22 changes: 22 additions & 0 deletions test/test_rdoc_class_module.rb
Expand Up @@ -95,6 +95,28 @@ def test_docuent_self_or_methods
refute @c1.document_self_or_methods
end

def test_documented_eh
cm = RDoc::ClassModule.new 'C'

refute cm.documented?

cm.add_comment 'hi', @top_level

assert cm.documented?

cm.comment.replace ''

assert cm.documented?

cm.comment_location.clear

refute cm.documented?

cm.document_self = nil # notify :nodoc:

assert cm.documented?
end

def test_each_ancestor
assert_equal [@parent], @child.each_ancestor.to_a
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_rdoc_store.rb
Expand Up @@ -708,7 +708,7 @@ def test_save_class_merge

document = @RM::Document.new inner

assert_equal document, s.load_class('Object').comment
assert_equal document, s.load_class('Object').comment_location
end

# This is a functional test
Expand Down

0 comments on commit 9a4d076

Please sign in to comment.