From 798cd5b8162ff1ec2c837c1b5fa3cfd86491753e Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Mon, 10 Aug 2015 10:16:26 -0700 Subject: [PATCH] (PDOC-35) Add a directive for puppet parameters * Print yard documentation statistics for providers * Define a directive which takes a type and a name --- lib/puppet/face/strings.rb | 4 ++++ lib/puppet_x/puppetlabs/strings.rb | 4 ++++ lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb | 4 ++++ lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb | 9 +++++++++ .../strings/yard/templates/default/provider/setup.rb | 5 +---- 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb diff --git a/lib/puppet/face/strings.rb b/lib/puppet/face/strings.rb index 01603aa..d9f9661 100644 --- a/lib/puppet/face/strings.rb +++ b/lib/puppet/face/strings.rb @@ -1,4 +1,5 @@ require 'puppet/face' +require 'puppet_x/puppetlabs/strings/yard/tags/directives' Puppet::Face.define(:strings, '0.0.1') do summary "Generate Puppet documentation with YARD." @@ -55,6 +56,9 @@ Puppet::Face.define(:strings, '0.0.1') do # all over the terminal. This should definitely not be in real code, but # it's very handy for debugging with pry #class YARD::Logger; def progress(*args); end; end + YARD::Tags::Library.define_directive("puppet.provider.param", + :with_types_and_name, + PuppetX::PuppetLabs::Strings::YARD::Tags::PuppetProviderParameterDirective) yardoc_actions.generate_documentation(*yard_args) diff --git a/lib/puppet_x/puppetlabs/strings.rb b/lib/puppet_x/puppetlabs/strings.rb index 619bf0d..e857dc5 100644 --- a/lib/puppet_x/puppetlabs/strings.rb +++ b/lib/puppet_x/puppetlabs/strings.rb @@ -21,6 +21,10 @@ module PuppetX::PuppetLabs require 'puppet_x/puppetlabs/strings/yard/monkey_patches' require 'puppet_x/puppetlabs/strings/yard/parser' + module Tags + require 'puppet_x/puppetlabs/strings/yard/tags/directives' + end + # This submodule contains code objects which are used to represent relevant # aspects of puppet code in YARD's Registry module CodeObjects diff --git a/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb b/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb index 6dd5903..781dca6 100644 --- a/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb +++ b/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb @@ -18,6 +18,10 @@ class YARD::CLI::Stats def stats_for_definedtypes output 'Puppet Types', *type_statistics(:definedtype) end + + def stats_for_providers + output 'Puppet Providers', *type_statistics(:provider) + end end class YARD::Logger diff --git a/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb b/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb new file mode 100644 index 0000000..531af50 --- /dev/null +++ b/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb @@ -0,0 +1,9 @@ +require 'puppet_x/puppetlabs/strings/yard/core_ext/yard' +# Creates a new code object based on the directive +class PuppetX::PuppetLabs::Strings::YARD::Tags::PuppetProviderParameterDirective < YARD::Tags::Directive + def call + return if object.nil? + object.parameters << ([tag.text] + tag.types) + object.parameter_details << {:name => tag.name, :desc => tag.text, :exists? => true, :provider => true} + end +end diff --git a/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb b/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb index 0b249f3..3878183 100644 --- a/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb +++ b/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb @@ -11,11 +11,8 @@ def init end def parameter_details - params = object.parameter_details.map { |h| h[:name] } - - @param_details = [] - @param_details = object.parameter_details + @param_details = object.parameter_details.each { |h| h[:desc] = htmlify(h[:desc]) } @template_helper.check_parameters_match_docs object erb(:parameter_details)