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,91 +0,0 @@
1
- include T('default/module')
2
-
3
- require File.join(File.dirname(__FILE__),'../html_helper')
4
- require File.join(File.dirname(__FILE__),'../template_helper')
5
-
6
- def init
7
- sections :header, :box_info,
8
- :method_summary, [:item_summary],
9
- :method_details_list, [T('method_details')]
10
-
11
- @methods = object.children
12
- @template_helper = TemplateHelper.new
13
- end
14
-
15
- def header
16
- # The list is expected to only contain one type of function
17
- if @methods[0]['puppet_4x_function']
18
- @header_text = "Puppet 4 Functions"
19
- else
20
- @header_text = "Puppet 3 Functions"
21
- end
22
-
23
- erb(:header)
24
- end
25
-
26
- def box_info
27
- @source_files = []
28
-
29
- @methods.each do |method|
30
- # extract the file name and line number for each method
31
- file_name = method.files[0][0]
32
- line_number = method.files[0][1]
33
-
34
- @source_files.push([method.name, "#{file_name} (#{line_number})"])
35
- end
36
-
37
- erb(:box_info)
38
- end
39
-
40
- def method_summary
41
- @method_details = []
42
- @html_helper = HTMLHelper.new
43
-
44
- @methods.each do |method|
45
- # If there are multiple sentences in the method description, only
46
- # use the first one for the summary. If the author did not include
47
- # any periods in their summary, include the whole thing
48
- first_sentence = method.docstring.match(/^(.*?)\./)
49
- brief_summary = first_sentence ? first_sentence : method.docstring
50
-
51
- return_tag = method.tags.find { |tag| tag.tag_name == "return"}
52
- return_types = return_tag.nil? ? nil : return_tag.types
53
-
54
- @method_details.push({:name => method.name, :short_desc => brief_summary, :return_types => return_types})
55
- end
56
-
57
- erb(:method_summary)
58
- end
59
-
60
- def method_details_list
61
- @class_details = []
62
- @html_helper = HTMLHelper.new
63
-
64
- @methods.each do |object|
65
-
66
- method_info = @template_helper.extract_tag_data(object)
67
- param_details = nil
68
- param_tags = object.tags.find_all{ |tag| tag.tag_name == "param"}
69
-
70
- if object['puppet_4x_function']
71
- # Extract the source code
72
- source_code = object.source
73
- # Extract the parameters for the source code
74
- parameters = source_code.match(/(?:def .*)\((.*?)\)/)
75
- # Convert the matched string into an array of strings
76
- params = parameters.nil? ? nil : parameters[1].split(/\s*,\s*/)
77
-
78
- param_details = @template_helper.extract_param_details(params, param_tags) unless params.nil?
79
- @template_helper.check_types_match_docs object, param_details
80
- @template_helper.check_parameters_match_docs object
81
- else
82
- param_details = @template_helper.comment_only_param_details(param_tags)
83
- end
84
-
85
- method_info[:params] = param_details
86
-
87
- @class_details.push(method_info)
88
- end
89
-
90
- erb(:method_details_list)
91
- end
@@ -1,192 +0,0 @@
1
- require "puppet"
2
-
3
- # A class containing helper methods to aid in the extraction of relevant data
4
- # from comments and YARD tags
5
- class TemplateHelper
6
- # Extracts data from comments which include the supported YARD tags
7
- def extract_tag_data(object)
8
- examples = Hash.new
9
- example_tags = object.tags.find_all { |tag| tag.tag_name == "example" }
10
- example_tags.each do |example|
11
- examples["#{example.name}"] = example.text
12
- end
13
-
14
- return_tag = object.tags.find { |tag| tag.tag_name == "return"}
15
- return_text = return_tag.nil? ? nil : return_tag.text
16
- return_types = return_tag.nil? ? nil : return_tag.types
17
- return_details = (return_text.nil? && return_types.nil?) ? nil : [return_text, return_types]
18
-
19
- since_tag = object.tags.find { |tag| tag.tag_name == "since"}
20
- since_text = since_tag.nil? ? nil : since_tag.text
21
-
22
- {:name => object.name, :desc => object.docstring, :examples => examples, :since => since_text, :return => return_details}
23
- end
24
-
25
- # Given the parameter information and YARD param tags, extracts the
26
- # useful information and returns it as an array of hashes which can
27
- # be printed and formatted as HTML
28
- #
29
- # @param parameters [Array] parameter details obtained programmatically
30
- # @param tags_hash [Array] parameter details obtained from comments
31
- # @param fq_name [Boolean] does this parameter have a fully qualified name?
32
- #
33
- # @return [Hash] The relevant information about each parameter with the following keys/values:
34
- # {:name => [String] The name of the parameter
35
- # :fq_name => [String] The fully qualified parameter name
36
- # :desc => [String] The description provided in the comment
37
- # :types => [Array] The parameter type(s) specified in the comment
38
- # :exists => [Boolean] True only if the parameter exists in the documented logic and not just in a comment}
39
- def extract_param_details(parameters, tags_hash, fq_name = false)
40
- parameter_info = []
41
-
42
- # Extract the information for parameters that exist
43
- # as opposed to parameters that are defined only in the comments
44
- parameters.each do |param|
45
- if fq_name
46
- param_name = param[0]
47
- fully_qualified_name = param[1]
48
- else
49
- param_name = param
50
- end
51
-
52
- param_tag = tags_hash.find { |tag| tag.name == param_name }
53
-
54
- description = param_tag.nil? ? nil : param_tag.text
55
- param_types = param_tag.nil? ? nil : param_tag.types
56
-
57
- param_details = {:name => param_name, :desc => description, :types => param_types, :exists? => true}
58
-
59
- if fq_name
60
- param_details[:fq_name] = fully_qualified_name
61
- end
62
-
63
- parameter_info.push(param_details)
64
- end
65
-
66
- # Check if there were any comments for parameters that do not exist
67
- tags_hash.each do |tag|
68
- param_exists = false
69
- parameter_info.each do |parameter|
70
- if parameter[:name] == tag.name
71
- param_exists = true
72
- end
73
- end
74
- if !param_exists
75
- parameter_info.push({:name => tag.name, :desc => tag.text, :types => tag.types, :exists? => false})
76
- end
77
- end
78
-
79
- parameter_info
80
- end
81
-
82
- # Generates parameter information in situations where the information can only
83
- # come from YARD tags in the comments, not from the code itself. For now the only
84
- # use for this is 3x functions. In this case exists? will always be true since we
85
- # cannot verify if the parameter exists in the code itself. We must trust the user
86
- # to provide information in the comments that is accurate.
87
- #
88
- # @param param_tags [Array] parameter details obtained from comments
89
- #
90
- # @return [Hash] The relevant information about each parameter with the following keys/values:
91
- # {:name => [String] The name of the parameter
92
- # :desc => [String] The description provided in the comment
93
- # :types => [Array] The parameter type(s) specified in the comment
94
- # :exists => [Boolean] True only if the parameter exists in the documented logic and not just in a comment
95
- # :puppet_3_func => [Boolean] Are these parameters for a puppet 3 function? (relevant in HTML generation)}
96
- def comment_only_param_details(param_tags)
97
- return if param_tags.empty?
98
-
99
- parameter_info = []
100
-
101
- param_tags.each do |tag|
102
- parameter_info.push({:name => tag.name, :desc => tag.text, :types => tag.types, :exists? => true, :puppet_3_func => true})
103
- end
104
-
105
- parameter_info
106
- end
107
-
108
- # Check that any types specified in the docstrings match the actual method
109
- # types. This is used by puppet 4x functions and defined types.
110
- # @param object the code object to examine for parameters names
111
- def check_types_match_docs(object, params_hash)
112
- # We'll need this to extract type info from the type specified by the
113
- # docstring.
114
- type_parser = Puppet::Pops::Types::TypeParser.new
115
- type_calculator = Puppet::Pops::Types::TypeCalculator.new
116
-
117
- object.type_info.each do |function|
118
- function.keys.each do |key|
119
- if function[key].class == String
120
- begin
121
- instantiated = type_parser.parse function[key]
122
- rescue Puppet::ParseError
123
- # Likely the result of a malformed type
124
- next
125
- end
126
- else
127
- instantiated = function[key]
128
- end
129
- params_hash.each do |param|
130
- if param[:name] == key and param[:types] != nil
131
- param[:types].each do |type|
132
- param_instantiated = type_parser.parse type
133
- if not type_calculator.assignable? instantiated, param_instantiated
134
- actual_types = object.type_info.map do |sig|
135
- sig[key].to_s if sig[key]
136
- end.compact
137
- # Get the locations where the object can be found. We only care about
138
- # the first one.
139
- locations = object.files
140
- warning = <<-EOS
141
- [warn]: @param tag types do not match the code. The #{param[:name]}
142
- parameter is declared as types #{param[:types]} in the docstring,
143
- but the code specifies the types #{actual_types}
144
- EOS
145
-
146
- # If the locations aren't in the shape we expect then report that
147
- # the file number couldn't be determined.
148
- if locations.length >= 1 and locations[0].length == 2
149
- file = locations[0][0]
150
- line = locations[0][1]
151
- warning += " in the file #{file} near line #{line}."
152
- else
153
- warning += " Sorry, the file and line number could " +
154
- "not be determined."
155
- end
156
- $stderr.puts warning
157
- end
158
- end
159
- end
160
- end
161
- end
162
- end
163
- end
164
-
165
- # Check that the actual function parameters match what is stated in the docs.
166
- # If there is a mismatch, print a warning to stderr.
167
- # This is necessary for puppet classes and defined types. This type of
168
- # warning will be issued for ruby code by the ruby docstring parser.
169
- # @param object the code object to examine for parameters names
170
- def check_parameters_match_docs(object)
171
- param_tags = object.tags.find_all{ |tag| tag.tag_name == "param"}
172
- names = object.parameters.map {|l| l.first.gsub(/\W/, '') }
173
- locations = object.files
174
- param_tags.each do |tag|
175
- if not names.include?(tag.name)
176
- if locations.length >= 1 and locations[0].length == 2
177
- file_name = locations[0][0]
178
- line_number = locations[0][1]
179
- $stderr.puts <<-EOS
180
- [warn]: The parameter #{tag.name} is documented, but doesn't exist in
181
- your code, in file #{file_name} near line #{line_number}.
182
- EOS
183
- else
184
- $stderr.puts <<-EOS
185
- [warn]: The parameter #{tag.name} is documented, but doesn't exist in
186
- your code. Sorry, the file and line number could not be determined.
187
- EOS
188
- end
189
- end
190
- end
191
- end
192
- end
@@ -1,34 +0,0 @@
1
- <div class="docstring">
2
- <div class="discussion">
3
- <p><%= htmlify(Puppet::Util::Docs::scrub(@class_details[:desc])) %></p>
4
- </div>
5
- </div>
6
- <div class="tags">
7
- <% if @class_details[:examples] != {}%>
8
- <div class="examples">
9
- <p class="tag_title">Examples:</p>
10
- <% @class_details[:examples].each do |title, text| %>
11
- <div class="inline"><p><%= title %></p></div>
12
- <pre class="example code"><code><span><%= text %></span></code></pre>
13
- <% end %>
14
- </div>
15
- <% end %>
16
- <% if @class_details[:since] %>
17
- <p class="tag_title">Since:</p>
18
- <ul class="since">
19
- <li>
20
- <div class="inline">
21
- <p><%= @class_details[:since] %></p>
22
- </div>
23
- </li>
24
- </ul>
25
- <% end %>
26
- <% if @class_details[:return] %>
27
- <p class="tag_title">Return:</p>
28
- <ul class="return">
29
- <li>
30
- <%= @html_helper.generate_return_types(@class_details[:return][1], @class_details[:return][0]) %>
31
- </li>
32
- </ul>
33
- <% end %>
34
- </div>
@@ -1,5 +0,0 @@
1
- <div class='module_header'>
2
- <h1>
3
- <%= @header_text %>
4
- </h1>
5
- </div>
@@ -1,12 +0,0 @@
1
- <h2>Parameter Summary</h2>
2
- <div class="tags">
3
- <ul class="param">
4
- <%= @html_helper.generate_parameters(@param_details, object) %>
5
- </ul>
6
- </div>
7
- <h2>Features</h2>
8
- <div class="tags">
9
- <ul class="feature">
10
- <%= @html_helper.generate_features(@feature_details, object) %>
11
- </ul>
12
- </div>
@@ -1,10 +0,0 @@
1
- <h2>Available Providers</h2>
2
- <% if @providers != [] %>
3
- <div class="tags">
4
- <ul class="command">
5
- <% @providers.each do |provider| %>
6
- <li><a href="<%= provider.name.to_s %>.html"><tt><%= provider.name.to_s %></tt></a></li>
7
- <% end %>
8
- </ul>
9
- </div>
10
- <% end %>
@@ -1 +0,0 @@
1
- include T('default/module/html')
@@ -1,55 +0,0 @@
1
- include T('default/module')
2
-
3
- require File.join(File.dirname(__FILE__),'../html_helper')
4
- require File.join(File.dirname(__FILE__),'../template_helper')
5
-
6
- def init
7
- sections :header, :box_info, :pre_docstring, :docstring, :parameter_details, :provider_details
8
-
9
- @template_helper = TemplateHelper.new
10
- @html_helper = HTMLHelper.new
11
- end
12
-
13
- def header
14
- @header_text = object.header_name
15
-
16
- erb(:header)
17
- end
18
-
19
- def provider_details
20
- type_name = object.name.to_s
21
- @providers = YARD::Registry.all(:provider).select { |t| t.type_name == type_name }
22
-
23
- erb(:provider_details)
24
- end
25
-
26
- def parameter_details
27
- params = object.parameter_details.map { |h| h[:name] }
28
- # Put properties and parameters in one big list where the descriptions are
29
- # scrubbed and htmlified and the namevar is the first element, the ensure
30
- # property the second, and the rest are alphabetized.
31
- @param_details = (object.parameter_details + object.property_details).each {
32
- |h| h[:desc] = htmlify(Puppet::Util::Docs::scrub(h[:desc])) if h[:desc]
33
- }.sort { |a, b| a[:name] <=> b[:name] }
34
- # Float ensurable and namevars to the top of the list
35
- @param_details = @param_details.partition{|a| a[:name] == 'ensure'}.flatten
36
- @param_details = @param_details.partition{|a| a[:namevar]}.flatten
37
-
38
- @feature_details = object.features
39
- @template_helper.check_parameters_match_docs object
40
-
41
- erb(:parameter_details)
42
- end
43
-
44
- def header
45
- @header_text = "Puppet Type: #{object.name}"
46
-
47
- erb(:header)
48
- end
49
-
50
- def docstring
51
-
52
- @class_details = @template_helper.extract_tag_data(object)
53
-
54
- erb(:docstring)
55
- end