Move parser functions into a PuppetNamespace

Seperate Puppet parser functions out into a PuppetNamespace so they are no
longer listed with the Ruby methods.
This commit is contained in:
Charlie Sharpsteen 2014-06-12 21:21:11 -07:00
parent 32d69848e1
commit 1b8cc98118
7 changed files with 50 additions and 5 deletions

View File

@ -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
#

View File

@ -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

View File

@ -0,0 +1,8 @@
<li>
<a class='toggle'></a>
<%= link_object(P(:root, 'ParserFunctions'), 'Parser Functions', nil, false) %>
<small class='search_info'>ParserFunctions</small>
</li>
<ul>
<%= namespace_list(:root => P(:root,'ParserFunctions'), :namespace_types => [:puppetnamespace, :method]) %>
</ul>

View File

@ -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 = {})

View File

@ -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

View File

@ -0,0 +1 @@
include T('default/module/html')

View File

@ -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