List subclasses for each host class

Basically a straight port of the logic from the YARD template for Ruby classes.
This commit is contained in:
Charlie Sharpsteen 2014-05-27 19:23:34 -07:00
parent 787fca8ebc
commit d226d08ddb
3 changed files with 23 additions and 4 deletions

View File

@ -1,5 +1 @@
include T('default/module/html')
def init
sections :header, :box_info, :pre_docstring, T('docstring'), :children
end

View File

@ -0,0 +1,4 @@
<div id="subclasses">
<h2>Direct Known Subclasses</h2>
<p class="children"><%= @subclasses.map {|child| linkify(child, child.path) }.join(", ") %></p>
</div>

View File

@ -0,0 +1,19 @@
include T('default/module')
def init
sections :header, :box_info, :pre_docstring, T('docstring'), :subclasses
end
def subclasses
# The naming is a bit weird because Ruby classes use `globals.subclasses`.
unless globals.hostsubclasses
globals.hostsubclasses = {}
list = run_verifier Registry.all(:hostclass)
list.each {|o| (globals.hostsubclasses[o.parent_class.path] ||= []) << o if o.parent_class }
end
@subclasses = globals.hostsubclasses[object.path]
return if @subclasses.nil? || @subclasses.empty?
erb(:subclasses)
end