" if @context.comment.empty? %> - <%= full_name @context %> + <%= full_name_for @context %> <%= "
" if @context.comment.empty? %>#{named.split(%r"(?<=./|.::)").map { |part| h part }.join("")}
"
end
- def short_name(named)
+ def short_name_for(named)
named = named.name if named.is_a?(RDoc::CodeObject)
"#{h named}
"
end
+ def description_for(rdoc_object)
+ if rdoc_object.comment && !rdoc_object.comment.empty?
+ %(Bar
", rdoc_module)).
must_equal %(Bar
)
@@ -183,7 +183,7 @@ module Foo; module Bar; end
module Foo; class Bar; end; end
RUBY
- _(@helpers.link_to_if(false, rdoc_module, "url")).must_equal @helpers.full_name(rdoc_module)
+ _(@helpers.link_to_if(false, rdoc_module, "url")).must_equal @helpers.full_name_for(rdoc_module)
end
end
@@ -233,23 +233,23 @@ module Foo; def <<(*); end; end
end
end
- describe "#full_name" do
+ describe "#full_name_for" do
it "wraps name in " do
- _(@helpers.full_name("Foo")).must_equal "Foo
"
+ _(@helpers.full_name_for("Foo")).must_equal "Foo
"
end
it "inserts word-break opportunities into module names" do
- _(@helpers.full_name("Foo::Bar::Qux")).must_equal "Foo::Bar::Qux
"
- _(@helpers.full_name("::Foo::Bar::Qux")).must_equal "::Foo::Bar::Qux
"
+ _(@helpers.full_name_for("Foo::Bar::Qux")).must_equal "Foo::Bar::Qux
"
+ _(@helpers.full_name_for("::Foo::Bar::Qux")).must_equal "::Foo::Bar::Qux
"
end
it "inserts word-break opportunities into file paths" do
- _(@helpers.full_name("path/to/file.rb")).must_equal "path/to/file.rb
"
- _(@helpers.full_name("/path/to/file.rb")).must_equal "/path/to/file.rb
"
+ _(@helpers.full_name_for("path/to/file.rb")).must_equal "path/to/file.rb
"
+ _(@helpers.full_name_for("/path/to/file.rb")).must_equal "/path/to/file.rb
"
end
it "escapes name parts" do
- _(@helpers.full_name("ruby&rails/file.rb")).must_equal "ruby&rails/file.rb
"
+ _(@helpers.full_name_for("ruby&rails/file.rb")).must_equal "ruby&rails/file.rb
"
end
it "uses RDoc::CodeObject#full_name when argument is an RDoc::CodeObject" do
@@ -257,17 +257,17 @@ module Foo; def <<(*); end; end
module Foo; module Bar; class Qux; end; end; end
RUBY
- _(@helpers.full_name(rdoc_module)).must_equal "Foo::Bar::Qux
"
+ _(@helpers.full_name_for(rdoc_module)).must_equal "Foo::Bar::Qux
"
end
end
- describe "#short_name" do
+ describe "#short_name_for" do
it "wraps name in " do
- _(@helpers.short_name("foo")).must_equal "foo
"
+ _(@helpers.short_name_for("foo")).must_equal "foo
"
end
it "escapes the name" do
- _(@helpers.short_name("<=>")).must_equal "<=>
"
+ _(@helpers.short_name_for("<=>")).must_equal "<=>
"
end
it "uses RDoc::CodeObject#name when argument is an RDoc::CodeObject" do
@@ -275,7 +275,27 @@ module Foo; module Bar; class Qux; end; end; end
module Foo; def bar; end; end
RUBY
- _(@helpers.short_name(rdoc_method)).must_equal "bar
"
+ _(@helpers.short_name_for(rdoc_method)).must_equal "bar
"
+ end
+ end
+
+ describe "#description_for" do
+ it "returns RDoc::CodeObject#description wrapped in div.description" do
+ rdoc_module = rdoc_top_level_for(<<~RUBY).find_module_named("Foo")
+ # This is +Foo+.
+ module Foo; end
+ RUBY
+
+ _(@helpers.description_for(rdoc_module)).
+ must_equal %(\nThis is Foo
.
\n)
+ end
+
+ it "returns nil when RDoc::CodeObject#description is empty" do
+ rdoc_module = rdoc_top_level_for(<<~RUBY).find_module_named("Foo")
+ module Foo; end
+ RUBY
+
+ _(@helpers.description_for(rdoc_module)).must_be_nil
end
end