Skip to content

Commit 6de02eb

Browse files
committed
Simplify sidebar ToC's generation logic
1 parent a97022a commit 6de02eb

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

lib/rdoc/generator/darkfish.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def generate_index
323323
# suppress 1.9.3 warning
324324
here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
325325
# some partials rely on the presence of current variable to render
326-
here.local_variable_set(:current, @main_page) if @main_page
326+
here.local_variable_set(:current, @main_page)
327327
here
328328
end
329329
rescue => e
@@ -808,6 +808,17 @@ def excerpt(comment)
808808
extracted_text[0...150].gsub(/\n/, " ").squeeze(" ")
809809
end
810810

811+
def generate_table_from_the_current_object(current)
812+
return '' if current.nil?
813+
comment =
814+
if current.respond_to? :comment_location then
815+
current.comment_location
816+
else
817+
current.comment
818+
end
819+
current.parse(comment).table_of_contents.dup
820+
end
821+
811822
def generate_ancestor_list(ancestors, klass)
812823
return '' if ancestors.empty?
813824

lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
<%- comment = if current.respond_to? :comment_location then
2-
current.comment_location
3-
else
4-
current.comment
5-
end
6-
table = current.parse(comment).table_of_contents.dup
7-
8-
if table.length > 1 then %>
1+
<%- table = generate_table_from_the_current_object(current) -%>
2+
<%- if table.length > 1 %>
93
<div class="nav-section">
104
<h3>Table of Contents</h3>
115

0 commit comments

Comments
 (0)