Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/rdoc/generator/markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
5 changes: 1 addition & 4 deletions lib/rdoc/generator/template/aliki/class.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@
<%- if method.calls_super %>
<div class="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 %>
</div>
<%- end %>
</div>
Expand Down
5 changes: 1 addition & 4 deletions lib/rdoc/generator/template/darkfish/class.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@
<%- if method.calls_super %>
<div class="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 %>
</div>
<%- end %>
</div>
Expand Down
35 changes: 35 additions & 0 deletions test/rdoc/generator/markup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,45 @@ def test_formatter
assert_same self, formatter.context
end

def test_superclass_method_link
method = method_calling_super 'foo'

expected = '<a href="Outer.html#method-i-foo"><code>Outer#foo</code></a>'
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 = '<a href="Outer.html#method-i-3C-3C"><code>Outer#&lt;&lt;</code></a>'
assert_equal expected, link
refute_match %r{<code>Outer#<<</code>}, 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

Comment thread
st0012 marked this conversation as resolved.
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
Loading