diff --git a/lib/puppet-strings.rb b/lib/puppet-strings.rb index 0a61787..f2cbdfc 100644 --- a/lib/puppet-strings.rb +++ b/lib/puppet-strings.rb @@ -18,6 +18,9 @@ module PuppetStrings # @option options [Array] :yard_args The arguments to pass to yard. # @return [void] def self.generate(search_patterns = DEFAULT_SEARCH_PATTERNS, options = {}) + require 'puppet-strings/yard' + PuppetStrings::Yard.setup! + # Format the arguments to YARD args = ['doc'] args << '--debug' if options[:debug] @@ -51,6 +54,9 @@ module PuppetStrings # Runs the YARD documentation server. # @param [Array] args The arguments to YARD. def self.run_server(*args) + require 'puppet-strings/yard' + PuppetStrings::Yard.setup! + YARD::CLI::Server.run(*args) end end diff --git a/lib/puppet-strings/yard.rb b/lib/puppet-strings/yard.rb new file mode 100644 index 0000000..38f2415 --- /dev/null +++ b/lib/puppet-strings/yard.rb @@ -0,0 +1,54 @@ +require 'yard' + +# Module for YARD related functionality. +module PuppetStrings::Yard + require 'puppet-strings/yard/code_objects' + require 'puppet-strings/yard/handlers' + require 'puppet-strings/yard/tags' + require 'puppet-strings/yard/parsers' + + # Sets up YARD for use with puppet-strings. + # @return [void] + def self.setup! + # Register the template path + YARD::Templates::Engine.register_template_path(File.join(File.dirname(__FILE__), 'yard', 'templates')) + end +end + +# Monkey patch YARD::CLI::Yardoc#all_objects to return our custom code objects. +# @private +class YARD::CLI::Yardoc + def all_objects + YARD::Registry.all( + :root, + :module, + :class + ) + end +end + +# Monkey patch the stats object to return statistics for our objects. +# This is the recommended way to add custom stats. +# @private +class YARD::CLI::Stats + def output(name, data, undoc = nil) + # Monkey patch output to accommodate our larger header widths + @total += data if data.is_a?(Integer) && undoc + @undocumented += undoc if undoc.is_a?(Integer) + if undoc + data = ('%5s (% 5d undocumented)' % [data, undoc]) + else + data = '%5s' % data + end + log.puts('%-21s %s' % [name + ':', data]) + end + + # This differs from the YARD implementation in that it considers + # a docstring without text but with tags to be undocumented. + def type_statistics_all(type) + objs = all_objects.select {|m| m.type == type } + undoc = objs.find_all {|m| m.docstring.all.empty? } + @undoc_list |= undoc if @undoc_list + [objs.size, undoc.size] + end +end diff --git a/lib/puppet-strings/yard/code_objects.rb b/lib/puppet-strings/yard/code_objects.rb new file mode 100644 index 0000000..d346ef7 --- /dev/null +++ b/lib/puppet-strings/yard/code_objects.rb @@ -0,0 +1,3 @@ +# The module for custom YARD code objects. +module PuppetStrings::Yard::CodeObjects +end diff --git a/lib/puppet-strings/yard/handlers.rb b/lib/puppet-strings/yard/handlers.rb new file mode 100644 index 0000000..e502343 --- /dev/null +++ b/lib/puppet-strings/yard/handlers.rb @@ -0,0 +1,3 @@ +# The module for custom YARD handlers. +module PuppetStrings::Yard::Handlers +end diff --git a/lib/puppet-strings/yard/parsers.rb b/lib/puppet-strings/yard/parsers.rb new file mode 100644 index 0000000..3d049d0 --- /dev/null +++ b/lib/puppet-strings/yard/parsers.rb @@ -0,0 +1,3 @@ +# The module for custom YARD parsers. +module PuppetStrings::Yard::Parsers +end diff --git a/lib/puppet-strings/yard/tags.rb b/lib/puppet-strings/yard/tags.rb new file mode 100644 index 0000000..8bd1d4b --- /dev/null +++ b/lib/puppet-strings/yard/tags.rb @@ -0,0 +1,3 @@ +# The module for custom YARD tags. +module PuppetStrings::Yard::Tags +end