diff --git a/lib/rdoc/generator/markup.rb b/lib/rdoc/generator/markup.rb index 5bc0c5849a..d6a56adf97 100644 --- a/lib/rdoc/generator/markup.rb +++ b/lib/rdoc/generator/markup.rb @@ -83,6 +83,23 @@ class RDoc::CodeObject end +class RDoc::AnyMethod + + ## + # Creates an HTML link to the superclass method called by this method. + + def superclass_method_link + target = superclass_method + return unless target + + html_formatter = formatter + name = target.full_name + + html_formatter.link name, html_formatter.convert_string(name) + end + +end + class RDoc::MethodAttr ## diff --git a/lib/rdoc/generator/template/aliki/class.rhtml b/lib/rdoc/generator/template/aliki/class.rhtml index 6cb99ee214..cfef74d1a6 100644 --- a/lib/rdoc/generator/template/aliki/class.rhtml +++ b/lib/rdoc/generator/template/aliki/class.rhtml @@ -185,10 +185,7 @@ <%- if method.calls_super %>
Calls superclass method - <%= - method.superclass_method ? - method.formatter.link(method.superclass_method.full_name, method.superclass_method.full_name) : nil - %> + <%= method.superclass_method_link %>
<%- end %> diff --git a/lib/rdoc/generator/template/darkfish/class.rhtml b/lib/rdoc/generator/template/darkfish/class.rhtml index 39b3070175..8e7fdbf4a5 100644 --- a/lib/rdoc/generator/template/darkfish/class.rhtml +++ b/lib/rdoc/generator/template/darkfish/class.rhtml @@ -185,10 +185,7 @@ <%- if method.calls_super %>
Calls superclass method - <%= - method.superclass_method ? - method.formatter.link(method.superclass_method.full_name, method.superclass_method.full_name) : nil - %> + <%= method.superclass_method_link %>
<%- end %> diff --git a/test/rdoc/generator/markup_test.rb b/test/rdoc/generator/markup_test.rb index e78f1a4265..ab3ff2eabd 100644 --- a/test/rdoc/generator/markup_test.rb +++ b/test/rdoc/generator/markup_test.rb @@ -48,10 +48,45 @@ def test_formatter assert_same self, formatter.context end + def test_superclass_method_link + method = method_calling_super 'foo' + + expected = 'Outer#foo' + assert_equal expected, method.superclass_method_link + + assert_nil RDoc::AnyMethod.new('bar').superclass_method_link + end + + def test_superclass_method_link_escapes_name + method = method_calling_super '<<' + + link = method.superclass_method_link + + expected = 'Outer#<<' + assert_equal expected, link + refute_match %r{Outer#<<}, link + end + attr_reader :path def find_symbol(name) @symbols[name] end + def method_calling_super(name) + top_level = @store.add_file 'superclass_method_link.rb' + parent_method = RDoc::AnyMethod.new name + + method = RDoc::AnyMethod.new name + method.calls_super = true + + parent = top_level.add_class RDoc::NormalClass, 'Outer' + parent.add_method parent_method + + child = top_level.add_class RDoc::NormalClass, 'Inner', parent.full_name + child.add_method method + + method + end + end