puppet-strings 2.2.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +87 -1
  3. data/CONTRIBUTING.md +32 -2
  4. data/README.md +81 -17
  5. data/lib/puppet-strings.rb +5 -3
  6. data/lib/puppet-strings/describe.rb +2 -0
  7. data/lib/puppet-strings/json.rb +4 -0
  8. data/lib/puppet-strings/markdown.rb +13 -9
  9. data/lib/puppet-strings/markdown/base.rb +30 -3
  10. data/lib/puppet-strings/markdown/data_type.rb +36 -0
  11. data/lib/puppet-strings/markdown/data_types.rb +43 -0
  12. data/lib/puppet-strings/markdown/defined_type.rb +2 -0
  13. data/lib/puppet-strings/markdown/defined_types.rb +3 -1
  14. data/lib/puppet-strings/markdown/function.rb +9 -7
  15. data/lib/puppet-strings/markdown/functions.rb +3 -1
  16. data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
  17. data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
  18. data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
  19. data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
  20. data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
  21. data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
  22. data/lib/puppet-strings/markdown/resource_type.rb +21 -2
  23. data/lib/puppet-strings/markdown/resource_types.rb +3 -1
  24. data/lib/puppet-strings/markdown/table_of_contents.rb +4 -1
  25. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +18 -6
  26. data/lib/puppet-strings/markdown/templates/data_type.erb +101 -0
  27. data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
  28. data/lib/puppet-strings/markdown/templates/function.erb +10 -1
  29. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  30. data/lib/puppet-strings/markdown/templates/resource_type.erb +35 -13
  31. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
  32. data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
  33. data/lib/puppet-strings/tasks.rb +2 -0
  34. data/lib/puppet-strings/tasks/generate.rb +5 -2
  35. data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
  36. data/lib/puppet-strings/version.rb +3 -1
  37. data/lib/puppet-strings/yard.rb +19 -0
  38. data/lib/puppet-strings/yard/code_objects.rb +4 -0
  39. data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
  40. data/lib/puppet-strings/yard/code_objects/class.rb +5 -3
  41. data/lib/puppet-strings/yard/code_objects/data_type.rb +102 -0
  42. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +60 -0
  43. data/lib/puppet-strings/yard/code_objects/defined_type.rb +5 -3
  44. data/lib/puppet-strings/yard/code_objects/function.rb +9 -6
  45. data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
  46. data/lib/puppet-strings/yard/code_objects/plan.rb +5 -3
  47. data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
  48. data/lib/puppet-strings/yard/code_objects/task.rb +3 -1
  49. data/lib/puppet-strings/yard/code_objects/type.rb +49 -5
  50. data/lib/puppet-strings/yard/handlers.rb +4 -0
  51. data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
  52. data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
  53. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
  54. data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
  55. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
  56. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
  57. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
  58. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
  59. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
  60. data/lib/puppet-strings/yard/handlers/ruby/base.rb +7 -2
  61. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +409 -0
  62. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -9
  63. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
  64. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +6 -3
  65. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +25 -12
  66. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +6 -3
  67. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +18 -1
  68. data/lib/puppet-strings/yard/parsers.rb +2 -0
  69. data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -1
  70. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
  71. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +11 -2
  72. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +29 -0
  73. data/lib/puppet-strings/yard/tags.rb +4 -0
  74. data/lib/puppet-strings/yard/tags/enum_tag.rb +14 -0
  75. data/lib/puppet-strings/yard/tags/factory.rb +18 -0
  76. data/lib/puppet-strings/yard/tags/overload_tag.rb +5 -2
  77. data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
  78. data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
  79. data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
  80. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
  81. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
  82. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
  83. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
  84. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
  85. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
  86. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  87. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
  88. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
  89. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
  90. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
  91. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
  92. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
  93. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
  94. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
  95. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
  96. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
  97. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
  98. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
  99. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
  100. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
  101. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
  102. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +1 -1
  103. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
  104. data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
  105. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
  106. data/lib/puppet-strings/yard/util.rb +7 -4
  107. data/lib/puppet/application/strings.rb +2 -0
  108. data/lib/puppet/face/strings.rb +7 -4
  109. data/lib/puppet/feature/rgen.rb +2 -0
  110. data/lib/puppet/feature/yard.rb +2 -0
  111. metadata +35 -45
  112. data/Gemfile +0 -38
  113. data/HISTORY.md +0 -218
  114. data/JSON.md +0 -802
  115. data/Rakefile +0 -98
  116. data/codecov.yml +0 -3
  117. data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
  118. data/spec/acceptance/emit_json_options.rb +0 -71
  119. data/spec/acceptance/generate_markdown_spec.rb +0 -49
  120. data/spec/acceptance/lib/util.rb +0 -163
  121. data/spec/acceptance/running_strings_generate.rb +0 -54
  122. data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
  123. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
  124. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
  125. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
  126. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
  127. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
  128. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
  129. data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
  130. data/spec/fixtures/unit/markdown/output.md +0 -508
  131. data/spec/fixtures/unit/markdown/output_with_plan.md +0 -542
  132. data/spec/spec_helper.rb +0 -46
  133. data/spec/spec_helper_acceptance.rb +0 -28
  134. data/spec/unit/puppet-strings/describe_spec.rb +0 -141
  135. data/spec/unit/puppet-strings/json_spec.rb +0 -283
  136. data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
  137. data/spec/unit/puppet-strings/markdown_spec.rb +0 -296
  138. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
  139. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -116
  140. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
  141. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
  142. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
  143. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
  144. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
  145. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -235
  146. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -295
  147. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -72
  148. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
  149. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
  150. data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
@@ -0,0 +1,67 @@
1
+ ### <a name="<%= link %>"></a>`<%= name %>`
2
+
3
+ #### `<%= signature %>`
4
+
5
+ <% if text -%>
6
+ <%= text %>
7
+
8
+ <% elsif summary -%>
9
+ <%= summary %>
10
+
11
+ <% else -%>
12
+ <%= "The #{name} function." %>
13
+
14
+ <% end -%>
15
+ <% if note -%>
16
+ * **Note** <%= note %>
17
+
18
+ <% end -%>
19
+ <% if return_type -%>
20
+ Returns: `<%= return_type %>`<% if return_val %> <%= return_val %><% end %>
21
+
22
+ <% end -%>
23
+ <% if raises -%>
24
+ Raises:
25
+ <% raises.each do |r| -%>
26
+ * <%= error_type(r[:text]) %> <%= error_text(r[:text]) %>
27
+ <% end -%>
28
+
29
+ <% end -%>
30
+ <% if examples -%>
31
+ ##### Examples
32
+
33
+ <% examples.each do |eg| -%>
34
+ ###### <%= eg[:name] %>
35
+
36
+ ```puppet
37
+ <%= eg[:text] %>
38
+ ```
39
+
40
+ <% end -%>
41
+ <% end -%>
42
+ <% if params -%>
43
+ <% params.each do |param| -%>
44
+ ##### `<%= param[:name] %>`
45
+
46
+ Data type: `<%= param[:types][0] %>`
47
+
48
+ <%= param[:text] %>
49
+
50
+ <% if options_for_param(param[:name]) -%>
51
+ Options:
52
+
53
+ <% options_for_param(param[:name]).each do |o| -%>
54
+ * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
55
+ <% end -%>
56
+
57
+ <% end -%>
58
+ <% if enums_for_param(param[:name]) -%>
59
+ Options:
60
+
61
+ <% enums_for_param(param[:name]).each do |e| -%>
62
+ * **<%= e[:opt_name] %>**: <%= e[:opt_text] %>
63
+ <% end -%>
64
+
65
+ <% end -%>
66
+ <% end -%>
67
+ <% end -%>
@@ -1,4 +1,4 @@
1
- ### <%= name %>
1
+ ### <a name="<%= link %>"></a>`<%= name %>`
2
2
 
3
3
  Type: <%= type %>
4
4
 
@@ -55,6 +55,7 @@ Returns: `<%= sig.return_type %>`<% if sig.return_val %> <%= sig.return_val %><%
55
55
  <% end -%>
56
56
  <% if raises -%>
57
57
  Raises:
58
+
58
59
  <% raises.each do |r| -%>
59
60
  * <%= error_type(r[:text]) %> <%= error_text(r[:text]) %>
60
61
  <% end -%>
@@ -87,6 +88,14 @@ Options:
87
88
  * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
88
89
  <% end -%>
89
90
 
91
+ <% end -%>
92
+ <% if sig.enums_for_param(param[:name]) -%>
93
+ Options:
94
+
95
+ <% sig.enums_for_param(param[:name]).each do |e| -%>
96
+ * **<%= e[:opt_name] %>**: <%= e[:opt_text] %>
97
+ <% end -%>
98
+
90
99
  <% end -%>
91
100
  <% end -%>
92
101
  <% end -%>
@@ -1,4 +1,4 @@
1
- ### <%= name %>
1
+ ### <a name="<%= link %>"></a>`<%= name %>`
2
2
 
3
3
  <% if text -%>
4
4
  <%= text %>
@@ -1,4 +1,4 @@
1
- ### <%= name %>
1
+ ### <a name="<%= link %>"></a>`<%= name %>`
2
2
 
3
3
  <% if text -%>
4
4
  <%= text %>
@@ -24,10 +24,10 @@
24
24
  * **See also**
25
25
  <% see.each do |sa| -%>
26
26
  <% if sa[:name] -%>
27
- <%= sa[:name] %>
27
+ <%= " * #{sa[:name]}" %>
28
28
  <% end -%>
29
29
  <% if sa[:text] -%>
30
- <%= sa[:text] %>
30
+ <%= " * #{sa[:text]}" %>
31
31
  <% end -%>
32
32
  <% end -%>
33
33
 
@@ -44,16 +44,16 @@
44
44
 
45
45
  <% end -%>
46
46
  <% end -%>
47
- <% if properties -%>
47
+ <% if properties_and_checks -%>
48
48
  #### Properties
49
49
 
50
50
  The following properties are available in the `<%= name %>` <%= @type %>.
51
51
 
52
- <% properties.each do |prop| -%>
52
+ <% properties_and_checks.each do |prop| -%>
53
53
  ##### `<%= prop[:name] %>`
54
54
 
55
55
  <% if prop[:values] -%>
56
- Valid values: <%= prop[:values].map { |value| value_string(value) }.join(', ') %>
56
+ Valid values: `<%= prop[:values].map { |value| value_string(value) }.join('`, `') %>`
57
57
 
58
58
  <% end -%>
59
59
  <% if prop[:isnamevar] -%>
@@ -61,7 +61,7 @@ namevar
61
61
 
62
62
  <% end -%>
63
63
  <% if prop[:aliases] -%>
64
- Aliases: <%= prop[:aliases].to_s.delete('{').delete('}') %>
64
+ Aliases: `<%= prop[:aliases].to_s.delete('{').delete('}') %>`
65
65
 
66
66
  <% end -%>
67
67
  <% if prop[:data_type] -%>
@@ -77,9 +77,17 @@ Options:
77
77
  * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
78
78
  <% end -%>
79
79
 
80
+ <% end -%>
81
+ <% if enums_for_param(prop[:name]) -%>
82
+ Options:
83
+
84
+ <% enums_for_param(prop[:name]).each do |e| -%>
85
+ * **<%= e[:opt_name] %>**: <%= e[:opt_text] %>
86
+ <% end -%>
87
+
80
88
  <% end -%>
81
89
  <% if prop[:default] -%>
82
- Default value: <%= prop[:default] %>
90
+ Default value: `<%= prop[:default] %>`
83
91
 
84
92
  <% end -%>
85
93
  <% end -%>
@@ -90,10 +98,14 @@ Default value: <%= prop[:default] %>
90
98
  The following parameters are available in the `<%= name %>` <%= @type %>.
91
99
 
92
100
  <% parameters.each do |param| -%>
93
- ##### `<%= param[:name] %>`
101
+ * [`<%= param[:name] %>`](#<%= param[:name] %>)
102
+ <% end -%>
103
+
104
+ <% parameters.each do |param| -%>
105
+ ##### <a name="<%= param[:name] %>"></a>`<%= param[:name] %>`
94
106
 
95
107
  <% if param[:values] -%>
96
- Valid values: <%= param[:values].map { |value| value_string(value) }.join(', ') %>
108
+ Valid values: `<%= param[:values].map { |value| value_string(value) }.join('`, `') %>`
97
109
 
98
110
  <% end -%>
99
111
  <% if param[:isnamevar] -%>
@@ -101,14 +113,16 @@ namevar
101
113
 
102
114
  <% end -%>
103
115
  <% if param[:aliases] -%>
104
- Aliases: <%= param[:aliases].to_s.delete('{').delete('}') %>
116
+ Aliases: `<%= param[:aliases].to_s.delete('{').delete('}') %>`
105
117
 
106
118
  <% end -%>
107
119
  <% if param[:data_type] -%>
108
120
  Data type: `<%= param[:data_type] %>`<%= "\n_\*this data type contains a regex that may not be accurately reflected in generated documentation_" if regex_in_data_type?(param[:data_type]) %>
109
121
 
110
122
  <% end -%>
111
- <%= param[:description] %>
123
+ <% if param[:description] -%>
124
+ <%= word_wrap(param[:description]) %>
125
+ <% end -%>
112
126
 
113
127
  <% if options_for_param(param[:name]) -%>
114
128
  Options:
@@ -117,9 +131,17 @@ Options:
117
131
  * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
118
132
  <% end -%>
119
133
 
134
+ <% end -%>
135
+ <% if enums_for_param(param[:name]) -%>
136
+ Options:
137
+
138
+ <% enums_for_param(param[:name]).each do |e| -%>
139
+ * **<%= e[:opt_name] %>**: <%= e[:opt_text] %>
140
+ <% end -%>
141
+
120
142
  <% end -%>
121
143
  <% if param[:default] -%>
122
- Default value: <%= value_string(param[:default]) %>
144
+ Default value: `<%= value_string(param[:default]) %>`
123
145
 
124
146
  <% end -%>
125
147
  <% if param[:required_features] -%>
@@ -1,25 +1,25 @@
1
1
  <% if group.length > 0 -%>
2
- **<%= group_name %>**
2
+ ### <%= group_name %>
3
3
 
4
4
  <% if priv -%>
5
- _Public <%= group_name %>_
5
+ #### Public <%= group_name %>
6
6
 
7
7
  <% group.each do |item| -%>
8
8
  <% unless item[:private] -%>
9
- * [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
9
+ * [`<%= item[:name] %>`](#<%= item[:link] %>)<% unless item[:desc].nil? || item[:desc].empty? %>: <%= item[:desc] %><% end %>
10
10
  <% end -%>
11
11
  <% end -%>
12
12
 
13
- _Private <%= group_name %>_
13
+ #### Private <%= group_name %>
14
14
 
15
15
  <% group.each do |item| -%>
16
16
  <% if item[:private] -%>
17
- * `<%= item[:name] %>`: <%= item[:desc] %>
17
+ * `<%= item[:name] %>`<% unless item[:desc].nil? || item[:desc].empty? %>: <%= item[:desc] %><% end %>
18
18
  <% end -%>
19
19
  <% end -%>
20
20
  <% else -%>
21
21
  <% group.each do |item| -%>
22
- * [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
22
+ * [`<%= item[:name] %>`](#<%= item[:link] %>)<% unless item[:desc].nil? || item[:desc].empty? %>: <%= item[:desc] %><% end %>
23
23
  <% end -%>
24
24
  <% end -%>
25
25
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Monkey patch URL decoding in object displays. Usually :: is interpreted as a
2
4
  # namespace, but this is disabled in our base object, and so instead gets
3
5
  # URL-encoded.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  require 'rake/tasklib'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings'
2
4
 
3
5
  # Implements the strings:generate task.
@@ -33,11 +35,12 @@ namespace :strings do
33
35
  end
34
36
  end
35
37
  end
38
+ # rubocop:enable Style/PreferredHashMethods
36
39
 
37
- [:json,:markdown].each { |format| parse_format_option(args, options, format) }
40
+ %i[json markdown].each { |format| parse_format_option(args, options, format) }
38
41
 
39
42
  warn('yard_args behavior is a little dodgy, use at your own risk') if args[:yard_args]
40
- options[:yard_args] = args[:yard_args].split if args.has_key? :yard_args
43
+ options[:yard_args] = args[:yard_args].split if args.key? :yard_args
41
44
 
42
45
  PuppetStrings.generate(patterns, options)
43
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/tasks'
2
4
 
3
5
  namespace :strings do
@@ -5,6 +7,7 @@ namespace :strings do
5
7
  task :checkout do
6
8
  if Dir.exist?('doc')
7
9
  fail "The 'doc' directory (#{File.expand_path('doc')}) is not a Git repository! Remove it and run the Rake task again." unless Dir.exist?('doc/.git')
10
+
8
11
  Dir.chdir('doc') do
9
12
  system 'git checkout gh-pages'
10
13
  system 'git pull --rebase origin gh-pages'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PuppetStrings
2
- VERSION = '2.2.0'.freeze
4
+ VERSION = '2.6.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yard'
2
4
 
3
5
  # Module for YARD related functionality.
@@ -11,6 +13,9 @@ module PuppetStrings::Yard
11
13
  # Sets up YARD for use with puppet-strings.
12
14
  # @return [void]
13
15
  def self.setup!
16
+ # Register our factory
17
+ YARD::Tags::Library.default_factory = PuppetStrings::Yard::Tags::Factory
18
+
14
19
  # Register the template path
15
20
  YARD::Templates::Engine.register_template_path(File.join(File.dirname(__FILE__), 'yard', 'templates'))
16
21
 
@@ -30,6 +35,9 @@ module PuppetStrings::Yard
30
35
  # Register the summary tag
31
36
  PuppetStrings::Yard::Tags::SummaryTag.register!
32
37
 
38
+ # Register the enum tag
39
+ PuppetStrings::Yard::Tags::EnumTag.register!
40
+
33
41
  # Ignore documentation on Puppet DSL calls
34
42
  # This prevents the YARD DSL parser from emitting warnings for Puppet's Ruby DSL
35
43
  YARD::Handlers::Ruby::DSLHandlerMethods::IGNORE_METHODS['create_function'] = true
@@ -46,6 +54,8 @@ class YARD::CLI::Yardoc
46
54
  :module,
47
55
  :class,
48
56
  :puppet_class,
57
+ :puppet_data_type,
58
+ :puppet_data_type_alias,
49
59
  :puppet_defined_type,
50
60
  :puppet_type,
51
61
  :puppet_provider,
@@ -64,6 +74,14 @@ class YARD::CLI::Stats
64
74
  output 'Puppet Classes', *type_statistics_all(:puppet_class)
65
75
  end
66
76
 
77
+ def stats_for_puppet_data_types
78
+ output 'Puppet Data Types', *type_statistics_all(:puppet_data_type)
79
+ end
80
+
81
+ def stats_for_puppet_data_type_aliases
82
+ output 'Puppet Data Type Aliases', *type_statistics_all(:puppet_data_type_alias)
83
+ end
84
+
67
85
  def stats_for_puppet_defined_types
68
86
  output 'Puppet Defined Types', *type_statistics_all(:puppet_defined_type)
69
87
  end
@@ -86,6 +104,7 @@ class YARD::CLI::Stats
86
104
 
87
105
  def stats_for_puppet_plans
88
106
  return unless PuppetStrings.puppet_5?
107
+
89
108
  output 'Puppet Plans', *type_statistics_all(:puppet_plan)
90
109
  end
91
110
 
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The module for custom YARD code objects.
2
4
  module PuppetStrings::Yard::CodeObjects
3
5
  require 'puppet-strings/yard/code_objects/class'
6
+ require 'puppet-strings/yard/code_objects/data_type'
7
+ require 'puppet-strings/yard/code_objects/data_type_alias'
4
8
  require 'puppet-strings/yard/code_objects/defined_type'
5
9
  require 'puppet-strings/yard/code_objects/type'
6
10
  require 'puppet-strings/yard/code_objects/provider'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Implements the base code object.
2
4
  class PuppetStrings::Yard::CodeObjects::Base < YARD::CodeObjects::NamespaceObject
3
5
  # Allocates a new code object.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet classes.
@@ -51,9 +53,9 @@ class PuppetStrings::Yard::CodeObjects::Class < PuppetStrings::Yard::CodeObjects
51
53
  hash[:line] = line
52
54
  hash[:inherits] = statement.parent_class if statement.parent_class
53
55
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
54
- defaults = Hash[*parameters.select{ |p| !p[1].nil? }.flatten]
55
- hash[:defaults] = defaults unless defaults.empty?
56
- hash[:source] = source unless source && source.empty?
56
+ defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
57
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
58
+ hash[:source] = source unless source.nil? || source.empty?
57
59
  hash
58
60
  end
59
61
  end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'puppet-strings/yard/code_objects/group'
4
+ require 'puppet-strings/yard/util'
5
+
6
+ # Implements the group for Puppet DataTypes.
7
+ class PuppetStrings::Yard::CodeObjects::DataTypes < PuppetStrings::Yard::CodeObjects::Group
8
+ # Gets the singleton instance of the group.
9
+ # @return Returns the singleton instance of the group.
10
+ def self.instance
11
+ super(:puppet_data_types)
12
+ end
13
+
14
+ # Gets the display name of the group.
15
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
16
+ # @return [String] Returns the display name of the group.
17
+ def name(prefix = false)
18
+ 'Puppet Data Types'
19
+ end
20
+ end
21
+
22
+ # Implements the Puppet DataType code object.
23
+ class PuppetStrings::Yard::CodeObjects::DataType < PuppetStrings::Yard::CodeObjects::Base
24
+ # Initializes a Puppet class code object.
25
+ # @param [String] The name of the Data Type
26
+ # @return [void]
27
+ def initialize(name)
28
+ super(PuppetStrings::Yard::CodeObjects::DataTypes.instance, name)
29
+ @defaults = {}
30
+ end
31
+
32
+ # Gets the type of the code object.
33
+ # @return Returns the type of the code object.
34
+ def type
35
+ :puppet_data_type
36
+ end
37
+
38
+ # Gets the source of the code object.
39
+ # @return Returns the source of the code object.
40
+ def source
41
+ # Not implemented, but would be nice!
42
+ nil
43
+ end
44
+
45
+ def add_parameter(name, type, default)
46
+ tag = docstring.tags(:param).find { |item| item.name == name }
47
+ if tag.nil?
48
+ tag = YARD::Tags::Tag.new(:param, '', nil, name)
49
+ docstring.add_tag(tag)
50
+ end
51
+ type = [type] unless type.is_a?(Array)
52
+ tag.types = type if tag.types.nil?
53
+ set_parameter_default(name, default)
54
+ end
55
+
56
+ def set_parameter_default(param_name, default)
57
+ defaults.delete(param_name)
58
+ defaults[param_name] = default unless default.nil?
59
+ end
60
+
61
+ def parameters
62
+ docstring.tags(:param).map { |tag| [tag.name, defaults[tag.name]] }
63
+ end
64
+
65
+ def add_function(name, return_type, parameter_types)
66
+ meth_obj = YARD::CodeObjects::MethodObject.new(self, name, :class)
67
+
68
+ # Add return tag
69
+ meth_obj.add_tag(YARD::Tags::Tag.new(:return, '', return_type))
70
+
71
+ # Add parameters
72
+ parameter_types.each_with_index do |param_type, index|
73
+ meth_obj.add_tag(YARD::Tags::Tag.new(:param, '', [param_type], "param#{index + 1}"))
74
+ end
75
+
76
+ self.meths << meth_obj
77
+ end
78
+
79
+ def functions
80
+ meths
81
+ end
82
+
83
+ # Converts the code object to a hash representation.
84
+ # @return [Hash] Returns a hash representation of the code object.
85
+ def to_hash
86
+ hash = {}
87
+ hash[:name] = name
88
+ hash[:file] = file
89
+ hash[:line] = line
90
+ hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example])
91
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
92
+ hash[:source] = source unless source.nil? || source.empty?
93
+ hash[:functions] = functions.map do |func|
94
+ {
95
+ name: func.name,
96
+ signature: func.signature,
97
+ docstring: PuppetStrings::Yard::Util.docstring_to_hash(func.docstring, %i[param option enum return example])
98
+ }
99
+ end
100
+ hash
101
+ end
102
+ end