puppet-strings 0.4.0 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +122 -0
  3. data/COMMITTERS.md +185 -0
  4. data/CONTRIBUTING.md +89 -0
  5. data/Gemfile +38 -0
  6. data/JSON.md +511 -0
  7. data/LICENSE +13 -0
  8. data/README.md +416 -0
  9. data/Rakefile +49 -0
  10. data/lib/puppet-strings.rb +63 -0
  11. data/lib/puppet-strings/json.rb +49 -0
  12. data/lib/puppet-strings/tasks.rb +10 -0
  13. data/lib/puppet-strings/tasks/generate.rb +23 -0
  14. data/lib/puppet-strings/tasks/gh_pages.rb +43 -0
  15. data/lib/puppet-strings/yard.rb +96 -0
  16. data/lib/puppet-strings/yard/code_objects.rb +8 -0
  17. data/lib/puppet-strings/yard/code_objects/base.rb +14 -0
  18. data/lib/puppet-strings/yard/code_objects/class.rb +59 -0
  19. data/lib/puppet-strings/yard/code_objects/defined_type.rb +58 -0
  20. data/lib/puppet-strings/yard/code_objects/function.rb +93 -0
  21. data/lib/puppet-strings/yard/code_objects/group.rb +30 -0
  22. data/lib/puppet-strings/yard/code_objects/provider.rb +93 -0
  23. data/lib/puppet-strings/yard/code_objects/type.rb +146 -0
  24. data/lib/puppet-strings/yard/handlers.rb +16 -0
  25. data/lib/puppet-strings/yard/handlers/puppet/base.rb +44 -0
  26. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +23 -0
  27. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +23 -0
  28. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +42 -0
  29. data/lib/puppet-strings/yard/handlers/ruby/base.rb +38 -0
  30. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +357 -0
  31. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +113 -0
  32. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +194 -0
  33. data/lib/puppet-strings/yard/parsers.rb +7 -0
  34. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +70 -0
  35. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +146 -0
  36. data/lib/puppet-strings/yard/tags.rb +6 -0
  37. data/lib/puppet-strings/yard/tags/overload_tag.rb +109 -0
  38. data/lib/puppet-strings/yard/tags/parameter_directive.rb +24 -0
  39. data/lib/puppet-strings/yard/tags/property_directive.rb +24 -0
  40. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb +9 -0
  41. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb +9 -0
  42. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb +10 -0
  43. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +10 -0
  44. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +9 -0
  45. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +64 -0
  46. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +35 -0
  47. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +172 -0
  48. data/lib/puppet-strings/yard/templates/default/puppet_class/html/box_info.erb +26 -0
  49. data/lib/puppet-strings/yard/templates/default/puppet_class/html/header.erb +1 -0
  50. data/lib/puppet-strings/yard/templates/default/puppet_class/html/overview.erb +6 -0
  51. data/lib/puppet-strings/yard/templates/default/puppet_class/html/setup.rb +14 -0
  52. data/lib/puppet-strings/yard/templates/default/puppet_class/html/source.erb +12 -0
  53. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/box_info.erb +10 -0
  54. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/header.erb +1 -0
  55. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/overview.erb +6 -0
  56. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/setup.rb +5 -0
  57. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/source.erb +12 -0
  58. data/lib/puppet-strings/yard/templates/default/puppet_function/html/box_info.erb +14 -0
  59. data/lib/puppet-strings/yard/templates/default/puppet_function/html/header.erb +1 -0
  60. data/lib/puppet-strings/yard/templates/default/puppet_function/html/overview.erb +18 -0
  61. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +5 -0
  62. data/lib/puppet-strings/yard/templates/default/puppet_function/html/source.erb +12 -0
  63. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/box_info.erb +14 -0
  64. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/collection.erb +10 -0
  65. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/features.erb +12 -0
  66. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/header.erb +1 -0
  67. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/overview.erb +6 -0
  68. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/setup.rb +29 -0
  69. data/lib/puppet-strings/yard/templates/default/puppet_type/html/box_info.erb +20 -0
  70. data/lib/puppet-strings/yard/templates/default/puppet_type/html/features.erb +13 -0
  71. data/lib/puppet-strings/yard/templates/default/puppet_type/html/header.erb +1 -0
  72. data/lib/puppet-strings/yard/templates/default/puppet_type/html/overview.erb +6 -0
  73. data/lib/puppet-strings/yard/templates/default/puppet_type/html/parameters.erb +35 -0
  74. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +32 -0
  75. data/lib/puppet-strings/yard/templates/default/tags/html/puppet_overload.erb +12 -0
  76. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +15 -0
  77. data/lib/puppet/application/strings.rb +1 -0
  78. data/lib/puppet/face/strings.rb +80 -39
  79. data/spec/acceptance/emit_json_options.rb +41 -0
  80. data/spec/acceptance/lib/util.rb +15 -0
  81. data/spec/acceptance/running_strings_generate.rb +54 -0
  82. data/spec/fixtures/acceptance/modules/test/functions/add.pp +9 -0
  83. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +5 -0
  84. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +2 -0
  85. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +9 -0
  86. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +15 -0
  87. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +27 -0
  88. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +27 -0
  89. data/spec/fixtures/acceptance/modules/test/metadata.json +6 -0
  90. data/spec/fixtures/unit/json/output.json +348 -0
  91. data/spec/fixtures/unit/json/output_without_puppet_function.json +301 -0
  92. data/spec/spec_helper.rb +21 -0
  93. data/spec/spec_helper_acceptance.rb +27 -0
  94. data/spec/unit/puppet-strings/json_spec.rb +136 -0
  95. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +155 -0
  96. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +155 -0
  97. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +169 -0
  98. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +613 -0
  99. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +90 -0
  100. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +214 -0
  101. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +171 -0
  102. metadata +115 -92
  103. data/lib/puppet-strings/rake_tasks.rb +0 -18
  104. data/lib/puppet_x/puppetlabs/strings.rb +0 -64
  105. data/lib/puppet_x/puppetlabs/strings/actions.rb +0 -92
  106. data/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb +0 -79
  107. data/lib/puppet_x/puppetlabs/strings/pops/yard_transformer.rb +0 -47
  108. data/lib/puppet_x/puppetlabs/strings/util.rb +0 -65
  109. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/defined_type_object.rb +0 -33
  110. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/host_class_object.rb +0 -22
  111. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/method_object.rb +0 -62
  112. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/provider_object.rb +0 -24
  113. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/puppet_namespace_object.rb +0 -48
  114. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/type_object.rb +0 -42
  115. data/lib/puppet_x/puppetlabs/strings/yard/core_ext/yard.rb +0 -40
  116. data/lib/puppet_x/puppetlabs/strings/yard/handlers/base.rb +0 -13
  117. data/lib/puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler.rb +0 -31
  118. data/lib/puppet_x/puppetlabs/strings/yard/handlers/heredoc_helper.rb +0 -80
  119. data/lib/puppet_x/puppetlabs/strings/yard/handlers/host_class_handler.rb +0 -42
  120. data/lib/puppet_x/puppetlabs/strings/yard/handlers/provider_handler.rb +0 -95
  121. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +0 -54
  122. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb +0 -234
  123. data/lib/puppet_x/puppetlabs/strings/yard/handlers/type_handler.rb +0 -295
  124. data/lib/puppet_x/puppetlabs/strings/yard/json_registry_store.rb +0 -85
  125. data/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb +0 -68
  126. data/lib/puppet_x/puppetlabs/strings/yard/parser.rb +0 -30
  127. data/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb +0 -9
  128. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb +0 -34
  129. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/header.erb +0 -5
  130. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb +0 -6
  131. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/setup.rb +0 -1
  132. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/setup.rb +0 -49
  133. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_class.erb +0 -2
  134. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_manifest.erb +0 -1
  135. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb +0 -21
  136. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +0 -1
  137. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +0 -1
  138. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/setup.rb +0 -82
  139. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/box_info.erb +0 -22
  140. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/setup.rb +0 -1
  141. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/subclasses.erb +0 -4
  142. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb +0 -21
  143. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/html_helper.rb +0 -139
  144. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/layout/html/setup.rb +0 -18
  145. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/html/header.erb +0 -17
  146. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/setup.rb +0 -21
  147. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/text/header.erb +0 -2
  148. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/command_details.erb +0 -8
  149. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/confine_details.erb +0 -10
  150. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/default_details.erb +0 -10
  151. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/docstring.erb +0 -34
  152. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/feature_details.erb +0 -10
  153. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/header.erb +0 -5
  154. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/setup.rb +0 -1
  155. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb +0 -50
  156. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/box_info.erb +0 -11
  157. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/header.erb +0 -5
  158. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_details_list.erb +0 -53
  159. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb +0 -20
  160. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/setup.rb +0 -1
  161. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb +0 -91
  162. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb +0 -192
  163. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/docstring.erb +0 -34
  164. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/header.erb +0 -5
  165. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/parameter_details.erb +0 -12
  166. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/provider_details.erb +0 -10
  167. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/setup.rb +0 -1
  168. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/setup.rb +0 -55
@@ -1,47 +0,0 @@
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
@@ -1,65 +0,0 @@
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
@@ -1,33 +0,0 @@
1
- require 'json'
2
-
3
- class PuppetX::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject < PuppetX::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject
4
- # A list of parameters attached to this class.
5
- # @return [Array<Array(String, String)>]
6
- attr_accessor :parameters
7
- attr_accessor :type_info
8
-
9
- def to_s
10
- name.to_s
11
- end
12
-
13
- def to_json(*a)
14
- {
15
- "name" => @name,
16
- "file" => file,
17
- "line" => line,
18
- "parameters" => Hash[@parameters],
19
- "docstring" => Puppet::Util::Docs.scrub(@docstring),
20
- "signatures" => @type_info.map do |signature|
21
- signature.map do |key, value|
22
- {
23
- "name" => key,
24
- "type" => value,
25
- }
26
- end
27
- end,
28
- "examples" => self.tags.map do |tag|
29
- tag.text if tag.tag_name == 'example'
30
- end.compact,
31
- }.to_json(*a)
32
- end
33
- end
@@ -1,22 +0,0 @@
1
- class PuppetX::PuppetLabs::Strings::YARD::CodeObjects::HostClassObject < PuppetX::PuppetLabs::Strings::YARD::CodeObjects::DefinedTypeObject
2
- # The {HostClassObject} that this class inherits from, if any.
3
- # @return [HostClassObject, Proxy, nil]
4
- attr_accessor :parent_class
5
-
6
- # NOTE: `include_mods` is never used as it makes no sense for Puppet, but
7
- # this is called by `YARD::Registry` and it will pass a parameter.
8
- def inheritance_tree(include_mods = false)
9
- if parent_class.is_a?(PuppetX::PuppetLabs::Strings::YARD::CodeObjects::HostClassObject)
10
- # Cool. We got a host class. Return self + parent inheritance tree.
11
- [self] + parent_class.inheritance_tree
12
- elsif parent_class.is_a?(YARD::CodeObjects::Proxy)
13
- # We have a reference to a parent that has not been created yet. Just
14
- # return it.
15
- [self, parent_class]
16
- else
17
- # Most likely no parent class. But also possibly an object that we
18
- # shouldn't inherit from. Just return self.
19
- [self]
20
- end
21
- end
22
- end
@@ -1,62 +0,0 @@
1
- class YARD::CodeObjects::MethodObject
2
-
3
- # Override to_s and to_json methods in Yard's MethodObject so that they
4
- # return output formatted as I like for puppet 3x and 4x methods.
5
- def to_s
6
- if self[:puppet_4x_function] || self[:puppet_3x_function]
7
- name.to_s
8
- else
9
- super
10
- end
11
- end
12
-
13
- def to_json(*a)
14
- if self[:puppet_4x_function]
15
- {
16
- "name" => @name,
17
- "file" => file,
18
- "line" => line,
19
- "function_api_version" => 4,
20
- "docstring" => Puppet::Util::Docs.scrub(@docstring),
21
- "examples" => self.tags.map do |tag|
22
- tag.text if tag.tag_name == 'example'
23
- end.compact,
24
- "documented_params" => @parameters.map do |tuple|
25
- {
26
- "name" => tuple[0],
27
- "type" => tuple[1],
28
- }
29
- end,
30
- "signatures" => @type_info.map do |signature|
31
- signature.map do |key, value|
32
- {
33
- "name" => key,
34
- "type" => value,
35
- }
36
- end
37
- end,
38
- }.to_json(*a)
39
- elsif self[:puppet_3x_function]
40
- {
41
- "name" => @name,
42
- "file" => file,
43
- "line" => line,
44
- "function_api_version" => 3,
45
- "docstring" => Puppet::Util::Docs.scrub(@docstring),
46
- "documented_params" => @parameters.map do |tuple|
47
- {
48
- "name" => tuple[0],
49
- "type" => tuple[1],
50
- }
51
- end,
52
- "examples" => self.tags.map do |tag|
53
- tag.text if tag.tag_name == 'example'
54
- end.compact,
55
- }.to_json(*a)
56
- else
57
- super
58
- end
59
- end
60
-
61
-
62
- end
@@ -1,24 +0,0 @@
1
- class PuppetX::PuppetLabs::Strings::YARD::CodeObjects::ProviderObject < PuppetX::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject
2
- # A list of parameters attached to this class.
3
- # @return [Array<Array(String, String)>]
4
- attr_accessor :parameters
5
-
6
- def to_json(*a)
7
- {
8
- "name" => @name,
9
- "type_name" => @type_name,
10
- "file" => file,
11
- "line" => line,
12
- "docstring" => Puppet::Util::Docs.scrub(@docstring),
13
- "commands" => @commands,
14
- "confines" => @confines,
15
- "defaults" => @defaults,
16
- "features" => @features,
17
- "examples" => self.tags.map do |tag|
18
- tag.text if tag.tag_name == 'example'
19
- end.compact,
20
- }.to_json(*a)
21
- end
22
-
23
-
24
- end
@@ -1,48 +0,0 @@
1
- class PuppetX::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject < YARD::CodeObjects::NamespaceObject
2
-
3
- attr_accessor :type_info
4
- # NOTE: `YARD::Registry#resolve` requires a method with this signature to
5
- # be present on all subclasses of `NamespaceObject`.
6
- def inheritance_tree(include_mods = false)
7
- [self]
8
- end
9
-
10
- def to_s
11
- name.to_s
12
- end
13
-
14
- def to_json(*a)
15
- {
16
- "name" => @name,
17
- "file" => file,
18
- "line" => line,
19
- "docstring" => @docstring,
20
- "examples" => self.tags.map do |tag|
21
- tag.text if tag.tag_name == 'example'
22
- end.compact,
23
- }.to_json(*a)
24
- end
25
-
26
- # FIXME: We used to override `self.new` to ensure no YARD proxies were
27
- # created for namespaces segments that did not map to a host class or
28
- # defined type. Fighting the system in this way turned out to be
29
- # counter-productive.
30
- #
31
- # However, if a proxy is left in, YARD will drop back to namspace-mangling
32
- # heuristics that are very specific to Ruby and which produce ugly paths in
33
- # the resulting output. Need to find a way to address this.
34
- #
35
- # Tried:
36
- #
37
- # - Overriding self.new in the code object. Failed because self.new
38
- # overrides are gross and difficult to pull off. Especially when
39
- # replacing an existing override.
40
- #
41
- # - Adding functionality to the base handler to ensure something other
42
- # than a proxy occupies each namespace segment. Failed because once a
43
- # code object is created with a namespace, it will never update.
44
- # Unless that namespace is set to a Proxy.
45
- #
46
- # def self.new(namespace, name, *args, &block)
47
- end
48
-
@@ -1,42 +0,0 @@
1
- class PuppetX::PuppetLabs::Strings::YARD::CodeObjects::TypeObject < PuppetX::PuppetLabs::Strings::YARD::CodeObjects::PuppetNamespaceObject
2
- # A list of parameters attached to this class.
3
- # @return [Array<Array(String, String)>]
4
- attr_accessor :parameters
5
-
6
- def to_json(*a)
7
- {
8
- "name" => @name,
9
- "file" => file,
10
- "line" => line,
11
- "docstring" => Puppet::Util::Docs.scrub(@docstring),
12
- "parameters" => @parameter_details.map do |obj|
13
- {
14
- "allowed_values" => obj[:allowed_values] ? obj[:allowed_values].flatten : [],
15
- "default" => obj[:default],
16
- "docstring" => Puppet::Util::Docs.scrub(obj[:desc] || ''),
17
- "namevar" => obj[:namevar],
18
- "name" => obj[:name],
19
- }
20
- end,
21
- "examples" => self.tags.map do |tag|
22
- tag.text if tag.tag_name == 'example'
23
- end.compact,
24
- "properties" => @property_details.map do |obj|
25
- {
26
- "allowed_values" => obj[:allowed_values] ? obj[:allowed_values].flatten : [],
27
- "default" => obj[:default],
28
- "docstring" => Puppet::Util::Docs.scrub(obj[:desc] || ''),
29
- "name" => obj[:name],
30
- }
31
- end,
32
- "features" => @features.map do |obj|
33
- {
34
- "docstring" => Puppet::Util::Docs.scrub(obj[:desc] || ''),
35
- "methods" => obj[:methods],
36
- "name" => obj[:name],
37
- }
38
- end,
39
- }.to_json(*a)
40
- end
41
-
42
- end
@@ -1,40 +0,0 @@
1
- require 'yard'
2
-
3
- require 'puppet_x/puppetlabs/strings'
4
-
5
- # Patch the regular expression used to match namespaces
6
- # so it will allow namespace segments that begin with
7
- # both uppercase and lowercase letters (i.e. both
8
- # Puppet::Namespace and puppet::namespace)
9
- YARD::CodeObjects.send(:remove_const, :CONSTANTMATCH)
10
- YARD::CodeObjects::CONSTANTMATCH = /[a-zA-Z]\w*/
11
-
12
- # This is a temporary hack until a new version of YARD is
13
- # released. We submitted a patch to YARD to add the
14
- # CONSTANTSTART constant so that we could patch it and
15
- # successfully match our own namesapces. However until
16
- # the next version of the YARD gem is released, we must
17
- # patch the problematic method itself as it is not yet
18
- # using the added variable
19
- if defined? YARD::CodeObjects::CONSTANTSTART
20
- YARD::CodeObjects.send(:remove_const, :CONSTANTSTART)
21
- YARD::CodeObjects::CONSTANTSTART = /^[a-zA-Z]/
22
- else
23
- class YARD::CodeObjects::Proxy
24
- def proxy_path
25
- if @namespace.root?
26
- (@imethod ? YARD::CodeObjects::ISEP : "") + name.to_s
27
- elsif @origname
28
- if @origname =~ /^[a-zA-Z]/
29
- @origname
30
- else
31
- [namespace.path, @origname].join
32
- end
33
- elsif name.to_s =~ /^[a-zA-Z]/ # const
34
- name.to_s
35
- else # class meth?
36
- [namespace.path, name.to_s].join(YARD::CodeObjects::CSEP)
37
- end
38
- end
39
- end
40
- end
@@ -1,13 +0,0 @@
1
- require 'puppet_x/puppetlabs/strings/yard/core_ext/yard'
2
-
3
- class PuppetX::PuppetLabs::Strings::YARD::Handlers::Base < ::YARD::Handlers::Base
4
- # Easy access to Pops model objects for handler matching.
5
- include Puppet::Pops::Model
6
- # Easy access to custom code objects from which documentation is generated.
7
- include PuppetX::PuppetLabs::Strings::YARD::CodeObjects
8
-
9
- def self.handles?(statement)
10
- handlers.any? {|h| h == statement.type}
11
- end
12
-
13
- end
@@ -1,31 +0,0 @@
1
- class PuppetX::PuppetLabs::Strings::YARD::Handlers::DefinedTypeHandler < PuppetX::PuppetLabs::Strings::YARD::Handlers:: Base
2
- handles ResourceTypeDefinition
3
-
4
- process do
5
- obj = DefinedTypeObject.new(:root, statement.pops_obj.name) do |o|
6
- o.parameters = statement.parameters.map do |a|
7
- param_tuple = [a[0].pops_obj.name]
8
- param_tuple << ( a[1].nil? ? nil : a[1].source )
9
- end
10
- end
11
- tp = Puppet::Pops::Types::TypeParser.new
12
- param_type_info = {}
13
- statement.pops_obj.parameters.each do |pop_param|
14
- # If the parameter's type expression is nil, default to Any
15
- if pop_param.type_expr == nil
16
- param_type_info[pop_param.name] = Puppet::Pops::Types::TypeFactory.any()
17
- else
18
- begin
19
- param_type_info[pop_param.name] = tp.interpret_any(pop_param.type_expr)
20
- rescue Puppet::ParseError => e
21
- # If the type could not be interpreted insert a prominent warning
22
- param_type_info[pop_param.name] = "Type Error: #{e.message}"
23
- end
24
- end
25
- end
26
- obj.type_info = [param_type_info]
27
-
28
-
29
- register obj
30
- end
31
- end
@@ -1,80 +0,0 @@
1
- class HereDocHelper
2
- # NOTE: The following methods duplicate functionality from
3
- # Puppet::Util::Reference and Puppet::Parser::Functions.functiondocs
4
- #
5
- # However, implementing this natively in YARD is a good test for the
6
- # feasibility of extracting custom Ruby documentation. In the end, the
7
- # existing approach taken by Puppet::Util::Reference may be the best due to
8
- # the heavy use of metaprogramming in Types and Providers.
9
-
10
- # Extracts the Puppet function name and options hash from the parsed
11
- # definition.
12
- #
13
- # @return [(String, Hash{String => String})]
14
- def process_parameters(statement)
15
- # Passing `false` to prameters excludes the block param from the returned
16
- # list.
17
- name, opts = statement.parameters(false).compact
18
-
19
- name = process_element(name)
20
-
21
- # Don't try to process options if we don't have any
22
- if !opts.nil?
23
- opts = opts.map do |tuple|
24
- # Jump down into the S-Expression that represents a hashrocket, `=>`,
25
- # and the values on either side of it.
26
- tuple.jump(:assoc).map{|e| process_element(e)}
27
- end
28
-
29
- options = Hash[opts]
30
- else
31
- options = {}
32
- end
33
-
34
- [name, options]
35
- end
36
-
37
- # Sometimes the YARD parser returns Heredoc strings that start with `<-`
38
- # instead of `<<-`.
39
- HEREDOC_START = /^<?<-/
40
-
41
- def is_heredoc?(str)
42
- HEREDOC_START.match(str)
43
- end
44
-
45
- # Turns an entry in the method parameter list into a string.
46
- #
47
- # @param ele [YARD::Parser::Ruby::AstNode]
48
- # @return [String]
49
- def process_element(ele)
50
- ele = ele.jump(:ident, :string_content)
51
-
52
- case ele.type
53
- when :ident
54
- ele.source
55
- when :string_content
56
- source = ele.source
57
- if is_heredoc? source
58
- process_heredoc(source)
59
- else
60
- source
61
- end
62
- end
63
- end
64
-
65
- # Cleans up and formats Heredoc contents parsed by YARD.
66
- #
67
- # @param source [String]
68
- # @return [String]
69
- def process_heredoc(source)
70
- source = source.lines.to_a
71
-
72
- # YARD adds a line of source context on either side of the Heredoc
73
- # contents.
74
- source.shift
75
- source.pop
76
-
77
- # This utility method normalizes indentation and trims whitespace.
78
- Puppet::Util::Docs.scrub(source.join)
79
- end
80
- end