From 1b8cc98118acfd185ce1e3b711c3ae5adc2cfb93 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Thu, 12 Jun 2014 21:21:11 -0700 Subject: [PATCH] Move parser functions into a PuppetNamespace Seperate Puppet parser functions out into a PuppetNamespace so they are no longer listed with the Ruby methods. --- .../yard/handlers/parser_function_handler.rb | 20 +++++++++++++++++-- lib/puppetx/yardoc/yard/monkey_patches.rb | 2 +- .../fulldoc/html/full_list_puppet_plugin.erb | 8 ++++++++ .../templates/default/fulldoc/html/setup.rb | 12 +++++++++++ .../templates/default/layout/html/setup.rb | 5 +++-- .../default/puppetnamespace/html/setup.rb | 1 + .../default/puppetnamespace/setup.rb | 7 +++++++ 7 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 lib/puppetx/yardoc/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb create mode 100644 lib/puppetx/yardoc/yard/templates/default/puppetnamespace/html/setup.rb create mode 100644 lib/puppetx/yardoc/yard/templates/default/puppetnamespace/setup.rb diff --git a/lib/puppetx/yardoc/yard/handlers/parser_function_handler.rb b/lib/puppetx/yardoc/yard/handlers/parser_function_handler.rb index 39ca715..aefe9d0 100644 --- a/lib/puppetx/yardoc/yard/handlers/parser_function_handler.rb +++ b/lib/puppetx/yardoc/yard/handlers/parser_function_handler.rb @@ -1,16 +1,18 @@ # This utility library contains some tools for working with Puppet docstrings. require 'puppet/util/docs' -require_relative 'base' +require_relative '../code_objects' module Puppetx::Yardoc::YARD::Handlers class ParserFunctionHandler < YARD::Handlers::Ruby::Base + include Puppetx::Yardoc::YARD::CodeObjects + handles method_call(:newfunction) process do name, options = process_parameters - obj = MethodObject.new(:root, name) + obj = MethodObject.new(function_namespace, name) register obj if options['doc'] @@ -26,6 +28,20 @@ module Puppetx::Yardoc::YARD::Handlers private + # Returns a {PuppetNamespaceObject} for holding functions. Creates this + # object if necessary. + # + # @return [PuppetNamespaceObject] + def function_namespace + # NOTE: This tricky. If there is ever a Ruby class or module with the + # name ::ParserFunctions, then there will be a clash. Hopefully the name + # is sufficiently uncommon. + obj = P(:root, 'ParserFunctions') + ::YARD::Registry.register PuppetNamespaceObject.new(:root, 'ParserFunctions') if obj.is_a?(Proxy) + + obj + end + # NOTE: The following methods duplicate functionality from # Puppet::Util::Reference and Puppet::Parser::Functions.functiondocs # diff --git a/lib/puppetx/yardoc/yard/monkey_patches.rb b/lib/puppetx/yardoc/yard/monkey_patches.rb index 83163e3..0863b7f 100644 --- a/lib/puppetx/yardoc/yard/monkey_patches.rb +++ b/lib/puppetx/yardoc/yard/monkey_patches.rb @@ -6,7 +6,7 @@ require 'yard' class YARD::CLI::Yardoc def all_objects - YARD::Registry.all(:root, :module, :class, :hostclass, :definedtype) + YARD::Registry.all(:root, :module, :class, :puppetnamespace, :hostclass, :definedtype) end end diff --git a/lib/puppetx/yardoc/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb b/lib/puppetx/yardoc/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb new file mode 100644 index 0000000..91c04b2 --- /dev/null +++ b/lib/puppetx/yardoc/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb @@ -0,0 +1,8 @@ +
  • + + <%= link_object(P(:root, 'ParserFunctions'), 'Parser Functions', nil, false) %> + ParserFunctions +
  • + diff --git a/lib/puppetx/yardoc/yard/templates/default/fulldoc/html/setup.rb b/lib/puppetx/yardoc/yard/templates/default/fulldoc/html/setup.rb index b75486a..69fb957 100644 --- a/lib/puppetx/yardoc/yard/templates/default/fulldoc/html/setup.rb +++ b/lib/puppetx/yardoc/yard/templates/default/fulldoc/html/setup.rb @@ -15,6 +15,18 @@ def generate_puppet_manifest_list generate_list_contents end +def generate_puppet_plugin_list + # NOTE: PuppetNamaspaceObject might eventually be used for more than just a + # container for plugins... + @items = options.objects.select{|o| [:puppetnamespace].include? o.type} if options.objects + @list_title = "Puppet Plugin List" + # This is important. It causes some YARD JavaScript bits to hook in and + # perform the correct formatting. + @list_class = "class" + @list_type = "puppet_plugin" + generate_list_contents +end + # A hacked version of class_list that can be instructed to only display certain # namespace types. This allows us to separate Puppet bits from Ruby bits. def namespace_list(opts = {}) diff --git a/lib/puppetx/yardoc/yard/templates/default/layout/html/setup.rb b/lib/puppetx/yardoc/yard/templates/default/layout/html/setup.rb index 79d3f44..53a1ee0 100644 --- a/lib/puppetx/yardoc/yard/templates/default/layout/html/setup.rb +++ b/lib/puppetx/yardoc/yard/templates/default/layout/html/setup.rb @@ -2,7 +2,7 @@ # @objects_by_letter prevents that. Submit a pull request. def index @objects_by_letter = {} - objects = Registry.all(:class, :module, :hostclass, :definedtype).sort_by {|o| o.name.to_s } + objects = Registry.all(:class, :module, :puppetnamespace, :hostclass, :definedtype).sort_by {|o| o.name.to_s } objects = run_verifier(objects) objects.each {|o| (@objects_by_letter[o.name.to_s[0,1].upcase] ||= []) << o } erb(:index) @@ -10,6 +10,7 @@ end def menu_lists [ - {:type => 'puppet_manifest', :title => 'Puppet Manifests', :search_title => "Puppet Manifest List"} + {:type => 'puppet_manifest', :title => 'Puppet Manifests', :search_title => "Puppet Manifest List"}, + {:type => 'puppet_plugin', :title => 'Puppet Plugins', :search_title => "Puppet Plugin List"} ] + super end diff --git a/lib/puppetx/yardoc/yard/templates/default/puppetnamespace/html/setup.rb b/lib/puppetx/yardoc/yard/templates/default/puppetnamespace/html/setup.rb new file mode 100644 index 0000000..91e114a --- /dev/null +++ b/lib/puppetx/yardoc/yard/templates/default/puppetnamespace/html/setup.rb @@ -0,0 +1 @@ +include T('default/module/html') diff --git a/lib/puppetx/yardoc/yard/templates/default/puppetnamespace/setup.rb b/lib/puppetx/yardoc/yard/templates/default/puppetnamespace/setup.rb new file mode 100644 index 0000000..cf37b36 --- /dev/null +++ b/lib/puppetx/yardoc/yard/templates/default/puppetnamespace/setup.rb @@ -0,0 +1,7 @@ +include T('default/module') + +def init + sections :header, :box_info, :pre_docstring, T('docstring'), + :method_summary, [:item_summary], + :method_details_list, [T('method_details')] +end