puppet-strings 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/lib/puppet-strings/rake_tasks.rb +18 -0
  3. data/lib/puppet/application/strings.rb +4 -0
  4. data/lib/puppet/face/strings.rb +64 -0
  5. data/lib/puppet/feature/rgen.rb +3 -0
  6. data/lib/puppet/feature/yard.rb +3 -0
  7. data/lib/puppet_x/puppetlabs/strings.rb +64 -0
  8. data/lib/puppet_x/puppetlabs/strings/actions.rb +92 -0
  9. data/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb +79 -0
  10. data/lib/puppet_x/puppetlabs/strings/pops/yard_transformer.rb +47 -0
  11. data/lib/puppet_x/puppetlabs/strings/util.rb +65 -0
  12. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/defined_type_object.rb +33 -0
  13. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/host_class_object.rb +22 -0
  14. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/method_object.rb +62 -0
  15. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/provider_object.rb +24 -0
  16. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/puppet_namespace_object.rb +48 -0
  17. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/type_object.rb +42 -0
  18. data/lib/puppet_x/puppetlabs/strings/yard/core_ext/yard.rb +40 -0
  19. data/lib/puppet_x/puppetlabs/strings/yard/handlers/base.rb +13 -0
  20. data/lib/puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler.rb +31 -0
  21. data/lib/puppet_x/puppetlabs/strings/yard/handlers/heredoc_helper.rb +80 -0
  22. data/lib/puppet_x/puppetlabs/strings/yard/handlers/host_class_handler.rb +42 -0
  23. data/lib/puppet_x/puppetlabs/strings/yard/handlers/provider_handler.rb +95 -0
  24. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +54 -0
  25. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb +234 -0
  26. data/lib/puppet_x/puppetlabs/strings/yard/handlers/type_handler.rb +295 -0
  27. data/lib/puppet_x/puppetlabs/strings/yard/json_registry_store.rb +85 -0
  28. data/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb +68 -0
  29. data/lib/puppet_x/puppetlabs/strings/yard/parser.rb +30 -0
  30. data/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb +9 -0
  31. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb +34 -0
  32. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/header.erb +5 -0
  33. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb +6 -0
  34. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/setup.rb +1 -0
  35. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/setup.rb +49 -0
  36. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_class.erb +2 -0
  37. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_manifest.erb +1 -0
  38. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb +21 -0
  39. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +1 -0
  40. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +1 -0
  41. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/setup.rb +82 -0
  42. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/box_info.erb +22 -0
  43. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/setup.rb +1 -0
  44. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/subclasses.erb +4 -0
  45. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb +21 -0
  46. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/html_helper.rb +139 -0
  47. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/layout/html/setup.rb +18 -0
  48. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/html/header.erb +17 -0
  49. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/setup.rb +21 -0
  50. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/text/header.erb +2 -0
  51. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/command_details.erb +8 -0
  52. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/confine_details.erb +10 -0
  53. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/default_details.erb +10 -0
  54. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/docstring.erb +34 -0
  55. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/feature_details.erb +10 -0
  56. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/header.erb +5 -0
  57. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/setup.rb +1 -0
  58. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb +50 -0
  59. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/box_info.erb +11 -0
  60. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/header.erb +5 -0
  61. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_details_list.erb +53 -0
  62. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb +20 -0
  63. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/setup.rb +1 -0
  64. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb +91 -0
  65. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb +192 -0
  66. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/docstring.erb +34 -0
  67. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/header.erb +5 -0
  68. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/parameter_details.erb +12 -0
  69. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/provider_details.erb +10 -0
  70. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/setup.rb +1 -0
  71. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/setup.rb +55 -0
  72. metadata +142 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c5d45a8489fb4754aebb00abe3afb2e85b4e75c
4
+ data.tar.gz: cb074d7c812e50b1a1ffbbe42cafde1a909fb125
5
+ SHA512:
6
+ metadata.gz: 5bc48f92940b474aeddff28cad23338216db262815dec6abfc275aaf39f7c458a9d2a4d160c5131898724310e4ef75fe657f597164b80ede62fd9066d616ec9e
7
+ data.tar.gz: 9ce5ee6be34c1727855f9c1f99bb2049146b3434ab4bc5b51579d698cd15e531b70ae3a466beb77b08599ff0439cbf6c2e077c4556cb3d01448e5dd5adaf0a20
@@ -0,0 +1,18 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'puppet/face'
4
+ require 'puppet_x/puppetlabs/strings/util'
5
+
6
+ namespace :strings do
7
+ desc 'Generate Puppet documentation with YARD.'
8
+ task :generate do
9
+ PuppetX::PuppetLabs::Strings::Util.generate([
10
+ {emit_json: 'strings.json'}
11
+ ])
12
+ end
13
+
14
+ desc 'Serve YARD documentation for modules.'
15
+ task :serve do
16
+ PuppetX::PuppetLabs::Strings::Util.serve
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ require 'puppet/application/face_base'
2
+
3
+ class Puppet::Application::Strings < Puppet::Application::FaceBase
4
+ end
@@ -0,0 +1,64 @@
1
+ require 'puppet/face'
2
+ require 'puppet_x/puppetlabs/strings/yard/tags/directives'
3
+
4
+ Puppet::Face.define(:strings, '0.0.1') do
5
+ summary "Generate Puppet documentation with YARD."
6
+
7
+ # Ensures that the user has the needed features to use puppet strings
8
+ def check_required_features
9
+ unless Puppet.features.yard?
10
+ raise RuntimeError, "The 'yard' gem must be installed in order to use this face."
11
+ end
12
+
13
+ unless Puppet.features.rgen?
14
+ raise RuntimeError, "The 'rgen' gem must be installed in order to use this face."
15
+ end
16
+
17
+ if RUBY_VERSION.match(/^1\.8/)
18
+ raise RuntimeError, "This face requires Ruby 1.9 or greater."
19
+ end
20
+ end
21
+
22
+ action(:yardoc) do
23
+ default
24
+
25
+ option "--emit-json-stdout" do
26
+ summary "Print json representation of the documentation to stdout"
27
+ end
28
+ option "--emit-json FILE" do
29
+ summary "Write json representation of the documentation to FILE"
30
+ end
31
+
32
+ summary "Generate YARD documentation from files."
33
+ arguments "[manifest_file.pp ...]"
34
+
35
+ when_invoked do |*args|
36
+ check_required_features
37
+ require 'puppet_x/puppetlabs/strings/util'
38
+
39
+ PuppetX::PuppetLabs::Strings::Util.generate(args)
40
+
41
+ # Puppet prints the return value of the action. The return value of this
42
+ # action is that of the yardoc_actions invocation, which is the boolean
43
+ # "true". This clutters the statistics yard prints, so instead return the
44
+ # empty string. Note an extra newline will also be printed.
45
+ ""
46
+ end
47
+ end
48
+
49
+ # NOTE: Modeled after the `yard gems` command which builds doc indicies
50
+ # (.yardoc directories) for Ruby Gems. Currently lacks the fine-grained
51
+ # control over where these indicies are created and just dumps them in the
52
+ # module roots.
53
+
54
+ action(:server) do
55
+ summary "Serve YARD documentation for modules."
56
+
57
+ when_invoked do |*args|
58
+ check_required_features
59
+ require 'puppet_x/puppetlabs/strings/util'
60
+
61
+ PuppetX::PuppetLabs::Strings::Util.serve(args)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet/util/feature'
2
+
3
+ Puppet.features.add(:rgen, :libs => ['rgen/metamodel_builder', 'rgen/ecore/ecore'])
@@ -0,0 +1,3 @@
1
+ require 'puppet/util/feature'
2
+
3
+ Puppet.features.add(:yard, :libs => ['yard'])
@@ -0,0 +1,64 @@
1
+ require 'puppet'
2
+ require 'puppet/pops'
3
+ require 'puppet/util/docs'
4
+ require 'yard'
5
+
6
+ module PuppetX
7
+ end
8
+
9
+ # Nothing to see here except forward declarations.
10
+ module PuppetX::PuppetLabs
11
+ module Strings
12
+ # This submodule contains bits that operate on the Pops module produced by
13
+ # the Future parser.
14
+ module Pops
15
+ require 'puppet_x/puppetlabs/strings/pops/yard_statement'
16
+ require 'puppet_x/puppetlabs/strings/pops/yard_transformer'
17
+ end
18
+
19
+ # This submodule contains bits that interface with the YARD plugin system.
20
+ module YARD
21
+ require 'puppet_x/puppetlabs/strings/yard/monkey_patches'
22
+ require 'puppet_x/puppetlabs/strings/yard/parser'
23
+
24
+ module Tags
25
+ require 'puppet_x/puppetlabs/strings/yard/tags/directives'
26
+ end
27
+
28
+ # This submodule contains code objects which are used to represent relevant
29
+ # aspects of puppet code in YARD's Registry
30
+ module CodeObjects
31
+ require 'puppet_x/puppetlabs/strings/yard/code_objects/puppet_namespace_object'
32
+ require 'puppet_x/puppetlabs/strings/yard/code_objects/method_object'
33
+ require 'puppet_x/puppetlabs/strings/yard/code_objects/defined_type_object'
34
+ require 'puppet_x/puppetlabs/strings/yard/code_objects/host_class_object'
35
+ require 'puppet_x/puppetlabs/strings/yard/code_objects/type_object'
36
+ require 'puppet_x/puppetlabs/strings/yard/code_objects/provider_object'
37
+ end
38
+
39
+ # This submodule contains handlers which are used to extract relevant data about
40
+ # puppet code from the ASTs produced by the Ruby and Puppet parsers
41
+ module Handlers
42
+ # This utility library contains some tools for working with Puppet docstrings
43
+ require 'puppet_x/puppetlabs/strings/yard/handlers/base'
44
+ require 'puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler'
45
+ require 'puppet_x/puppetlabs/strings/yard/handlers/host_class_handler'
46
+ require 'puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler'
47
+ require 'puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler'
48
+ require 'puppet_x/puppetlabs/strings/yard/handlers/type_handler'
49
+ require 'puppet_x/puppetlabs/strings/yard/handlers/provider_handler'
50
+ end
51
+
52
+ ::YARD::Parser::SourceParser.register_parser_type(:puppet,
53
+ PuppetX::PuppetLabs::Strings::YARD::PuppetParser,
54
+ ['pp'])
55
+ ::YARD::Handlers::Processor.register_handler_namespace(:puppet,
56
+ PuppetX::PuppetLabs::Strings::YARD::Handlers)
57
+
58
+ # FIXME: Might not be the best idea to have the template code on the Ruby
59
+ # LOAD_PATH as the contents of this directory really aren't library code.
60
+ ::YARD::Templates::Engine.register_template_path(
61
+ File.join(File.dirname(__FILE__), 'strings', 'yard', 'templates'))
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,92 @@
1
+ require 'puppet_x/puppetlabs/strings'
2
+
3
+ class PuppetX::PuppetLabs::Strings::Actions
4
+
5
+ # Creates a new instance of the Actions class by determining
6
+ # whether or not debug and backtrace arguments should be sent
7
+ # to YARD
8
+ def initialize(puppet_debug, puppet_backtrace)
9
+ @debug = puppet_debug
10
+ @backtrace = puppet_backtrace
11
+ end
12
+
13
+ # Holds the name of a module and the file path to its YARD index
14
+ ModuleIndex = Struct.new(:name, :index_path)
15
+
16
+
17
+ # Maps things like the Puppet `--debug` flag to YARD options.
18
+ def merge_puppet_args!(yard_args)
19
+ yard_args.unshift '--debug' if @debug
20
+ yard_args.unshift '--backtrace' if @backtrace
21
+
22
+ yard_args
23
+ end
24
+
25
+ # Builds doc indices (.yardoc directories) for modules.
26
+ # Currently lacks the fine-grained control over where these
27
+ # indices are created and just dumps them in the module roots.
28
+ #
29
+ # @return [Array<Module>] the modules to be documented
30
+ #
31
+ # @param [Array<String>] module_names a list of the module source files
32
+ # @param [Array<String>] module_sourcefiles default list of module files
33
+ def index_documentation_for_modules(module_names, module_sourcefiles)
34
+ # NOTE: The return value of the `module` Face seems to have changed in
35
+ # 3.6.x. This part of the code will blow up if run under an earlier
36
+ # version of Puppet.
37
+ modules = Puppet::Face[:module, :current].list
38
+ module_list = modules[:modules_by_path].values.flatten
39
+
40
+ module_list.select! {|m| module_names.include? m.name} unless module_names.empty?
41
+
42
+ # Invoke `yardoc` with -n so that it doesn't generate any HTML output but
43
+ # does build a `.yardoc` index that other tools can generate output from.
44
+ yard_args = %w[--no-stats -n] + module_sourcefiles
45
+ merge_puppet_args!(yard_args)
46
+
47
+ module_list.each do |m|
48
+ Dir.chdir(m.path) do
49
+ YARD::CLI::Yardoc.run(*yard_args)
50
+
51
+ # Clear the global Registry so that objects from one module don't
52
+ # bleed into the next.
53
+ YARD::Registry.clear
54
+ end
55
+ end
56
+ end
57
+
58
+ # Extracts the needed information of the modules we're documenting
59
+ #
60
+ # @return [Array<ModuleIndex>] An array of representation of the modules
61
+ # to produce documentation for. Each ModuleIndex contains the module name
62
+ # and the path to its YARD index
63
+ #
64
+ # @param [Array<String>] module_list a list of the module source files
65
+ def generate_module_tuples(module_list)
66
+ module_list.map do |mod|
67
+ name = (mod.forge_name || mod.name).gsub('/', '-')
68
+ yard_index = File.join(mod.path, '.yardoc')
69
+
70
+ ModuleIndex.new(name, yard_index)
71
+ end
72
+ end
73
+
74
+ # Hands off the needed information to YARD so it may
75
+ # serve the documentation
76
+ #
77
+ # @param [Array<String>] yard_args a list of all the arguments to pass to YARD
78
+ def serve_documentation(*yard_args)
79
+ merge_puppet_args!(yard_args)
80
+ YARD::CLI::Server.run(*yard_args)
81
+ end
82
+
83
+ # Hands off the needed information to YARD so it may
84
+ # generate the documentation
85
+ #
86
+ # @param [Array<String>] yard_args a list of all the arguments to pass to YARD
87
+ def generate_documentation(*yard_args)
88
+ merge_puppet_args!(yard_args)
89
+ YARD::CLI::Yardoc.run(*yard_args)
90
+ end
91
+ end
92
+
@@ -0,0 +1,79 @@
1
+ require 'ostruct'
2
+
3
+ # An adapter class that conforms a Pops model instance + adapters to the
4
+ # interface expected by YARD handlers.
5
+ #
6
+ # FIXME: Inhertiting from OpenStruct is a bit of a hack. It allows attributes
7
+ # to be declared as needed but in the long run understandibility of the code
8
+ # would be improved by having a concrete model.
9
+ class PuppetX::PuppetLabs::Strings::Pops::YARDStatement < OpenStruct
10
+ attr_reader :pops_obj, :comments
11
+
12
+ def initialize(pops_obj)
13
+ # Initialize OpenStruct
14
+ super({})
15
+
16
+ unless pops_obj.is_a? Puppet::Pops::Model::PopsObject
17
+ raise ArgumentError, "A YARDStatement can only be initialized from a PopsObject. Got a: #{pops_obj.class}"
18
+ end
19
+
20
+ @pops_obj = pops_obj
21
+ @pos_adapter = Puppet::Pops::Adapters::SourcePosAdapter.adapt(@pops_obj)
22
+ # FIXME: Perhaps this should be a seperate adapter?
23
+ @comments = extract_comments
24
+ end
25
+
26
+ def type
27
+ pops_obj.class
28
+ end
29
+
30
+ def line
31
+ @line ||= @pos_adapter.line
32
+ end
33
+
34
+ def source
35
+ @source ||= @pos_adapter.extract_text
36
+ end
37
+
38
+ # FIXME: I don't know quite what these are supposed to do, but they show up
39
+ # quite often in the YARD handler code. Figure out whether they are
40
+ # necessary.
41
+ alias_method :show, :source
42
+ def comments_hash_flag; nil end
43
+ def comments_range; nil end
44
+
45
+ private
46
+ # TODO: This stuff should probably be part of a separate class/adapter.
47
+ COMMENT_PATTERN = /^\s*#.*\n/
48
+
49
+ def extract_comments
50
+ comments = []
51
+ program = pops_obj.eAllContainers.find {|c| c.is_a?(Puppet::Pops::Model::Program) }
52
+ # FIXME: Horribly inefficient. Multiple copies. Generator pattern would
53
+ # be much better.
54
+ source_text = program.source_text.lines.to_a
55
+
56
+ source_text.slice(0, line-1).reverse.each do |line|
57
+ if COMMENT_PATTERN.match(line)
58
+ # FIXME: The gsub trims comments, but is extremely optimistic: It
59
+ # assumes only one space separates the comment body from the
60
+ # comment character.
61
+ # NOTE: We cannot just trim any amount of whitespace as indentation
62
+ # is sometimes significant in markdown. We would need a real parser.
63
+
64
+ # Comments which begin with some whitespace, a hash and then some
65
+ # tabs and spaces should be scrubbed. Comments which just have a
66
+ # solitary hash then a newline should keep that newline since newlines
67
+ # are significant in markdown.
68
+ comments.unshift line.gsub(/^\s*#[\t ]/, '').gsub(/^\s*#\n/, "\n")
69
+ else
70
+ # No comment found on this line. We must be done piecing together a
71
+ # comment block.
72
+ break
73
+ end
74
+ end
75
+
76
+ # Stick everything back together.
77
+ comments.join
78
+ end
79
+ end
@@ -0,0 +1,47 @@
1
+ # Loosely based on the TreeDumper classes in Pops::Model. The responsibility of
2
+ # this class is to walk a Pops::Model and output objects that can be consumed
3
+ # by YARD handlers.
4
+ #
5
+ # @note Currently, this class only extracts node, host class and type
6
+ # definitions.
7
+ class PuppetX::PuppetLabs::Strings::Pops::YARDTransformer
8
+ def initialize
9
+ @transform_visitor = Puppet::Pops::Visitor.new(self, 'transform')
10
+ end
11
+
12
+ def transform(o)
13
+ @transform_visitor.visit(o)
14
+ end
15
+
16
+ private
17
+
18
+ def transform_Factory(o)
19
+ transform(o.current)
20
+ end
21
+
22
+ def transform_Program(o)
23
+ o.definitions.map{|d| transform(d)}
24
+ end
25
+
26
+ # Extract comments from type definitions and class definitions. Wrap them
27
+ # into YARDStatement objects that provide an interface for YARD handlers.
28
+ def transform_NamedDefinition(o)
29
+ obj = PuppetX::PuppetLabs::Strings::Pops::YARDStatement.new(o)
30
+ obj.parameters = o.parameters.map do |p|
31
+ param_tuple = [transform(p)]
32
+ param_tuple << ( p.value.nil? ? nil : transform(p.value) )
33
+ end
34
+
35
+ obj
36
+ end
37
+
38
+ # Catch-all visitor.
39
+ def transform_Positioned(o)
40
+ PuppetX::PuppetLabs::Strings::Pops::YARDStatement.new(o)
41
+ end
42
+
43
+ # nil in... nil out!
44
+ def transform_NilClass(o)
45
+ nil
46
+ end
47
+ end
@@ -0,0 +1,65 @@
1
+ require 'puppet_x/puppetlabs/strings/actions'
2
+
3
+ module PuppetX::PuppetLabs::Strings::Util
4
+ MODULE_SOURCEFILES = ['manifests/**/*.pp', 'lib/**/*.rb']
5
+
6
+ def self.generate(args = [])
7
+ yardoc_actions = PuppetX::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace])
8
+
9
+ # The last element of the argument array should be the options hash.
10
+ # We don't have any options yet, so for now just pop the hash off and
11
+ # toss it.
12
+ #
13
+ # NOTE: The Puppet Face will throw 'unrecognized option' errors if any
14
+ # YARD options are passed to it. The best way to approach this problem is
15
+ # by using the `.yardopts` file. YARD will autoload any options placed in
16
+ # that file.
17
+ options = args.pop
18
+ YARD::Config.options = YARD::Config.options.merge(options) if options
19
+
20
+ # For now, assume the remaining positional args are a list of manifest
21
+ # and ruby files to parse.
22
+ yard_args = (args.empty? ? MODULE_SOURCEFILES : args)
23
+
24
+ # If json is going to be emitted to stdout, suppress statistics.
25
+ if options && options[:emit_json_stdout]
26
+ yard_args.push('--no-stats')
27
+ end
28
+
29
+ # This line monkeypatches yard's progress indicator so it doesn't write
30
+ # all over the terminal. This should definitely not be in real code, but
31
+ # it's very handy for debugging with pry
32
+ #class YARD::Logger; def progress(*args); end; end
33
+ YARD::Tags::Library.define_directive("puppet.type.param",
34
+ :with_types_and_name,
35
+ PuppetX::PuppetLabs::Strings::YARD::Tags::PuppetTypeParameterDirective)
36
+
37
+ yardoc_actions.generate_documentation(*yard_args)
38
+ end
39
+
40
+ def self.serve(args = [])
41
+ server_actions = PuppetX::PuppetLabs::Strings::Actions.new(Puppet[:debug], Puppet[:trace])
42
+
43
+ args.pop
44
+
45
+ module_names = args
46
+
47
+ # FIXME: This is pretty inefficient as it forcibly re-generates the YARD
48
+ # indicies each time the server is started. However, it ensures things are
49
+ # generated properly.
50
+ module_list = server_actions.index_documentation_for_modules(module_names, MODULE_SOURCEFILES)
51
+
52
+ module_tuples = server_actions.generate_module_tuples(module_list)
53
+
54
+ module_tuples.map! do |mod|
55
+ [mod[:name], mod[:index_path]]
56
+ end
57
+
58
+ # The `-m` flag means a list of name/path pairs will follow. The name is
59
+ # used as the module name and the path indicates which `.yardoc` index to
60
+ # generate documentation from.
61
+ yard_args = %w[-m -q] + module_tuples.flatten
62
+
63
+ server_actions.serve_documentation(*yard_args)
64
+ end
65
+ end