From d226d08ddb39ea3368e71b19345c01ff08b8d128 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Tue, 27 May 2014 19:23:34 -0700 Subject: [PATCH] List subclasses for each host class Basically a straight port of the logic from the YARD template for Ruby classes. --- .../templates/default/hostclass/html/setup.rb | 4 ---- .../default/hostclass/html/subclasses.erb | 4 ++++ .../yard/templates/default/hostclass/setup.rb | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 lib/puppetx/yardoc/yard/templates/default/hostclass/html/subclasses.erb create mode 100644 lib/puppetx/yardoc/yard/templates/default/hostclass/setup.rb diff --git a/lib/puppetx/yardoc/yard/templates/default/hostclass/html/setup.rb b/lib/puppetx/yardoc/yard/templates/default/hostclass/html/setup.rb index 1e51893..91e114a 100644 --- a/lib/puppetx/yardoc/yard/templates/default/hostclass/html/setup.rb +++ b/lib/puppetx/yardoc/yard/templates/default/hostclass/html/setup.rb @@ -1,5 +1 @@ include T('default/module/html') - -def init - sections :header, :box_info, :pre_docstring, T('docstring'), :children -end diff --git a/lib/puppetx/yardoc/yard/templates/default/hostclass/html/subclasses.erb b/lib/puppetx/yardoc/yard/templates/default/hostclass/html/subclasses.erb new file mode 100644 index 0000000..3948080 --- /dev/null +++ b/lib/puppetx/yardoc/yard/templates/default/hostclass/html/subclasses.erb @@ -0,0 +1,4 @@ +
+

Direct Known Subclasses

+

<%= @subclasses.map {|child| linkify(child, child.path) }.join(", ") %>

+
diff --git a/lib/puppetx/yardoc/yard/templates/default/hostclass/setup.rb b/lib/puppetx/yardoc/yard/templates/default/hostclass/setup.rb new file mode 100644 index 0000000..5e7ccd1 --- /dev/null +++ b/lib/puppetx/yardoc/yard/templates/default/hostclass/setup.rb @@ -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