diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb
index 08f2b85e3b..cfd46b5ed4 100644
--- a/lib/rdoc/generator/darkfish.rb
+++ b/lib/rdoc/generator/darkfish.rb
@@ -316,11 +316,14 @@ def generate_index
asset_rel_prefix = rel_prefix + @asset_rel_path
@title = @options.title
+ @main_page = @files.find { |f| f.full_name == @options.main_page }
render_template template_file, out_file do |io|
here = binding
# suppress 1.9.3 warning
here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
+ # some partials rely on the presence of current variable to render
+ here.local_variable_set(:current, @main_page) if @main_page
here
end
rescue => e
diff --git a/lib/rdoc/generator/template/darkfish/index.rhtml b/lib/rdoc/generator/template/darkfish/index.rhtml
index a5c0dd54da..beaab9570f 100644
--- a/lib/rdoc/generator/template/darkfish/index.rhtml
+++ b/lib/rdoc/generator/template/darkfish/index.rhtml
@@ -7,6 +7,7 @@
<%= render '_sidebar_search.rhtml' %>
+ <%= render '_sidebar_table_of_contents.rhtml' if defined?(current) %>
<%= render '_sidebar_pages.rhtml' %>
<%= render '_sidebar_classes.rhtml' %>
@@ -14,10 +15,9 @@
-<%- if @options.main_page and
- main_page = @files.find { |f| f.full_name == @options.main_page } then %>
-<%= main_page.description %>
+<%- if @main_page %>
+ <%= @main_page.description %>
<%- else -%>
-This is the API documentation for <%= h @title %>.
+
This is the API documentation for <%= h @title %>.
<%- end -%>
diff --git a/test/rdoc/test_rdoc_generator_darkfish.rb b/test/rdoc/test_rdoc_generator_darkfish.rb
index 0a9be7e4ee..cedc876b4e 100644
--- a/test/rdoc/test_rdoc_generator_darkfish.rb
+++ b/test/rdoc/test_rdoc_generator_darkfish.rb
@@ -134,6 +134,88 @@ def test_generate
)
end
+ def test_generate_index_with_main_page
+ top_level = @store.add_file 'file.rb'
+ top_level.comment = <<~RDOC
+ = Heading 1
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
+ == Heading 1.1
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+ === Heading 1.1.1
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
+ ==== Heading 1.1.1.1
+ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
+ == Heading 1.2
+ cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
+ == Heading 1.3
+ non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ === Heading 1.3.1
+ etc etc...
+ RDOC
+
+ @options.main_page = 'file.rb'
+ @options.title = 'My awesome Ruby project'
+
+ @g.generate
+
+ assert_file 'index.html'
+ assert_file 'table_of_contents.html'
+ assert_file 'js/search_index.js'
+
+ assert_hard_link 'css/rdoc.css'
+ assert_hard_link 'css/fonts.css'
+
+ assert_hard_link 'fonts/SourceCodePro-Bold.ttf'
+ assert_hard_link 'fonts/SourceCodePro-Regular.ttf'
+
+ index_html = File.binread('index.html')
+
+ assert_include index_html, "
Table of Contents
"
+ assert_include index_html, 'Heading 1'
+ # When there's a main page, the default description should not be shown
+ assert_not_include index_html, 'This is the API documentation for My awesome Ruby project.'
+ end
+
+ def test_generate_index_without_main_page
+ top_level = @store.add_file 'file.rb'
+ top_level.comment = <<~RDOC
+ = Heading 1
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
+ == Heading 1.1
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
+ === Heading 1.1.1
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
+ ==== Heading 1.1.1.1
+ consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
+ == Heading 1.2
+ cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
+ == Heading 1.3
+ non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+ === Heading 1.3.1
+ etc etc...
+ RDOC
+
+ @options.title = 'My awesome Ruby project'
+
+ @g.generate
+
+ assert_file 'index.html'
+ assert_file 'table_of_contents.html'
+ assert_file 'js/search_index.js'
+
+ assert_hard_link 'css/rdoc.css'
+ assert_hard_link 'css/fonts.css'
+
+ assert_hard_link 'fonts/SourceCodePro-Bold.ttf'
+ assert_hard_link 'fonts/SourceCodePro-Regular.ttf'
+
+ index_html = File.binread('index.html')
+
+ # If there is no main page, the index page should not have a table of contents
+ assert_not_include index_html, "Table of Contents
"
+ assert_include index_html, 'This is the API documentation for My awesome Ruby project.'
+ end
+
def test_generate_page
@store.add_file 'outer.rdoc', parser: RDoc::Parser::Simple
@store.add_file 'outer/inner.rdoc', parser: RDoc::Parser::Simple