puppet-strings 0.99.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/Gemfile +7 -6
  4. data/JSON.md +193 -20
  5. data/README.md +231 -140
  6. data/lib/puppet-strings/json.rb +19 -10
  7. data/lib/puppet-strings/tasks/gh_pages.rb +15 -4
  8. data/lib/puppet-strings/yard/code_objects/function.rb +13 -3
  9. data/lib/puppet-strings/yard/code_objects/provider.rb +5 -6
  10. data/lib/puppet-strings/yard/code_objects/type.rb +2 -1
  11. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +9 -4
  12. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +13 -4
  13. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +11 -6
  14. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +3 -3
  15. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +8 -0
  16. data/lib/puppet-strings/yard/tags/overload_tag.rb +2 -2
  17. data/lib/puppet-strings/yard/templates/default/fulldoc/html/css/common.css +8 -0
  18. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/collection.erb +9 -2
  19. data/lib/puppet-strings/yard/templates/default/tags/html/puppet_overload.erb +1 -1
  20. data/lib/puppet-strings/yard/util.rb +17 -0
  21. data/spec/acceptance/emit_json_options.rb +15 -1
  22. data/spec/fixtures/unit/json/output.json +220 -9
  23. data/spec/fixtures/unit/json/output_without_puppet_function.json +179 -8
  24. data/spec/spec_helper.rb +3 -0
  25. data/spec/unit/puppet-strings/json_spec.rb +15 -4
  26. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +72 -0
  27. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +44 -0
  28. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +20 -2
  29. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +25 -1
  30. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +38 -0
  31. data/spec/unit/puppet-strings/yard/util_spec.rb +31 -0
  32. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6a68c372004eb1cf650ae8542c16dd019614ec1
4
- data.tar.gz: b4e29585c10fa54c4ad5a141a0c04ac22f642739
3
+ metadata.gz: 2beba5e6c9153efb0208b8dd2fe19eb0ae1ea589
4
+ data.tar.gz: f64ddfa0a74a5aeef8e525cbb59512888dd6bc2f
5
5
  SHA512:
6
- metadata.gz: 8e2d046b43f397bd7f6580e7312edb4f1a7e58de320927af653bcf2c0f830b4260a0473616c8817f98561cf38ea997951ebe96b1697e4507a3041546168a9d28
7
- data.tar.gz: c5828dc16270f1e2a51f77ff2be199c322b2c5d7e95eb72178bf9151998b0e804ac1efde40e22c279f3541b1e3fb50c11fa7b2c43c2bbcd54c07169f4cf71385
6
+ metadata.gz: 144215672c483f72a13b23897613fdf7440e6c6ce4d4310b407d7192a889037e58a1bc38a4a9d40b3fbf121c91bde7ccca2e126a374e91828a768c8a69b04405
7
+ data.tar.gz: 1e3525e0d4689fee040d12c9dac44f6184803d49327aa6707d18d64d641543deea47e526adf38c5a3af2dab4da6c1e46f86612c52fe747bbadabd4a71102b7e6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ##2016-11-28 - Release 1.0.0
2
+
3
+ ###Summary
4
+
5
+ This release fixes up minor bugs from the 0.99.0 release and modifies the JSON schema for Puppet functions.
6
+
7
+ All related tickets can be found under the [PDOC](https://tickets.puppetlabs.com/browse/PDOC) JIRA project with the fix version of [1.0.0](https://tickets.puppetlabs.com/issues/?filter=23607).
8
+
9
+ ###Features
10
+ - The JSON schema for Puppet functions has been altered to include a new 'signatures' top-level key **(PDOC-125)**
11
+ - Includes information about all function signatures (overloads). Existing overload key format has been preserved.
12
+ - Reworked README for enhanced clarity **(PDOC-133)**
13
+
14
+ ###BugFixes
15
+ - Fixed an issue where the search box in the code navigator overlapped list items below it **(PDOC-93)**
16
+ - Strings can now handle multiple `defaultfor` calls in Puppet providers **(PDOC-95)**
17
+ - Fixed an issue preventing the generated \_index.html file from being uploaded to GitHub pages via the gh_pages task **(PDOC-120)**
18
+ - Fixed several issues with String's handling of Puppet 3.x and 4.x function return types **(PDOC-135)**, **(PDOC-136)**
19
+ - Fixed an issue where String's didn't properly parse overloads if no summary description was provided **(PDOC-129)**
20
+ - Strings now correctly handles Puppet 3.x functions when the `newfunction` call is on a newline **(PDOC-122)**
21
+ - Fixed an issue where certain Ruby string constructs were incompletely stripped from some docstrings **(PDOC-126)**
22
+ - Hanging indents from type feature descriptions are now properly stripped **(PDOC-127)**
23
+
1
24
  ##2016-10-10 - Release 0.99.0
2
25
 
3
26
  ###Summary
data/Gemfile CHANGED
@@ -6,12 +6,10 @@ gem 'rgen'
6
6
  gem 'redcarpet'
7
7
  gem 'yard', '~> 0.9.5'
8
8
 
9
- puppetversion = ENV['PUPPET_VERSION']
10
-
11
- if puppetversion
12
- gem 'puppet', puppetversion
9
+ if ENV['PUPPET_GEM_VERSION']
10
+ gem 'puppet', ENV['PUPPET_GEM_VERSION'], :require => false
13
11
  else
14
- gem 'puppet'
12
+ gem 'puppet', :require => false
15
13
  end
16
14
 
17
15
  group :test do
@@ -19,7 +17,6 @@ group :test do
19
17
  gem 'mocha'
20
18
  gem 'puppetlabs_spec_helper'
21
19
  gem 'serverspec'
22
- gem 'rubocop', '~> 0.41.0'
23
20
  end
24
21
 
25
22
  group :acceptance do
@@ -36,3 +33,7 @@ group :development do
36
33
  gem 'pry-byebug'
37
34
  end
38
35
  end
36
+
37
+ gem 'json', '<= 1.8' if RUBY_VERSION < '2.0.0'
38
+ gem 'json_pure', '<= 2.0.1' if RUBY_VERSION < '2.0.0'
39
+ gem 'rubocop' if RUBY_VERSION >= '2.0.0'
data/JSON.md CHANGED
@@ -3,7 +3,7 @@ Puppet Strings JSON Data
3
3
 
4
4
  Puppet Strings has two flags to the `generate` action that can be used to emit JSON data:
5
5
 
6
- * `--emit-json <file>`: Emits the JSON data to the given file.
6
+ * `--emit-json <file>`: Emits the JSON data to the given file.
7
7
  * `--emit-json-stdout`: Emits the JSON data to STDOUT.
8
8
 
9
9
  Document Schema
@@ -100,13 +100,13 @@ Each entry in the `providers` list is an object with the following attributes:
100
100
  | Attribute Key | Description |
101
101
  | ------------- | ---------------------------------------------------- |
102
102
  | name | The name of the provider. |
103
- | type_name | The name of the resource type of the provider. |
103
+ | type_name | The name of the resource type of the provider. |
104
104
  | file | The file defining the provider. |
105
105
  | line | The line where the provider is defined. |
106
106
  | docstring | The *DocString* object for the provider (see below). |
107
107
  | confines | The string map of confines for the provider. |
108
108
  | features | The list of features implemented by the provider. |
109
- | defaults | The string map of "default for" for the provider. |
109
+ | defaults | The list of lists of "default for" for the provider. |
110
110
  | commands | The string map of commands for the provider. |
111
111
 
112
112
  Puppet Functions
@@ -114,23 +114,38 @@ Puppet Functions
114
114
 
115
115
  Each entry in the `puppet_functions` list is an object with the following attributes:
116
116
 
117
- | Attribute Key | Description |
118
- | ------------- | ---------------------------------------------------- |
119
- | name | The name of the function. |
120
- | file | The file defining the provider. |
121
- | line | The line where the provider is defined. |
122
- | type | The function type (e.g. ruby3x, ruby4x, puppet). |
123
- | signature | The Puppet signature of the function (no overloads). |
124
- | docstring | The *DocString* object for the function (see below). |
125
- | defaults | The map of parameter names to default values. |
126
- | source | The source code for the function. |
117
+ | Attribute Key | Description |
118
+ | ------------- | ----------------------------------------------------------------------------- |
119
+ | name | The name of the function. |
120
+ | file | The file defining the provider. |
121
+ | line | The line where the provider is defined. |
122
+ | type | The function type (e.g. ruby3x, ruby4x, puppet). |
123
+ | signatures | A list of Puppet signatures of the function, including overloads if present. |
124
+ | docstring | The *DocString* object for the function (see below). |
125
+ | defaults | The map of parameter names to default values. |
126
+ | source | The source code for the function. |
127
+
128
+ Signature Objects
129
+ -----------------
130
+
131
+ The `signatures` key is a function-specific list containing an object for each signature of a
132
+ function. Each object includes the `signature` itself, as well as each of its `param` and `return`
133
+ tags. Puppet 4.x functions with overloads will contain multiple signatures, while other function
134
+ types will contain only one.
135
+
136
+ Each signature is represented as an object with the following attributes:
137
+
138
+ | Attribute Key | Description |
139
+ | ------------- | -------------------------------------------------------------------------------------------------- |
140
+ | signature | The signature of the function. |
141
+ | docstring | The *DocString* object describing the signature, which includes `text`, `param` and `return` tags. |
127
142
 
128
143
  DocString Objects
129
144
  -----------------
130
145
 
131
146
  For the above types, their docstrings are represented as an object with the following attributes:
132
147
 
133
- | Attribute Key | Description DocString |
148
+ | Attribute Key | Description |
134
149
  | ------------- | --------------------------------------------------- |
135
150
  | text | The textual part of the DocString. |
136
151
  | tags | The array of tag objects, if any are present. |
@@ -327,9 +342,24 @@ An example JSON document describing a Puppet class, defined type, resource type,
327
342
  "implements_some_feature",
328
343
  "some_other_feature"
329
344
  ],
330
- "defaults": {
331
- "kernel": "Linux"
332
- },
345
+ "defaults": [
346
+ [
347
+ [
348
+ "kernel",
349
+ "Linux"
350
+ ]
351
+ ],
352
+ [
353
+ [
354
+ "osfamily",
355
+ "RedHat",
356
+ ],
357
+ [
358
+ "operatingsystemmajrelease",
359
+ "7"
360
+ ]
361
+ ]
362
+ ],
333
363
  "commands": {
334
364
  "foo": "/usr/bin/foo"
335
365
  }
@@ -341,7 +371,47 @@ An example JSON document describing a Puppet class, defined type, resource type,
341
371
  "file": "site.pp",
342
372
  "line": 20,
343
373
  "type": "puppet",
344
- "signature": "func(Integer $param1, Any $param2, String $param3 = hi)",
374
+ "signatures": [
375
+ {
376
+ "signature": "func(Integer $param1, Any $param2, String $param3 = hi)",
377
+ "docstring": {
378
+ "text": "A simple function.",
379
+ "tags": [
380
+ {
381
+ "tag_name": "param",
382
+ "text": "First param.",
383
+ "types": [
384
+ "Integer"
385
+ ],
386
+ "name": "param1"
387
+ },
388
+ {
389
+ "tag_name": "param",
390
+ "text": "Second param.",
391
+ "types": [
392
+ "Any"
393
+ ],
394
+ "name": "param2"
395
+ },
396
+ {
397
+ "tag_name": "param",
398
+ "text": "Third param.",
399
+ "types": [
400
+ "String"
401
+ ],
402
+ "name": "param3"
403
+ },
404
+ {
405
+ "tag_name": "return",
406
+ "text": "Returns nothing.",
407
+ "types": [
408
+ "Undef"
409
+ ]
410
+ }
411
+ ]
412
+ }
413
+ }
414
+ ],
345
415
  "docstring": {
346
416
  "text": "A simple function.",
347
417
  "tags": [
@@ -388,7 +458,39 @@ An example JSON document describing a Puppet class, defined type, resource type,
388
458
  "file": "func3x.rb",
389
459
  "line": 1,
390
460
  "type": "ruby3x",
391
- "signature": "func3x(String $first, Any $second)",
461
+ "signatures": [
462
+ {
463
+ "signature": "func3x(String $first, Any $second)",
464
+ "docstring": {
465
+ "text": "An example 3.x function.",
466
+ "tags": [
467
+ {
468
+ "tag_name": "param",
469
+ "text": "The first parameter.",
470
+ "types": [
471
+ "String"
472
+ ],
473
+ "name": "first"
474
+ },
475
+ {
476
+ "tag_name": "param",
477
+ "text": "The second parameter.",
478
+ "types": [
479
+ "Any"
480
+ ],
481
+ "name": "second"
482
+ },
483
+ {
484
+ "tag_name": "return",
485
+ "text": "Returns nothing.",
486
+ "types": [
487
+ "Undef"
488
+ ]
489
+ }
490
+ ]
491
+ }
492
+ }
493
+ ],
392
494
  "docstring": {
393
495
  "text": "An example 3.x function.",
394
496
  "tags": [
@@ -424,6 +526,78 @@ An example JSON document describing a Puppet class, defined type, resource type,
424
526
  "file": "func4x.rb",
425
527
  "line": 11,
426
528
  "type": "ruby4x",
529
+ "signatures": [
530
+ {
531
+ "signature": "func4x(Integer $param1, Any $param2, Optional[Array[String]] $param3)",
532
+ "docstring": {
533
+ "text": "The first overload.",
534
+ "tags": [
535
+ {
536
+ "tag_name": "param",
537
+ "text": "The first parameter.",
538
+ "types": [
539
+ "Integer"
540
+ ],
541
+ "name": "param1"
542
+ },
543
+ {
544
+ "tag_name": "param",
545
+ "text": "The second parameter.",
546
+ "types": [
547
+ "Any"
548
+ ],
549
+ "name": "param2"
550
+ },
551
+ {
552
+ "tag_name": "param",
553
+ "text": "The third parameter.",
554
+ "types": [
555
+ "Optional[Array[String]]"
556
+ ],
557
+ "name": "param3"
558
+ },
559
+ {
560
+ "tag_name": "return",
561
+ "text": "Returns nothing.",
562
+ "types": [
563
+ "Undef"
564
+ ]
565
+ }
566
+ ]
567
+ }
568
+ },
569
+ {
570
+ "signature": "func4x(Boolean $param, Callable &$block)",
571
+ "docstring": {
572
+ "text": "The second overload.",
573
+ "tags": [
574
+ {
575
+ "tag_name": "param",
576
+ "text": "The first parameter.",
577
+ "types": [
578
+ "Boolean"
579
+ ],
580
+ "name": "param"
581
+ },
582
+ {
583
+ "tag_name": "param",
584
+ "text": "The block parameter.",
585
+ "types": [
586
+ "Callable"
587
+ ],
588
+ "name": "&block"
589
+ },
590
+ {
591
+ "tag_name": "return",
592
+ "text": "Returns a string.",
593
+ "types": [
594
+ "String"
595
+ ]
596
+ }
597
+ ]
598
+ }
599
+ }
600
+ ],
427
601
  "docstring": {
428
602
  "text": "An example 4.x function.",
429
603
  "tags": [
@@ -508,4 +682,3 @@ An example JSON document describing a Puppet class, defined type, resource type,
508
682
  ]
509
683
  }
510
684
  ```
511
-
data/README.md CHANGED
@@ -6,8 +6,6 @@ A Puppet command built on [YARD](http://yardoc.org/).
6
6
 
7
7
  Puppet Strings generates HTML documentation for Puppet extensions written in Puppet and Ruby.
8
8
 
9
- This tool will eventually place the existing `puppet doc` command once feature parity has been achieved.
10
-
11
9
  | | |
12
10
  | -------------- |---------------------------------------------------------------- |
13
11
  | *Code* | [GitHub][repo] |
@@ -23,123 +21,155 @@ This tool will eventually place the existing `puppet doc` command once feature p
23
21
  [contributing]: https://github.com/puppetlabs/puppet-strings/blob/master/CONTRIBUTING.md
24
22
  [committers]: https://github.com/puppetlabs/puppet-strings/blob/master/COMMITTERS.md
25
23
 
26
- Requirements
27
- ------------
24
+ ## Installing Puppet Strings
25
+
26
+ ### Requirements
28
27
 
29
- In order to run strings you need to have the following software installed:
28
+ To run Strings, you need the following software:
30
29
 
31
30
  * Ruby 1.9.3 or newer
32
31
  * Puppet 3.7 or newer
33
32
  * The `yard` Ruby gem
34
33
 
35
- Note that a few extra steps are necessary to install puppet-strings with Puppet Enterprise 3.8.
34
+ Note that if you are running PE 3.8, you'll have a few extra steps to install puppet-strings.
36
35
 
37
- Installing the YARD Gem
38
- -----------------------
36
+ ### 1. Install the YARD Gem
39
37
 
40
38
  The easiest way to install the `yard` gem is with Puppet itself:
41
39
 
42
- For Puppet 4.x:
40
+ For Puppet 4.x and Puppet Enterprise 2015.2 and later:
41
+
43
42
  ```
44
43
  $ puppet resource package yard provider=puppet_gem
45
44
  ```
46
45
 
47
46
  For Puppet 3.x:
47
+
48
48
  ```
49
49
  $ puppet resource package yard provider=gem
50
50
  ```
51
51
 
52
52
  For Puppet Enterprise 3.8:
53
+
53
54
  ```
54
55
  GEM_HOME=/opt/puppet/lib/ruby/gems/1.9.1 puppet resource package yard provider=gem
55
56
  ```
56
57
 
57
- Installing the redcarpet Gem (Puppet Enterprise 3.8 only)
58
- -------------------------
58
+ ### 2. Puppet Enterprise 3.8 only: Install the redcarpet gem
59
+
59
60
  ```
60
61
  GEM_HOME=/opt/puppet/lib/ruby/gems/1.9.1 puppet resource package redcarpet provider=gem
61
62
  ```
62
63
 
63
- Installing Puppet Strings
64
- -------------------------
64
+ ### 3. Install Puppet Strings
65
65
 
66
- Strings can be installed using the [puppet-strings](https://rubygems.org/gems/puppet-strings) gem.
66
+ Install the [puppet-strings](https://rubygems.org/gems/puppet-strings) gem. To ensure that Strings is installed in the right place, install the gem with Puppet as shown below.
67
67
 
68
- To ensure it is installed in right place, it is best to install it using Puppet:
68
+ For Puppet 4.x and Puppet Enterprise 2015.2 and later:
69
69
 
70
- For Puppet 4.x:
71
70
  ```
72
71
  $ puppet resource package puppet-strings provider=puppet_gem
73
72
  ```
74
73
 
75
74
  For Puppet 3.x:
75
+
76
76
  ```
77
77
  $ puppet resource package puppet-strings provider=gem
78
78
  ```
79
79
 
80
80
  For Puppet Enterprise 3.8:
81
+
81
82
  ```
82
83
  GEM_HOME=/opt/puppet/lib/ruby/gems/1.9.1 puppet resource package puppet-strings provider=gem
83
84
  ```
84
85
 
85
- Running Puppet Strings
86
- ----------------------
86
+ ### 4. Optional: Set YARD options for Strings
87
87
 
88
- Once strings has been installed you can document a puppet module:
88
+ Puppet Strings supports YARD options (on the command line, run `yard help doc` for a list of possible options. To set YARD options, specify a `yardopts` file in the same directory in which you run `puppet strings`.
89
89
 
90
- ```
91
- $ cd /path/to/module
92
- $ puppet strings
93
- ```
90
+ Puppet Strings supports the Markdown format and automatically sets the YARD `markup` option to `markdown`.
91
+
92
+ ## Generating documentation with Puppet Strings
93
+
94
+ The `puppet strings` command processes the `README` file, as well as all Puppet and Ruby source files under the `./manifests/`, `./functions/`, and `./lib/`
95
+ directories, and then creates HTML documentation under the `./doc/` directory.
96
+
97
+ ### Generate module documentation
94
98
 
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.
99
+ To generate documentation for a Puppet module, run Strings from that module's directory.
97
100
 
98
- To document specific files:
101
+ 1. Change directory into the module: `cd /modules/sample-module`.
102
+ 2. Run the command: `puppet strings`.
103
+
104
+ ### Generate documentation for specific files
105
+
106
+ To generate documentation for specific files in a module, run the `puppet strings generate` subcommand and specify the files.
99
107
 
100
108
  ```
101
- $ puppet strings generate first.pp second.pp ...
109
+ puppet strings generate first.pp second.pp`
102
110
  ```
103
111
 
104
- To document specific directories:
112
+ To generate documentation for specific directories, run the `puppet strings generate` command and specify the directories:
105
113
 
106
114
  ```
107
115
  $ puppet strings generate 'modules/foo/lib/**/*.rb' 'modules/foo/manifests/**/*.pp' 'modules/foo/functions/**/*.pp' ...
108
116
  ```
109
117
 
110
- Strings can emit JSON documenting the Puppet extensions:
118
+ ### Set additional options for document generation
119
+
120
+ If you need to specify additional options when generating documentation, use the `puppet strings:generate` rake task. This command behaves exactly as `puppet strings generate`, but allows you to add the following parameters:
121
+
122
+ * `patterns`: the search patterns to use for finding files to document (defaults to `manifests/**/*.pp functions/**/*.pp types/**/*.pp lib/**/*.rb`).
123
+ * `debug`: enables debug output when set to `true`.
124
+ * `backtrace`: enables backtraces for errors when set to `true`.
125
+ * `markup`: the markup language to use (defaults to `markdown`).
126
+ * `yard_args`: additional arguments to pass to YARD.
127
+
128
+ For setup and usage details for the `puppet strings:generate` task, see [Rake tasks](#rake-tasks).
129
+
130
+ ## Viewing generated documentation
131
+
132
+ Strings generates documentation as HTML in a `./doc/` directory within the module for which you are generating documentation. Strings can also serve the generated docs locally or output documentation in JSON.
133
+
134
+ ### Serve documents locally
135
+
136
+ Strings can serve the generated HTML documentation with the `server` action. This action serves documentation for all modules in the [module path](https://docs.puppet.com/puppet/latest/reference/dirs_modulepath.html) at `http://localhost:8808`.
137
+
138
+ To serve documentation locally, run:
111
139
 
112
140
  ```
113
- $ puppet strings generate --emit-json documentation.json
141
+ $ puppet strings server
114
142
  ```
115
143
 
116
- It can also print the JSON to stdout:
144
+ ### Output documents in JSON
145
+
146
+ Strings can produce documentation in JSON and then either generate a `.json` file or print JSON to stdout. This can be useful for handling or displaying the data with your own custom applications.
147
+
148
+ To generate JSON documentation to a file, run:
117
149
 
118
150
  ```
119
- $ puppet strings generate --emit-json-stdout
151
+ $ puppet strings generate --emit-json documentation.json
120
152
  ```
121
153
 
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:
154
+ To generate and then print JSON documentation to stdout, run:
125
155
 
126
156
  ```
127
- $ puppet strings server
157
+ $ puppet strings generate --emit-json-stdout
128
158
  ```
129
159
 
130
- YARD Options
131
- ------------
160
+ For details about Strings JSON output, see [Strings JSON schema](https://github.com/puppetlabs/puppet-strings/blob/master/JSON.md).
132
161
 
133
- YARD options (see `yard help doc`) are supported in a `.yardopts` file in the same directory where `puppet strings` is run.
162
+ ### Output documents to GitHub Pages
134
163
 
135
- Puppet Strings automatically sets the `markup` option to `markdown`, allowing your documentation strings to be in Markdown format.
164
+ To generate documents and then make them available on [GitHub Pages](https://pages.github.com/), use the Strings rake task `strings:gh_pages:update`. See [Rake tasks](#rake-tasks) for setup and usage details.
136
165
 
137
- Documenting Puppet Extensions
138
- -----------------------------
166
+ ## Documenting Puppet code for Strings
139
167
 
140
- ### Puppet Classes / Defined Types
168
+ Strings relies on code comments and YARD docstrings to specify documentation comments. Comments can include free-form text that is treated as a high-level overview for the element being documented. You can also include any number of YARD tags that hold semantic metadata for various aspects of the code. These tags allow you to add this data to the code without worrying about presentation.
141
169
 
142
- To document Puppet classes and defined types, use a YARD docstring before the class or defined type definition:
170
+ ### Documenting Puppet classes and defined types
171
+
172
+ To document Puppet classes and defined types, use a series of comments to create a YARD docstring before the class or defined type definition.
143
173
 
144
174
  ```puppet
145
175
  # An example class.
@@ -157,8 +187,27 @@ class example_class(
157
187
  ) inherits example::params {
158
188
  # ...
159
189
  }
190
+ ```
160
191
 
161
- # An example defined type.
192
+ The Strings elements appearing in the above comment block are:
193
+
194
+ * Three comment lines, not prefixed with tags, give the class description.
195
+ * The `@example` YARD tag, immediately followed by an optional title.
196
+ * The `include` statement, which adds the usage example code.
197
+ * Two `@param` tags, with the name of the parameter first, followed by a string describing the parameter's purpose.
198
+
199
+ Puppet 4 is a typed language, so Puppet Strings automatically documents the parameter types from code. With Puppet 3, however, include the parameter type with the `@param` tag:
200
+
201
+ ```
202
+ # @param [String] first The first parameter for this class.
203
+ # @param [Integer] second The second parameter for this class.
204
+ ```
205
+
206
+ Note that if you document a parameter's type, and that parameter already has a Puppet type specifier, Strings emits a warning.
207
+
208
+ Defined types are documented in exactly the same way as classes:
209
+
210
+ ```
162
211
  #
163
212
  # This is an example of how to document a defined type.
164
213
  # @param ports The array of port numbers to use.
@@ -169,12 +218,9 @@ define example_type(
169
218
  }
170
219
  ```
171
220
 
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
221
+ ### Documenting resource types and providers
176
222
 
177
- To document custom resource types and their parameters/properties, use the `desc` method or assign a value to the `doc` attribute:
223
+ To document resource types, pass descriptions for each parameter, property, and the resource type itself to the `desc` method. Each description can include other tags as well, including examples.
178
224
 
179
225
  ```ruby
180
226
  Puppet::Type.newtype(:example) do
@@ -185,27 +231,22 @@ An example resource type.
185
231
  param => 'hi'
186
232
  }
187
233
  DESC
188
-
234
+
189
235
  newparam(:param) do
190
236
  desc 'An example parameter.'
191
237
  # ...
192
238
  end
193
-
239
+
194
240
  newproperty(:prop) do
195
241
  desc 'An example property.'
196
242
  #...
197
243
  end
198
-
244
+
199
245
  # ...
200
246
  end
201
247
  ```
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:
248
+
249
+ If your resource type includes dynamically created parameters and properties, you must also use the `#@!puppet.type.param` and `#@!puppet.type.property` directives **before** the `newtype` call. This is necessary because Strings does not evaluate Ruby code, so it cannot detect dynamic attributes.
209
250
 
210
251
  ```ruby
211
252
  # @!puppet.type.param [value1, value2, value3] my_param Documentation for a dynamic parameter.
@@ -215,51 +256,27 @@ Puppet::Type.newtype(:example) do
215
256
  end
216
257
  ```
217
258
 
218
- ### Providers
219
-
220
- To document providers, use the `desc` method or assign a value to the `doc` attribute:
259
+ Document providers similarly, again using the `desc` method:
221
260
 
222
261
  ```ruby
223
262
  Puppet::Type.type(:example).provide :platform do
224
263
  desc 'An example provider.'
225
-
264
+
226
265
  # ...
227
266
  end
228
267
  ```
229
268
 
230
- Puppet Strings documents this way to preserve backwards compatibility with `puppet doc` and existing resource types.
269
+ All provider method calls, including `confine`, `defaultfor`, and `commands`, are automatically parsed and documented by Strings. The `desc` method is used to generate the docstring, and can include tags such as `@example` if written as a heredoc.
231
270
 
232
- ***Note: Puppet Strings does not evaluate your Ruby code, so only certain static expressions are supported.***
271
+ **Note**: Puppet Strings can not evaluate your Ruby code, so only certain static expressions are supported.
233
272
 
234
- ### Functions
273
+ ### Documenting functions
235
274
 
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.
275
+ Puppet Strings supports the documenting of defined functions with the Puppet 4 API, the Puppet 3 API, or in the Puppet language itself.
238
276
 
239
- #### Puppet 3.x Functions
277
+ #### Document Puppet 4 functions
240
278
 
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:
279
+ To document a function in the Puppet 4 API, use a YARD docstring before the `create_function` call and before any `dispatch` calls:
263
280
 
264
281
  ```ruby
265
282
  # An example 4.x function.
@@ -273,16 +290,14 @@ Puppet::Functions.create_function(:example) do
273
290
  param 'String', :first
274
291
  param 'Integer', :second
275
292
  end
276
-
293
+
277
294
  # ...
278
295
  end
279
296
  ```
280
297
 
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.***
298
+ **Note**: Puppet Strings automatically uses the parameter type information from the `dispatch` block to document the parameter types. Only document your parameter types when the Puppet 4.x function contains no `dispatch` calls.
283
299
 
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:
300
+ If the Puppet 4 function contains multiple `dispatch` calls, Puppet Strings automatically creates `overload` tags to describe the function's overloads:
286
301
 
287
302
  ```ruby
288
303
  # An example 4.x function.
@@ -295,7 +310,7 @@ Puppet::Functions.create_function(:example) do
295
310
  dispatch :example_string do
296
311
  param 'String', :first
297
312
  end
298
-
313
+
299
314
  # Overload by integer.
300
315
  # @param first The first parameter.
301
316
  # @return [Integer] Returns an integer.
@@ -304,13 +319,33 @@ Puppet::Functions.create_function(:example) do
304
319
  dispatch :example_integer do
305
320
  param 'Integer', :first
306
321
  end
307
-
322
+
308
323
  # ...
309
324
  ```
310
325
 
311
- The resulting HTML for this example function will document both `example(String $first)` and `example(Integer $first)`.
326
+ The resulting HTML for this example function documents both `example(String $first)` and `example(Integer $first)`.
327
+
328
+ #### Document Puppet 3 functions
329
+
330
+ To document a function in the Puppet 3 API, use the `doc` option to `newfunction`:
331
+
332
+ ```ruby
333
+ Puppet::Parser::Functions.newfunction(:example, doc: <<-DOC
334
+ Documentation for an example 3.x function.
335
+ @param [String] param1 The first parameter.
336
+ @param [Integer] param2 The second parameter.
337
+ @return [Undef]
338
+ @example Calling the function.
339
+ example('hi', 10)
340
+ DOC
341
+ ) do |*args|
342
+ #...
343
+ end
344
+ ```
345
+
346
+ Because Puppet 3 is not typed in the way Puppet 4 is, specify the type for each parameter (for example, `@param [String]` for a string parameter). If a parameter type is omitted, a default of the `Any` Puppet type will be used.
312
347
 
313
- #### Puppet Language Functions
348
+ #### Document Puppet language functions
314
349
 
315
350
  To document Puppet functions written in the Puppet language, use a YARD docstring before the function definition:
316
351
 
@@ -325,42 +360,90 @@ function example(String $name) {
325
360
  }
326
361
  ```
327
362
 
328
- ***Note: Puppet Strings will automatically use the parameter type information from the function's parameter list to document
329
- the parameter types.***
363
+ **Note**: Puppet Strings automatically uses the parameter type information from the function's parameter list to document the parameter types.
330
364
 
331
- Additional Resources
332
- --------------------
365
+ ### Including examples in documentation
333
366
 
334
- Here are a few other good resources for getting started with documentation:
367
+ The `@example` YARD tag adds usage examples to any Ruby or Puppet language code.
335
368
 
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)
369
+ ```puppet
370
+ # @example String describing what this example demonstrates.
371
+ # $content = example('world')
372
+ # if $content == 'world' {
373
+ # include world
374
+ # }
375
+ function example(string $name) {
376
+ "hello $name"
377
+ }
378
+ ```
339
379
 
340
- Rake Tasks
341
- ----------
380
+ The string following the `@example` tag is an optional title which is displayed prominently above the code block.
342
381
 
343
- Puppet Strings comes with two rake tasks: `strings:generate` and `strings:gh_pages:update` available in `puppet-strings/tasks`.
382
+ The example body must begin on a newline underneath the tag, and each line of the example itself must be indented by
383
+ at least one space. Further indentation is preserved as preformatted text in the generated documentation.
344
384
 
345
- Add the following to your Gemfile to use `puppet-strings`:
385
+ ### Including multi-line tag descriptions
346
386
 
347
- ```ruby
348
- gem 'puppet-strings', :git => 'https://github.com/puppetlabs/puppet-strings.git'
387
+ You can spread tag descriptions across multiple lines, similar to multi-line examples, as long as subsequent lines are each uniformly indented by at least one space.
388
+
389
+ For example:
390
+
391
+ ```puppet
392
+ # @param name The name the function uses to say hello. Note that this
393
+ # description is extra long, so we've broken it up onto newlines for the sake
394
+ # of readability.
395
+ function example(string $name) {
396
+ "hello $name"
397
+ }
349
398
  ```
350
399
 
351
- In your `Rakefile`, add the following to use the `puppet-strings` tasks:
400
+ ## Reference
352
401
 
353
- ```ruby
402
+ ### Available Strings tags
403
+
404
+ The most commonly used tags for Strings are:
405
+
406
+ * `@param`: Documents a parameter with a given name, type and optional description.
407
+ * `@return`: Describes the return value (and type or types) of a method. You can list multiple return tags for a method if the method has distinct return cases. In this case, begin each case with "if".
408
+ * `@example`: Shows an example snippet of code for an object. The first line is an optional title. See above for more about how to [include examples in documentation](#including-examples-in-documentation).
409
+ * `@!puppet.type.param`: Documents dynamic type parameters. See [Documenting resource types and providers](#documenting-resource-types-and-providers) above.
410
+ * `@!puppet.type.property`: Documents dynamic type properties. See [Documenting resource types and providers](#documenting-resource-types-and-providers) above.
411
+ * `@since`: Lists the version in which the object was first added.
412
+ * `@see`: Adds "see also" references. Accepts URLs or other code objects with an optional description at the end. Note that the URL or object is automatically linked by YARD and does not need markup formatting.
413
+
414
+ For a complete list of tags, see the [YARD Tags Overview](http://www.rubydoc.info/gems/yard/file/docs/Tags.md).
415
+
416
+ ### Rake tasks
417
+
418
+ You can use Puppet Strings rake tasks to generate documentation with additional options or to make your generated docs available on [GitHub Pages](https://pages.github.com/).
419
+
420
+ The `strings:generate` and `strings:gh_pages:update` tasks are available in `puppet-strings/tasks`.
421
+
422
+ First, update your Gemfile and your Rakefile.:
423
+
424
+ 1. Add the following to your Gemfile to use `puppet-strings`:
425
+
426
+ ```ruby
427
+ gem 'puppet-strings'
428
+ ```
429
+
430
+ 2. Add the following to your `Rakefile` to use the `puppet-strings` tasks:
431
+
432
+ ```ruby
354
433
  require 'puppet-strings/tasks'
355
- ```
434
+ ```
435
+
436
+ Adding this `require` automatically creates the Rake tasks below.
437
+
438
+ #### Generate documentation with additional options
356
439
 
357
- The `strings:generate` task can be used to generate documentation:
440
+ Use the `strings:generate` task to generate documentation:
358
441
 
359
442
  ```
360
443
  $ rake strings:generate
361
444
  ```
362
445
 
363
- The task accepts the following parameters:
446
+ This command behaves exactly as `puppet strings generate`, but allows you to add the following parameters:
364
447
 
365
448
  * `patterns`: the search patterns to use for finding files to document (defaults to `manifests/**/*.pp functions/**/*.pp types/**/*.pp lib/**/*.rb`).
366
449
  * `debug`: enables debug output when set to `true`.
@@ -368,49 +451,57 @@ The task accepts the following parameters:
368
451
  * `markup`: the markup language to use (defaults to `markdown`).
369
452
  * `yard_args`: additional arguments to pass to YARD.
370
453
 
371
- An example of passing arguments to the `strings:generate` Rake task:
454
+ For example, the task below adds a search pattern, debugs output, backtraces errors, sets the markup language to `markdown`, and passes an additional YARD argument setting the readme file to `README.md`:
372
455
 
373
456
  ```
374
457
  $ rake strings:generate\['**/*{.pp\,.rb}, true, true, markdown, --readme README.md']
375
458
  ```
376
459
 
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:
460
+ #### Generate documentation on GitHub Pages
461
+
462
+ To generate Puppet Strings documentation and make it available on [GitHub Pages](https://pages.github.com/), use the `strings:gh_pages:update` task.
463
+
464
+ This task:
378
465
 
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**
466
+ 1. Creates a `doc` directory in the root of your project.
467
+ 2. Checks out the `gh-pages` branch of the current repository in the `doc` directory (it creates a branch if one does not already exist).
468
+ 3. Generates Strings documentation with the `strings:generate` task.
469
+ 4. Commits the changes and pushes them to the `gh-pages` branch **with the `--force` flag**.
383
470
 
384
471
  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
472
 
387
- Developing and Contributing
388
- ---------------------------
473
+ **Please note this operation is destructive if not used properly.**
474
+
475
+ ### Additional Resources
476
+
477
+ Here are a few other good resources for getting started with documentation:
478
+
479
+ * [Module README Template](https://docs.puppet.com/puppet/latest/reference/modules_documentation.html)
480
+ * [YARD Getting Started Guide](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
481
+ * [YARD Tags Overview](http://www.rubydoc.info/gems/yard/file/docs/Tags.md)
482
+
483
+ ## Developing and Contributing
389
484
 
390
485
  We love contributions from the community!
391
486
 
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.
487
+ If you'd like to contribute to puppet-strings, check out [CONTRIBUTING.md](https://github.com/puppetlabs/puppet-strings/blob/master/CONTRIBUTING.md) to get information on the contribution process.
393
488
 
394
- Running Specs
395
- -------------
489
+ ### Running Specs
396
490
 
397
491
  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
492
 
399
- To run specs, simply execute the `spec` rake task:
493
+ To run specs, run the `spec` rake task:
400
494
 
401
495
  $ bundle install --path .bundle/gems
402
496
  $ bundle exec rake spec
403
497
 
404
- Support
405
- -------
498
+ ## Support
406
499
 
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.
500
+ Please log tickets and issues in our [JIRA tracker][JIRA]. A [mailing list](https://groups.google.com/forum/?fromgroups#!forum/puppet-users) is available for asking questions and getting help from others.
409
501
 
410
502
  There is also an active #puppet channel on the Freenode IRC network.
411
503
 
412
- We use semantic version numbers for our releases, and recommend that users stay as up-to-date as possible by upgrading to
504
+ We use semantic version numbers for our releases and recommend that users upgrade to
413
505
  patch releases and minor releases as they become available.
414
506
 
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.
507
+ Bug fixes and ongoing development will occur in minor releases for the current major version. Security fixes will be ported to a previous major version on a best-effort basis, until the previous major version is no longer maintained.