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
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (C) 2014 Puppet Labs Inc
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,416 @@
1
+ Puppet Strings
2
+ ==============
3
+ [![Build Status](https://travis-ci.org/puppetlabs/puppet-strings.png?branch=master)](https://travis-ci.org/puppetlabs/puppet-strings) [![Gem Version](https://badge.fury.io/rb/puppet-strings.svg)](https://badge.fury.io/rb/puppet-strings)
4
+
5
+ A Puppet command built on [YARD](http://yardoc.org/).
6
+
7
+ Puppet Strings generates HTML documentation for Puppet extensions written in Puppet and Ruby.
8
+
9
+ This tool will eventually place the existing `puppet doc` command once feature parity has been achieved.
10
+
11
+ | | |
12
+ | -------------- |---------------------------------------------------------------- |
13
+ | *Code* | [GitHub][repo] |
14
+ | *Issues* | [Puppet JIRA Tracker][JIRA] |
15
+ | *License* | [Apache 2.0][LICENSE] |
16
+ | *Change log* | [CHANGELOG.md][changelog] |
17
+ | *Contributing* | [CONTRIBUTING.md][contributing] and [COMMITTERS.md][committers] |
18
+
19
+ [repo]: https://github.com/puppetlabs/puppet-strings
20
+ [JIRA]: https://tickets.puppetlabs.com/browse/PDOC
21
+ [LICENSE]: https://github.com/puppetlabs/puppet-strings/blob/master/LICENSE
22
+ [changelog]: https://github.com/puppetlabs/puppet-strings/blob/master/CHANGELOG.md
23
+ [contributing]: https://github.com/puppetlabs/puppet-strings/blob/master/CONTRIBUTING.md
24
+ [committers]: https://github.com/puppetlabs/puppet-strings/blob/master/COMMITTERS.md
25
+
26
+ Requirements
27
+ ------------
28
+
29
+ In order to run strings you need to have the following software installed:
30
+
31
+ * Ruby 1.9.3 or newer
32
+ * Puppet 3.7 or newer
33
+ * The `yard` Ruby gem
34
+
35
+ Note that a few extra steps are necessary to install puppet-strings with Puppet Enterprise 3.8.
36
+
37
+ Installing the YARD Gem
38
+ -----------------------
39
+
40
+ The easiest way to install the `yard` gem is with Puppet itself:
41
+
42
+ For Puppet 4.x:
43
+ ```
44
+ $ puppet resource package yard provider=puppet_gem
45
+ ```
46
+
47
+ For Puppet 3.x:
48
+ ```
49
+ $ puppet resource package yard provider=gem
50
+ ```
51
+
52
+ For Puppet Enterprise 3.8:
53
+ ```
54
+ GEM_HOME=/opt/puppet/lib/ruby/gems/1.9.1 puppet resource package yard provider=gem
55
+ ```
56
+
57
+ Installing the redcarpet Gem (Puppet Enterprise 3.8 only)
58
+ -------------------------
59
+ ```
60
+ GEM_HOME=/opt/puppet/lib/ruby/gems/1.9.1 puppet resource package redcarpet provider=gem
61
+ ```
62
+
63
+ Installing Puppet Strings
64
+ -------------------------
65
+
66
+ Strings can be installed using the [puppet-strings](https://rubygems.org/gems/puppet-strings) gem.
67
+
68
+ To ensure it is installed in right place, it is best to install it using Puppet:
69
+
70
+ For Puppet 4.x:
71
+ ```
72
+ $ puppet resource package puppet-strings provider=puppet_gem
73
+ ```
74
+
75
+ For Puppet 3.x:
76
+ ```
77
+ $ puppet resource package puppet-strings provider=gem
78
+ ```
79
+
80
+ For Puppet Enterprise 3.8:
81
+ ```
82
+ GEM_HOME=/opt/puppet/lib/ruby/gems/1.9.1 puppet resource package puppet-strings provider=gem
83
+ ```
84
+
85
+ Running Puppet Strings
86
+ ----------------------
87
+
88
+ Once strings has been installed you can document a puppet module:
89
+
90
+ ```
91
+ $ cd /path/to/module
92
+ $ puppet strings
93
+ ```
94
+
95
+ This processes `README` and all Puppet and Ruby source files under the `./manifests/`, `./functions/`, and `./lib/`
96
+ directories by default and creates HTML documentation under the `./doc/` directory.
97
+
98
+ To document specific files:
99
+
100
+ ```
101
+ $ puppet strings generate first.pp second.pp ...
102
+ ```
103
+
104
+ To document specific directories:
105
+
106
+ ```
107
+ $ puppet strings generate 'modules/foo/lib/**/*.rb' 'modules/foo/manifests/**/*.pp' 'modules/foo/functions/**/*.pp' ...
108
+ ```
109
+
110
+ Strings can emit JSON documenting the Puppet extensions:
111
+
112
+ ```
113
+ $ puppet strings generate --emit-json documentation.json
114
+ ```
115
+
116
+ It can also print the JSON to stdout:
117
+
118
+ ```
119
+ $ puppet strings generate --emit-json-stdout
120
+ ```
121
+
122
+ The schema for the JSON output is [documented here](https://github.com/puppetlabs/puppet-strings/blob/master/JSON.md).
123
+
124
+ In addition to generating a directory full of HTML, you can also serve up documentation for all your modules using the `server` action:
125
+
126
+ ```
127
+ $ puppet strings server
128
+ ```
129
+
130
+ YARD Options
131
+ ------------
132
+
133
+ YARD options (see `yard help doc`) are supported in a `.yardopts` file in the same directory where `puppet strings` is run.
134
+
135
+ Puppet Strings automatically sets the `markup` option to `markdown`, allowing your documentation strings to be in Markdown format.
136
+
137
+ Documenting Puppet Extensions
138
+ -----------------------------
139
+
140
+ ### Puppet Classes / Defined Types
141
+
142
+ To document Puppet classes and defined types, use a YARD docstring before the class or defined type definition:
143
+
144
+ ```puppet
145
+ # An example class.
146
+ #
147
+ # This is an example of how to document a Puppet class
148
+ #
149
+ # @example Declaring the class
150
+ # include example
151
+ #
152
+ # @param first The first parameter for this class
153
+ # @param second The second paramter for this class
154
+ class example_class(
155
+ String $first = $example::params::first_arg,
156
+ Integer $second = $example::params::second_arg,
157
+ ) inherits example::params {
158
+ # ...
159
+ }
160
+
161
+ # An example defined type.
162
+ #
163
+ # This is an example of how to document a defined type.
164
+ # @param ports The array of port numbers to use.
165
+ define example_type(
166
+ Array[Integer] $ports = []
167
+ ) {
168
+ # ...
169
+ }
170
+ ```
171
+
172
+ ***Note: unlike Ruby, Puppet 4.x is a typed language; Puppet Strings will automatically use the parameter type information to
173
+ document the parameter types. A warning will be emitted if you document a parameter's type for a parameter that has a Puppet type specifier.***
174
+
175
+ ### Resource Types
176
+
177
+ To document custom resource types and their parameters/properties, use the `desc` method or assign a value to the `doc` attribute:
178
+
179
+ ```ruby
180
+ Puppet::Type.newtype(:example) do
181
+ desc <<-DESC
182
+ An example resource type.
183
+ @example Using the type.
184
+ example { foo:
185
+ param => 'hi'
186
+ }
187
+ DESC
188
+
189
+ newparam(:param) do
190
+ desc 'An example parameter.'
191
+ # ...
192
+ end
193
+
194
+ newproperty(:prop) do
195
+ desc 'An example property.'
196
+ #...
197
+ end
198
+
199
+ # ...
200
+ end
201
+ ```
202
+
203
+ Puppet Strings documents this way to preserve backwards compatibility with `puppet doc` and existing resource types.
204
+
205
+ ***Note: Puppet Strings does not evaluate your Ruby code, so only certain static expressions are supported.***
206
+
207
+ To document parameters and properties that are dynamically created, use the `#@!puppet.type.param` and `#@!puppet.type.property`
208
+ directives before the `newtype` call:
209
+
210
+ ```ruby
211
+ # @!puppet.type.param [value1, value2, value3] my_param Documentation for a dynamic parameter.
212
+ # @!puppet.type.property [foo, bar, baz] my_prop Documentation for a dynamic property.
213
+ Puppet::Type.newtype(:example) do
214
+ #...
215
+ end
216
+ ```
217
+
218
+ ### Providers
219
+
220
+ To document providers, use the `desc` method or assign a value to the `doc` attribute:
221
+
222
+ ```ruby
223
+ Puppet::Type.type(:example).provide :platform do
224
+ desc 'An example provider.'
225
+
226
+ # ...
227
+ end
228
+ ```
229
+
230
+ Puppet Strings documents this way to preserve backwards compatibility with `puppet doc` and existing resource types.
231
+
232
+ ***Note: Puppet Strings does not evaluate your Ruby code, so only certain static expressions are supported.***
233
+
234
+ ### Functions
235
+
236
+ Puppet Strings supports three different ways of defining a function in Puppet: with the Puppet 3.x API, Puppet 4.X API,
237
+ and in the Puppet language itself.
238
+
239
+ #### Puppet 3.x Functions
240
+
241
+ To document a function in the Puppet 3.x API, use the `doc` option to `newfunction`:
242
+
243
+ ```ruby
244
+ Puppet::Parser::Functions.newfunction(:example, doc: <<-DOC
245
+ Documentation for an example 3.x function.
246
+ @param [String] param1 The first parameter.
247
+ @param [Integer] param2 The second parameter.
248
+ @return [Undef]
249
+ @example Calling the function.
250
+ example('hi', 10)
251
+ DOC
252
+ ) do |*args|
253
+ #...
254
+ end
255
+ ```
256
+
257
+ ***Note: if parameter types are omitted, a default of the `Any` Puppet type will be used.***
258
+
259
+ #### Puppet 4.x Functions
260
+
261
+ To document a function in the Puppet 4.x API, use a YARD docstring before the `create_function` call and any `dispatch`
262
+ calls:
263
+
264
+ ```ruby
265
+ # An example 4.x function.
266
+ Puppet::Functions.create_function(:example) do
267
+ # @param first The first parameter.
268
+ # @param second The second parameter.
269
+ # @return [String] Returns a string.
270
+ # @example Calling the function
271
+ # example('hi', 10)
272
+ dispatch :example do
273
+ param 'String', :first
274
+ param 'Integer', :second
275
+ end
276
+
277
+ # ...
278
+ end
279
+ ```
280
+
281
+ ***Note: Puppet Strings will automatically use the parameter type information from the `dispatch` block to document
282
+ the parameter types. Only document your parameter types when the Puppet 4.x function contains no `dispatch` calls.***
283
+
284
+ If the Puppet 4.x function contains multiple `dispatch` calls, Puppet Strings will automatically create `overload` tags
285
+ to describe the function's overloads:
286
+
287
+ ```ruby
288
+ # An example 4.x function.
289
+ Puppet::Functions.create_function(:example) do
290
+ # Overload by string.
291
+ # @param first The first parameter.
292
+ # @return [String] Returns a string.
293
+ # @example Calling the function
294
+ # example('hi')
295
+ dispatch :example_string do
296
+ param 'String', :first
297
+ end
298
+
299
+ # Overload by integer.
300
+ # @param first The first parameter.
301
+ # @return [Integer] Returns an integer.
302
+ # @example Calling the function
303
+ # example(10)
304
+ dispatch :example_integer do
305
+ param 'Integer', :first
306
+ end
307
+
308
+ # ...
309
+ ```
310
+
311
+ The resulting HTML for this example function will document both `example(String $first)` and `example(Integer $first)`.
312
+
313
+ #### Puppet Language Functions
314
+
315
+ To document Puppet functions written in the Puppet language, use a YARD docstring before the function definition:
316
+
317
+ ```puppet
318
+ # An example function written in Pupppet.
319
+ # @param name The name to say hello to.
320
+ # @return [String] Returns a string.
321
+ # @example Calling the function
322
+ # example('world')
323
+ function example(String $name) {
324
+ "hello $name"
325
+ }
326
+ ```
327
+
328
+ ***Note: Puppet Strings will automatically use the parameter type information from the function's parameter list to document
329
+ the parameter types.***
330
+
331
+ Additional Resources
332
+ --------------------
333
+
334
+ Here are a few other good resources for getting started with documentation:
335
+
336
+ * [Module README Template](https://docs.puppet.com/puppet/latest/reference/modules_documentation.html)
337
+ * [YARD Getting Started Guide](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
338
+ * [YARD Tags Overview](http://www.rubydoc.info/gems/yard/file/docs/Tags.md)
339
+
340
+ Rake Tasks
341
+ ----------
342
+
343
+ Puppet Strings comes with two rake tasks: `strings:generate` and `strings:gh_pages:update` available in `puppet-strings/tasks`.
344
+
345
+ Add the following to your Gemfile to use `puppet-strings`:
346
+
347
+ ```ruby
348
+ gem 'puppet-strings', :git => 'https://github.com/puppetlabs/puppet-strings.git'
349
+ ```
350
+
351
+ In your `Rakefile`, add the following to use the `puppet-strings` tasks:
352
+
353
+ ```ruby
354
+ require 'puppet-strings/tasks'
355
+ ```
356
+
357
+ The `strings:generate` task can be used to generate documentation:
358
+
359
+ ```
360
+ $ rake strings:generate
361
+ ```
362
+
363
+ The task accepts the following parameters:
364
+
365
+ * `patterns`: the search patterns to use for finding files to document (defaults to `manifests/**/*.pp functions/**/*.pp types/**/*.pp lib/**/*.rb`).
366
+ * `debug`: enables debug output when set to `true`.
367
+ * `backtrace`: enables backtraces for errors when set to `true`.
368
+ * `markup`: the markup language to use (defaults to `markdown`).
369
+ * `yard_args`: additional arguments to pass to YARD.
370
+
371
+ An example of passing arguments to the `strings:generate` Rake task:
372
+
373
+ ```
374
+ $ rake strings:generate\['**/*{.pp\,.rb}, true, true, markdown, --readme README.md']
375
+ ```
376
+
377
+ The `strings:gh_pages:update` task will generate your Puppet Strings documentation to be made available via [GitHub Pages](https://pages.github.com/). It will:
378
+
379
+ 1. Create a `doc` directory in the root of your project
380
+ 2. Check out the `gh-pages` branch of the current repository in the `doc` directory (it will create a branch if one does not already exist)
381
+ 3. Generate strings documentation using the `strings:generate` task
382
+ 4. Commit the changes and push them to the `gh-pages` branch **with the `--force` flag**
383
+
384
+ This task aims to keep the `gh-pages` branch up to date with the current code and uses the `-f` flag when pushing to the `gh-pages` branch.
385
+ ***Please note this operation will be destructive if not used properly.***
386
+
387
+ Developing and Contributing
388
+ ---------------------------
389
+
390
+ We love contributions from the community!
391
+
392
+ If you'd like to contribute to the strings module, check out [CONTRIBUTING.md](https://github.com/puppetlabs/puppet-strings/blob/master/CONTRIBUTING.md) to get information on the contribution process.
393
+
394
+ Running Specs
395
+ -------------
396
+
397
+ If you plan on developing features or fixing bugs in Puppet Strings, it is essential that you run specs before opening a pull request.
398
+
399
+ To run specs, simply execute the `spec` rake task:
400
+
401
+ $ bundle install --path .bundle/gems
402
+ $ bundle exec rake spec
403
+
404
+ Support
405
+ -------
406
+
407
+ Please log tickets and issues at our [JIRA tracker][JIRA]. A [mailing list](https://groups.google.com/forum/?fromgroups#!forum/puppet-users)
408
+ is available for asking questions and getting help from others.
409
+
410
+ There is also an active #puppet channel on the Freenode IRC network.
411
+
412
+ We use semantic version numbers for our releases, and recommend that users stay as up-to-date as possible by upgrading to
413
+ patch releases and minor releases as they become available.
414
+
415
+ Bug fixes and ongoing development will occur in minor releases for the current major version.
416
+ Security fixes will be ported to a previous major version on a best-effort basis, until the previous major version is no longer maintained.
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'puppetlabs_spec_helper/rake_tasks'
3
+ require 'puppet-lint/tasks/puppet-lint'
4
+
5
+ # Add our own tasks
6
+ require 'puppet-strings/tasks'
7
+
8
+ PuppetLint.configuration.send('disable_80chars')
9
+ PuppetLint.configuration.ignore_paths = %w(acceptance/**/*.pp spec/**/*.pp pkg/**/*.pp)
10
+
11
+ desc 'Validate Ruby source files and ERB templates.'
12
+ task :validate do
13
+ Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
14
+ sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
15
+ end
16
+ Dir['lib/puppet-strings/yard/templates/**/*.erb'].each do |template|
17
+ sh "erb -P -x -T '-' #{template} | ruby -c"
18
+ end
19
+ end
20
+
21
+ task :acceptance do
22
+ require 'beaker-hostgenerator'
23
+
24
+ target = ENV['platform']
25
+ if ! target
26
+ STDERR.puts 'TEST_TARGET environment variable is not set'
27
+ STDERR.puts 'setting to default value of "centos7-64ma".'
28
+ target = 'centos7-64ma'
29
+ ENV['platform'] = target
30
+ end
31
+
32
+ cli = BeakerHostGenerator::CLI.new([target])
33
+ nodeset_dir = 'spec/acceptance/nodesets'
34
+ nodeset = "#{nodeset_dir}/#{target}.yml"
35
+ FileUtils.mkdir_p(nodeset_dir)
36
+ File.open(nodeset, 'w') do |fh|
37
+ fh.print(cli.execute)
38
+ end
39
+ puts nodeset
40
+ sh 'gem build puppet-strings.gemspec'
41
+ sh 'puppet module build spec/fixtures/acceptance/modules/test'
42
+ sh "BEAKER_set=#{ENV['platform']} rspec spec/acceptance/*.rb"
43
+ end
44
+
45
+ task(:rubocop) do
46
+ require 'rubocop'
47
+ cli = RuboCop::CLI.new
48
+ cli.run(%w(-D -f s))
49
+ end