diff --git a/lib/rdoc/generator/template/rails/_context.rhtml b/lib/rdoc/generator/template/rails/_context.rhtml index 748ba2c5..13f868ec 100644 --- a/lib/rdoc/generator/template/rails/_context.rhtml +++ b/lib/rdoc/generator/template/rails/_context.rhtml @@ -1,5 +1,8 @@
<% unless (description = context.description).empty? %> + <% unless context.comment_title %> +

<%= context.title %>

+ <% end %>
<%= description %>
diff --git a/lib/sdoc/generator.rb b/lib/sdoc/generator.rb index 930bf687..ec4957fe 100644 --- a/lib/sdoc/generator.rb +++ b/lib/sdoc/generator.rb @@ -19,6 +19,16 @@ class RDoc::Options attr_accessor :search_index end +module RDoc::Generator::Markup + def comment_title + @comment_title ||= @comment.to_s.match(/\A[=#] (.*)$/) {|match| match[1] } + end + + def title + comment_title || full_name + end +end + class RDoc::Generator::SDoc RDoc::RDoc.add_generator self diff --git a/spec/rdoc_generator_markup_spec.rb b/spec/rdoc_generator_markup_spec.rb new file mode 100644 index 00000000..2b2a2eb0 --- /dev/null +++ b/spec/rdoc_generator_markup_spec.rb @@ -0,0 +1,36 @@ +require File.join(File.dirname(__FILE__), '/spec_helper') + +describe RDoc::Generator::Markup do + before :each do + @module = RDoc::NormalModule.new 'Example::SomeClass' + end + + describe "#comment_title" do + it "should parse the h1 title from the comment if present" do + @module.comment = RDoc::Comment.new '= Some Title' + _(@module.comment_title).must_equal 'Some Title' + end + + it "should parse the markdown h1 title from the comment if present" do + @module.comment = RDoc::Comment.new '# Markdown Title' + _(@module.comment_title).must_equal 'Markdown Title' + end + + it "should ignore lower level titles" do + @module.comment = RDoc::Comment.new '== Some Title' + _(@module.comment_title).must_equal nil + end + end + + describe "#title" do + it "should parse the h1 title from the comment if present" do + @module.comment = RDoc::Comment.new '= Some Title' + _(@module.title).must_equal 'Some Title' + end + + it "should fallback to the full_name" do + @module.comment = RDoc::Comment.new 'Some comment without title' + _(@module.title).must_equal "Example::SomeClass" + end + end +end