File tree 3 files changed +49
-0
lines changed
rdoc/generator/template/rails
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1
1
< div id ="content ">
2
2
<% unless ( description = context . description ) . empty? %>
3
+ <% unless context . comment_title %>
4
+ < h1 > <%= context . title %> </ h1 >
5
+ <% end %>
3
6
< div class ="description ">
4
7
<%= description %>
5
8
</ div >
Original file line number Diff line number Diff line change @@ -19,6 +19,16 @@ class RDoc::Options
19
19
attr_accessor :search_index
20
20
end
21
21
22
+ module RDoc ::Generator ::Markup
23
+ def comment_title
24
+ @comment_title ||= @comment . to_s . match ( /\A [=#] (.*)$/ ) { |match | match [ 1 ] }
25
+ end
26
+
27
+ def title
28
+ comment_title || full_name
29
+ end
30
+ end
31
+
22
32
class RDoc ::Generator ::SDoc
23
33
RDoc ::RDoc . add_generator self
24
34
Original file line number Diff line number Diff line change
1
+ require File . join ( File . dirname ( __FILE__ ) , '/spec_helper' )
2
+
3
+ describe RDoc ::Generator ::Markup do
4
+ before :each do
5
+ @module = RDoc ::NormalModule . new 'Example::SomeClass'
6
+ end
7
+
8
+ describe "#comment_title" do
9
+ it "should parse the h1 title from the comment if present" do
10
+ @module . comment = RDoc ::Comment . new '= Some Title'
11
+ _ ( @module . comment_title ) . must_equal 'Some Title'
12
+ end
13
+
14
+ it "should parse the markdown h1 title from the comment if present" do
15
+ @module . comment = RDoc ::Comment . new '# Markdown Title'
16
+ _ ( @module . comment_title ) . must_equal 'Markdown Title'
17
+ end
18
+
19
+ it "should ignore lower level titles" do
20
+ @module . comment = RDoc ::Comment . new '== Some Title'
21
+ _ ( @module . comment_title ) . must_equal nil
22
+ end
23
+ end
24
+
25
+ describe "#title" do
26
+ it "should parse the h1 title from the comment if present" do
27
+ @module . comment = RDoc ::Comment . new '= Some Title'
28
+ _ ( @module . title ) . must_equal 'Some Title'
29
+ end
30
+
31
+ it "should fallback to the full_name" do
32
+ @module . comment = RDoc ::Comment . new 'Some comment without title'
33
+ _ ( @module . title ) . must_equal "Example::SomeClass"
34
+ end
35
+ end
36
+ end
You can’t perform that action at this time.
0 commit comments