From d8bc2f3dce39794944617710b68f15115fed1508 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Mon, 26 May 2014 22:36:22 -0700 Subject: [PATCH] Display inheritance relationships for host classes --- .../yard/code_objects/host_class_object.rb | 4 ++++ .../yardoc/yard/handlers/host_class_handler.rb | 10 +++++++++- .../default/hostclass/html/box_info.erb | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 lib/puppetx/yardoc/yard/templates/default/hostclass/html/box_info.erb diff --git a/lib/puppetx/yardoc/yard/code_objects/host_class_object.rb b/lib/puppetx/yardoc/yard/code_objects/host_class_object.rb index 28b6599..d3abcf6 100644 --- a/lib/puppetx/yardoc/yard/code_objects/host_class_object.rb +++ b/lib/puppetx/yardoc/yard/code_objects/host_class_object.rb @@ -5,6 +5,10 @@ require_relative '../../../yardoc' module Puppetx::Yardoc::YARD::CodeObjects class HostClassObject < YARD::CodeObjects::NamespaceObject + # The {HostClassObject} that this class inherits from, if any. + # @return [HostClassObject, Proxy, nil] + attr_accessor :parent_class + # The `YARD::Codeobjects::Base` class pulls a bunch of shenanigans to # insert proxy namespaces. Unfortunately, said shenanigans pick up on the # `::` in Puppet names and start to mangle things based on rules for the diff --git a/lib/puppetx/yardoc/yard/handlers/host_class_handler.rb b/lib/puppetx/yardoc/yard/handlers/host_class_handler.rb index 5c32916..11be5d5 100644 --- a/lib/puppetx/yardoc/yard/handlers/host_class_handler.rb +++ b/lib/puppetx/yardoc/yard/handlers/host_class_handler.rb @@ -5,7 +5,15 @@ module Puppetx::Yardoc::YARD::Handlers handles HostClassDefinition process do - register HostClassObject.new(:root, statement.pops_obj.name) + obj = HostClassObject.new(:root, statement.pops_obj.name) + + statement.pops_obj.tap do |o| + if o.parent_class + obj.parent_class = P(:root, o.parent_class) + end + end + + register obj end end end diff --git a/lib/puppetx/yardoc/yard/templates/default/hostclass/html/box_info.erb b/lib/puppetx/yardoc/yard/templates/default/hostclass/html/box_info.erb new file mode 100644 index 0000000..0a7ce34 --- /dev/null +++ b/lib/puppetx/yardoc/yard/templates/default/hostclass/html/box_info.erb @@ -0,0 +1,17 @@ +<% n = 1 %> +
+ <% if object.parent_class %> +
Inherits:
+
+ <%= linkify object.parent_class %> + <%# TODO: Add inheritance tree. %> +
+ <% n = 2 %> + <% end %> + <% unless object.root? %> +
Defined in:
+
<%= erb(:defines) %>
+ <% end %> +
+
+