puppet-strings 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/CONTRIBUTING.md +3 -7
  4. data/JSON.md +126 -8
  5. data/README.md +16 -498
  6. data/lib/puppet-strings.rb +6 -0
  7. data/lib/puppet-strings/json.rb +2 -0
  8. data/lib/puppet-strings/markdown.rb +6 -1
  9. data/lib/puppet-strings/markdown/puppet_plan.rb +14 -0
  10. data/lib/puppet-strings/markdown/puppet_plans.rb +37 -0
  11. data/lib/puppet-strings/markdown/puppet_task.rb +24 -0
  12. data/lib/puppet-strings/markdown/puppet_tasks.rb +34 -0
  13. data/lib/puppet-strings/markdown/table_of_contents.rb +3 -1
  14. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +8 -5
  15. data/lib/puppet-strings/markdown/templates/function.erb +2 -3
  16. data/lib/puppet-strings/markdown/templates/puppet_task.erb +28 -0
  17. data/lib/puppet-strings/markdown/templates/resource_type.erb +9 -5
  18. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +5 -0
  19. data/lib/puppet-strings/monkey_patches/display_object_command.rb +11 -0
  20. data/lib/puppet-strings/yard.rb +15 -1
  21. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  22. data/lib/puppet-strings/yard/code_objects/plan.rb +56 -0
  23. data/lib/puppet-strings/yard/code_objects/task.rb +70 -0
  24. data/lib/puppet-strings/yard/handlers.rb +6 -0
  25. data/lib/puppet-strings/yard/handlers/json/base.rb +5 -0
  26. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +31 -0
  27. data/lib/puppet-strings/yard/handlers/puppet/base.rb +1 -1
  28. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +1 -1
  29. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +1 -1
  30. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +1 -1
  31. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +27 -0
  32. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +4 -1
  33. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +12 -2
  34. data/lib/puppet-strings/yard/parsers.rb +4 -0
  35. data/lib/puppet-strings/yard/parsers/json/parser.rb +33 -0
  36. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +35 -0
  37. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +11 -0
  38. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +14 -0
  39. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_plan.erb +9 -0
  40. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_task.erb +9 -0
  41. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +18 -0
  42. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +42 -2
  43. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/box_info.erb +10 -0
  44. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/header.erb +1 -0
  45. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/overview.erb +6 -0
  46. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/setup.rb +11 -0
  47. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/source.erb +12 -0
  48. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/summary.erb +4 -0
  49. data/lib/puppet-strings/yard/templates/default/puppet_task/html/box_info.erb +9 -0
  50. data/lib/puppet-strings/yard/templates/default/puppet_task/html/header.erb +1 -0
  51. data/lib/puppet-strings/yard/templates/default/puppet_task/html/input.erb +5 -0
  52. data/lib/puppet-strings/yard/templates/default/puppet_task/html/overview.erb +6 -0
  53. data/lib/puppet-strings/yard/templates/default/puppet_task/html/parameters.erb +16 -0
  54. data/lib/puppet-strings/yard/templates/default/puppet_task/html/setup.rb +22 -0
  55. data/lib/puppet-strings/yard/templates/default/puppet_task/html/supports_noop.erb +3 -0
  56. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +3 -1
  57. data/lib/puppet-strings/yard/util.rb +14 -0
  58. data/spec/fixtures/unit/json/output.json +50 -0
  59. data/spec/fixtures/unit/json/output_with_plan.json +689 -0
  60. data/spec/fixtures/unit/markdown/output.md +63 -8
  61. data/spec/fixtures/unit/markdown/output_with_plan.md +472 -0
  62. data/spec/spec_helper.rb +5 -2
  63. data/spec/unit/puppet-strings/json_spec.rb +42 -2
  64. data/spec/unit/puppet-strings/markdown_spec.rb +41 -8
  65. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +92 -0
  66. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +124 -0
  67. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +1 -1
  68. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +19 -12
  69. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +33 -0
  70. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +8 -7
  71. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +70 -0
  72. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +56 -0
  73. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +1 -1
  74. data/spec/unit/puppet-strings/yard/util_spec.rb +17 -0
  75. metadata +38 -5
  76. data/MAINTAINERS +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82ad70b526cc76afc1aa63fe94f18525f3a88ed5
4
- data.tar.gz: 11c0250595f96c209f17625cdf7a8a41feee39c3
3
+ metadata.gz: 841114139c5e61cbe619f7d6282f08555a8cd890
4
+ data.tar.gz: 3acc7ea95bb3bdb7cf3890e3fb58d95f2d4f7e61
5
5
  SHA512:
6
- metadata.gz: 55047d29045ebd5f26f52f0f26331b0b602d6d98c7e231b512052e87537664aba1f1b5c00613e07435d5b885683ba3a941941f382b104c3a89270cddbd836794
7
- data.tar.gz: 71a37b237fd792a7c3c94acc72514068e24c87a75db75af5cd2f83196b7b100bbd9ab1682ccc54fb8b7d889412bfa806a75542a8cf77d0fc8d5ae87ae4d55803
6
+ metadata.gz: 7729f413ef4d94ecb2ada117ae4d93eabf096da95ad99804280121c33460466b76032f8c964abeafdf97d5ca38aed7ee551aac1dc77d3b07fcaf00bc46f1bb73
7
+ data.tar.gz: a4c6a1960fce2917d318acb4c6cd0f353779499acaf416dab177d3f2da7706f1475e0a7c694e4b58813faac7ebe48882937c89e3651ec67831a79bb43aac6cb5
@@ -2,6 +2,32 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
4
4
 
5
+ ## [2.0.0](https://github.com/puppetlabs/puppet-strings/tree/2.0.0) (2018-05-11)
6
+
7
+ [Full Changelog](https://github.com/puppetlabs/puppet-strings/compare/1.2.1...2.0.0)
8
+
9
+ ### Changed
10
+
11
+ - bump required ruby and puppet versions [\#178](https://github.com/puppetlabs/puppet-strings/pull/178) ([eputnam](https://github.com/eputnam))
12
+
13
+ ### Added
14
+
15
+ - \(PDOC-238\) add generated message to markdown [\#175](https://github.com/puppetlabs/puppet-strings/pull/175) ([eputnam](https://github.com/eputnam))
16
+ - \(PDOC-228\) puppet plan support [\#168](https://github.com/puppetlabs/puppet-strings/pull/168) ([eputnam](https://github.com/eputnam))
17
+ - \(PDOC-206\) support for tasks [\#161](https://github.com/puppetlabs/puppet-strings/pull/161) ([eputnam](https://github.com/eputnam))
18
+
19
+ ### Fixed
20
+
21
+ - \(PDOC-36\) fix hack for README urls [\#176](https://github.com/puppetlabs/puppet-strings/pull/176) ([eputnam](https://github.com/eputnam))
22
+ - \(PDOC-240\) add handling for :array node type in rsapi\_handler [\#174](https://github.com/puppetlabs/puppet-strings/pull/174) ([eputnam](https://github.com/eputnam))
23
+ - \(PDOC-159\) server urls fix [\#173](https://github.com/puppetlabs/puppet-strings/pull/173) ([eputnam](https://github.com/eputnam))
24
+ - \(maint\) display Plans in markdown table of contents [\#171](https://github.com/puppetlabs/puppet-strings/pull/171) ([eputnam](https://github.com/eputnam))
25
+ - \(PDOC-233\) markdown whitespace fixes [\#170](https://github.com/puppetlabs/puppet-strings/pull/170) ([JohnLyman](https://github.com/JohnLyman))
26
+ - \(PDOC-229\) fix error with return\_type and @return [\#169](https://github.com/puppetlabs/puppet-strings/pull/169) ([eputnam](https://github.com/eputnam))
27
+ - \(PDOC-36\) hack to fix README links in generated HTML [\#167](https://github.com/puppetlabs/puppet-strings/pull/167) ([eputnam](https://github.com/eputnam))
28
+ - \(PDOC-192\) remove warning for title/name [\#166](https://github.com/puppetlabs/puppet-strings/pull/166) ([eputnam](https://github.com/eputnam))
29
+ - \(maint\) add condition for misleading warning [\#155](https://github.com/puppetlabs/puppet-strings/pull/155) ([eputnam](https://github.com/eputnam))
30
+
5
31
  ## [1.2.1](https://github.com/puppetlabs/puppet-strings/tree/1.2.1) (2018-03-01)
6
32
 
7
33
  [Full Changelog](https://github.com/puppetlabs/puppet-strings/compare/1.2.0...1.2.1)
@@ -1,6 +1,6 @@
1
1
  # How to contribute
2
2
 
3
- Third-party patches are essential for keeping strings great. We want to keep it
3
+ Third-party patches are essential for keeping Puppet Strings great. We want to keep it
4
4
  as easy as possible to contribute changes that get things working in your
5
5
  environment. There are a few guidelines that we need contributors to follow so
6
6
  that we can have a chance of keeping on top of things.
@@ -72,18 +72,14 @@ a ticket number.
72
72
  * Push your changes to a topic branch in your fork of the repository.
73
73
  * Submit a pull request to the repository in the puppetlabs organization.
74
74
  * Update your Jira ticket to mark that you have submitted code and are ready for it to be reviewed (Status: Ready for Merge).
75
- * Include a link to the pull request in the ticket.
76
- * The core team looks at Pull Requests on a regular basis in a weekly triage
77
- meeting that we hold in a public Google Hangout. The hangout is announced in
78
- the weekly status updates that are sent to the puppet-dev list.
75
+ * Include a link to the pull request in the ticket.
79
76
  * After feedback has been given we expect responses within two weeks. After two
80
77
  weeks will may close the pull request if it isn't showing any activity.
81
78
 
82
79
  # Additional Resources
83
80
 
84
81
  * [More information on contributing](http://links.puppet.com/contribute-to-puppet)
85
- * [Bug tracker (Jira)](http://tickets.puppetlabs.com)
82
+ * [Bug tracker (Jira)](http://tickets.puppet.com)
86
83
  * [Contributor License Agreement](http://links.puppet.com/cla)
87
84
  * [General GitHub documentation](http://help.github.com/)
88
85
  * [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
89
- * #puppet-dev IRC channel on freenode.org
data/JSON.md CHANGED
@@ -1,15 +1,15 @@
1
1
  Puppet Strings JSON Data
2
2
  ========================
3
3
 
4
- Puppet Strings has two flags to the `generate` action that can be used to emit JSON data:
5
-
6
- * `--emit-json <file>`: Emits the JSON data to the given file.
7
- * `--emit-json-stdout`: Emits the JSON data to STDOUT.
4
+ Puppet Strings can generate JSON to STDOUT with the `--format` option:
5
+ ```shell
6
+ puppet strings generate --format json
7
+ ```
8
8
 
9
9
  Document Schema
10
10
  ===============
11
11
 
12
- At the top level, there are five arrays in the JSON document:
12
+ At the top level, there are seven arrays in the JSON document:
13
13
 
14
14
  | Document Key | Description |
15
15
  | ---------------- | ----------------------------------------------------------------------------- |
@@ -17,7 +17,9 @@ At the top level, there are five arrays in the JSON document:
17
17
  | defined_types | The list of defined types that were parsed. |
18
18
  | resource_types | The list of resource types that were parsed. |
19
19
  | providers | The list of resource providers that were parsed. |
20
- | puppet_functions | The list of Puppet functions (3.x, 4.x and Puppet language) that were parsed. |
20
+ | puppet_functions | The list of Puppet functions (4.x, 4.x and Puppet language) that were parsed. |
21
+ | puppet_tasks | The list of Puppet tasks that were parsed. |
22
+ | puppet_plans | The list of Puppet plans that were parsed. |
21
23
 
22
24
  Puppet Classes
23
25
  --------------
@@ -117,14 +119,43 @@ Each entry in the `puppet_functions` list is an object with the following attrib
117
119
  | Attribute Key | Description |
118
120
  | ------------- | ----------------------------------------------------------------------------- |
119
121
  | name | The name of the function. |
120
- | file | The file defining the provider. |
121
- | line | The line where the provider is defined. |
122
+ | file | The file defining the function. |
123
+ | line | The line where the function is defined. |
122
124
  | type | The function type (e.g. ruby3x, ruby4x, puppet). |
123
125
  | signatures | A list of Puppet signatures of the function, including overloads if present. |
124
126
  | docstring | The *DocString* object for the function (see below). |
125
127
  | defaults | The map of parameter names to default values. |
126
128
  | source | The source code for the function. |
127
129
 
130
+ Puppet Tasks
131
+ ------------
132
+
133
+ Each entry in the `puppet_tasks` list is an object with the following attributes:
134
+
135
+ | Attribute Key | Description |
136
+ | ------------- | ----------------------------------------------------------------------------- |
137
+ | name | The name of the task. |
138
+ | file | The file defining the task. |
139
+ | line | The line where the task is defined. |
140
+ | docstring | The *DocString* object for the task (see below). |
141
+ | source | The source code for the task. |
142
+ | supports_noop | Whether the task supports noop mode |
143
+ | input_method | Maps to the `input_method` key in the task json |
144
+
145
+ Puppet Plans
146
+ ------------
147
+
148
+ Each entry in the `puppet_plans` list is an object with the following attributes:
149
+
150
+ | Attribute Key | Description |
151
+ | ------------- | ----------------------------------------------------------------------------- |
152
+ | name | The name of the plan. |
153
+ | file | The file defining the plan. |
154
+ | line | The line where the plan is defined. |
155
+ | docstring | The *DocString* object for the plan (see below). |
156
+ | defaults | The map of parameter names to default values. |
157
+ | source | The source code for the plan. |
158
+
128
159
  Signature Objects
129
160
  -----------------
130
161
 
@@ -679,6 +710,93 @@ An example JSON document describing a Puppet class, defined type, resource type,
679
710
  },
680
711
  "source": "Puppet::Functions.create_function(:func4x) do\n # The first overload.\n # @param param1 The first parameter.\n # @param param2 The second parameter.\n # @param param3 The third parameter.\n # @return [Undef] Returns nothing.\n dispatch :foo do\n param 'Integer', :param1\n param 'Any', :param2\n optional_param 'Array[String]', :param3\n end\n\n # The second overload.\n # @param param The first parameter.\n # @param block The block parameter.\n # @return [String] Returns a string.\n dispatch :other do\n param 'Boolean', :param\n block_param\n end\nend"
681
712
  }
713
+ ],
714
+ "puppet_tasks": [
715
+ {
716
+ "name": "(stdin)",
717
+ "file": "(stdin)",
718
+ "line": 0,
719
+ "docstring": {
720
+ "text": "Allows you to backup your database to local file.",
721
+ "tags": [
722
+ {
723
+ "name": "database",
724
+ "tag_name": "param",
725
+ "text": "Database to connect to",
726
+ "types": [
727
+ "Optional[String[1]]"
728
+ ]
729
+ },
730
+ {
731
+ "name": "user",
732
+ "tag_name": "param",
733
+ "text": "The user",
734
+ "types": [
735
+ "Optional[String[1]]"
736
+ ]
737
+ },
738
+ {
739
+ "name": "password",
740
+ "tag_name": "param",
741
+ "text": "The password",
742
+ "types": [
743
+ "Optional[String[1]]"
744
+ ]
745
+ },
746
+ {
747
+ "name": "sql",
748
+ "tag_name": "param",
749
+ "text": "Path to file you want backup to",
750
+ "types": [
751
+ "String[1]"
752
+ ]
753
+ }
754
+ ]
755
+ },
756
+ "source": "{\n \"description\": \"Allows you to backup your database to local file.\",\n \"input_method\": \"stdin\",\n \"parameters\": {\n \"database\": {\n \"description\": \"Database to connect to\",\n \"type\": \"Optional[String[1]]\"\n },\n \"user\": {\n \"description\": \"The user\",\n \"type\": \"Optional[String[1]]\"\n },\n \"password\": {\n \"description\": \"The password\",\n \"type\": \"Optional[String[1]]\"\n },\n \"sql\": {\n \"description\": \"Path to file you want backup to\",\n \"type\": \"String[1]\"\n }\n }\n}\n",
757
+ "supports_noop": false,
758
+ "input_method": "stdin"
759
+ }
760
+ ],
761
+ "puppet_plans": [
762
+ {
763
+ "name": "plann",
764
+ "file": "(stdin)",
765
+ "line": 5,
766
+ "docstring": {
767
+ "text": "A simple plan.",
768
+ "tags": [
769
+ {
770
+ "tag_name": "param",
771
+ "text": "First param.",
772
+ "types": [
773
+ "String"
774
+ ],
775
+ "name": "param1"
776
+ },
777
+ {
778
+ "tag_name": "param",
779
+ "text": "Second param.",
780
+ "types": [
781
+ "Any"
782
+ ],
783
+ "name": "param2"
784
+ },
785
+ {
786
+ "tag_name": "param",
787
+ "text": "Third param.",
788
+ "types": [
789
+ "Integer"
790
+ ],
791
+ "name": "param3"
792
+ }
793
+ ]
794
+ },
795
+ "defaults": {
796
+ "param3": "1"
797
+ },
798
+ "source": "plan plann(String $param1, $param2, Integer $param3 = 1) {\n}"
799
+ }
682
800
  ]
683
801
  }
684
802
  ```
data/README.md CHANGED
@@ -2,9 +2,8 @@ Puppet Strings
2
2
  ==============
3
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
4
 
5
- A Puppet command built on [YARD](http://yardoc.org/).
5
+ Puppet Strings generates documentation for Puppet code and extensions written in Puppet and Ruby. Strings processes code and YARD-style code comments to create documentation in HTML, Markdown, or JSON formats.
6
6
 
7
- Puppet Strings generates HTML documentation for Puppet extensions written in Puppet and Ruby.
8
7
 
9
8
  | | |
10
9
  | -------------- |---------------------------------------------------------------- |
@@ -25,512 +24,32 @@ Puppet Strings generates HTML documentation for Puppet extensions written in Pup
25
24
 
26
25
  ### Requirements
27
26
 
28
- To run Strings, you need the following software:
29
-
30
- * Ruby 1.9.3 or newer
31
- * Puppet 3.7 or newer
27
+ * Ruby 2.1.9 or newer
28
+ * Puppet 4.0 or newer
32
29
  * The `yard` Ruby gem
33
30
 
34
- Note that if you are running PE 3.8, you'll have a few extra steps to install puppet-strings.
35
-
36
- ### 1. Install the YARD Gem
37
-
38
- The easiest way to install the `yard` gem is with Puppet itself:
39
-
40
- For Puppet >= 4 and Puppet Enterprise 2015.2 and later:
41
-
42
- ```
43
- $ puppet resource package yard provider=puppet_gem
44
- ```
45
-
46
- For Puppet 3.x:
47
-
48
- ```
49
- $ puppet resource package yard provider=gem
50
- ```
51
-
52
- For Puppet Enterprise 3.8 (Linux):
53
-
54
- ```
55
- GEM_HOME=/opt/puppet/lib/ruby/gems/1.9.1 puppet resource package yard provider=gem
56
- ```
57
-
58
- For Puppet Enterprise 3.8 (Windows):
59
-
60
- ```
61
- $env:GEM_HOME = "C:\Program Files\Puppet Labs\Puppet Enterprise\sys\ruby\lib\ruby\gems\2.0.0"
62
- puppet resource package yard provider=gem
63
- ```
64
-
65
- ### 2. Puppet Enterprise 3.8 in Linux only: Install the redcarpet gem
66
-
67
- ```
68
- GEM_HOME=/opt/puppet/lib/ruby/gems/1.9.1 puppet resource package redcarpet provider=gem
69
- ```
31
+ ### Install Puppet Strings
70
32
 
71
- ### 3. Install Puppet Strings
33
+ 1. Install the YARD gem by running `gem install yard`
34
+ 1. Install the `puppet-strings` gem by running `gem install puppet-strings`
35
+ 1. **Optional**: Set YARD options for Strings
72
36
 
73
- 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.
37
+ To use YARD options with Puppet Strings, specify a `yardopts` file in the same directory in which you run `puppet strings`. Puppet Strings supports the Markdown format and automatically sets the YARD `markup` option to `markdown`.
74
38
 
75
- For Puppet 4.x and Puppet Enterprise 2015.2 and later:
39
+ To see a list of available YARD options, run `yard help doc`. For details about YARD options configuration, see the [YARD docs](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md#config).
76
40
 
77
- ```
78
- $ puppet resource package puppet-strings provider=puppet_gem
79
- ```
80
-
81
- For Puppet 3.x:
82
-
83
- ```
84
- $ puppet resource package puppet-strings provider=gem
85
- ```
86
-
87
- For Puppet Enterprise 3.8 (Linux):
88
-
89
- ```
90
- GEM_HOME=/opt/puppet/lib/ruby/gems/1.9.1 puppet resource package puppet-strings provider=gem
91
- ```
92
-
93
- For Puppet Enterprise 3.8 (Windows)
94
-
95
- ```
96
- $env:GEM_HOME = "C:\Program Files\Puppet Labs\Puppet Enterprise\sys\ruby\lib\ruby\gems\2.0.0"
97
- puppet resource package puppet-strings provider=gem
98
- ```
99
-
100
- ### 4. Optional: Set YARD options for Strings
101
-
102
- 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`.
103
-
104
- Puppet Strings supports the Markdown format and automatically sets the YARD `markup` option to `markdown`.
105
41
 
106
42
  ## Generating documentation with Puppet Strings
107
43
 
108
- The `puppet strings` command processes the `README` file, as well as all Puppet and Ruby source files under the `./manifests/`, `./functions/`, and `./lib/`
109
- directories, and then creates HTML documentation under the `./doc/` directory.
110
-
111
- ### Generate module documentation
112
-
113
- To generate documentation for a Puppet module, run Strings from that module's directory.
114
-
115
- 1. Change directory into the module: `cd /modules/sample-module`.
116
- 2. Run the command: `puppet strings`.
117
-
118
- ### Generate documentation for specific files
119
-
120
- To generate documentation for specific files in a module, run the `puppet strings generate` subcommand and specify the files.
121
-
122
- ```
123
- puppet strings generate first.pp second.pp
124
- ```
125
-
126
- To generate documentation for specific directories, run the `puppet strings generate` command and specify the directories:
127
-
128
- ```
129
- $ puppet strings generate 'modules/foo/lib/**/*.rb' 'modules/foo/manifests/**/*.pp' 'modules/foo/functions/**/*.pp' ...
130
- ```
131
-
132
- ### Set additional options for document generation
133
-
134
- 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:
135
-
136
- * `patterns`: the search patterns to use for finding files to document (defaults to `manifests/**/*.pp functions/**/*.pp types/**/*.pp lib/**/*.rb`).
137
- * `debug`: enables debug output when set to `true`.
138
- * `backtrace`: enables backtraces for errors when set to `true`.
139
- * `markup`: the markup language to use (defaults to `markdown`).
140
- * `yard_args`: additional arguments to pass to YARD.
141
-
142
- For setup and usage details for the `puppet strings:generate` task, see [Rake tasks](#rake-tasks).
143
-
144
- ## Viewing generated documentation
145
-
146
- 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.
147
-
148
- ### Serve documents locally
149
-
150
- 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`.
151
-
152
- To serve documentation locally, run:
153
-
154
- ```
155
- $ puppet strings server
156
- ```
157
-
158
- ### Output documents in JSON
159
-
160
- 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.
161
-
162
- To generate JSON documentation to a file, run:
163
-
164
- ```
165
- $ puppet strings generate --format json --out documentation.json
166
- ```
167
-
168
- To generate and then print JSON documentation to stdout, run:
169
-
170
- ```
171
- $ puppet strings generate --format json
172
- ```
173
-
174
- For details about Strings JSON output, see [Strings JSON schema](https://github.com/puppetlabs/puppet-strings/blob/master/JSON.md).
175
-
176
- ### Output documents in Markdown
177
-
178
- Strings can also produce documentation in Markdown and then either generate an `.md` file or print Markdown to stdout. The generated markdown layout has been reviewed and approved by Puppet's tech pubs team and is the same that is used in Puppet Supported modules.
179
-
180
- To generate REFERENCE.md:
181
-
182
- ```
183
- $ puppet strings generate --format markdown
184
- ```
185
-
186
- To write Markdown documentation to another file, use the --out option:
187
-
188
- ```
189
- $ puppet strings generate --format markdown --out docs/INFO.md
190
- ```
191
-
192
- ### Output documents to GitHub Pages
193
-
194
- 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.
195
-
196
- ## Documenting Puppet code for Strings
197
-
198
- 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.
199
-
200
- ### Documenting Puppet classes and defined types
201
-
202
- To document Puppet classes and defined types, use a series of comments to create a YARD docstring before the class or defined type definition.
203
-
204
- ```puppet
205
- # An example class.
206
- #
207
- # This is an example of how to document a Puppet class
208
- #
209
- # @summary A short summary of the purpose of the class.
210
- #
211
- # @example Declaring the class
212
- # include example
213
- #
214
- # @param first The first parameter for this class
215
- # @param second The second parameter for this class
216
- class example_class(
217
- String $first = $example::params::first_arg,
218
- Integer $second = $example::params::second_arg,
219
- ) inherits example::params {
220
- # ...
221
- }
222
- ```
223
-
224
- The Strings elements appearing in the above comment block are:
225
-
226
- * Three comment lines, not prefixed with tags, give the class description.
227
- * The `@summary` YARD tag, which can be used for a short description of the class (fewer than 140 characters recommended).
228
- * The `@example` YARD tag, immediately followed by an optional title.
229
- * The `include` statement, which adds the usage example code.
230
- * Two `@param` tags, with the name of the parameter first, followed by a string describing the parameter's purpose.
231
-
232
- Puppet 4 is a typed language, so Puppet Strings automatically documents the parameter types from code. You may optionally include a parameter type in the `@param` tag. Strings will emit a warning and ignore the documented type should it differ from the actual type.
233
-
234
- With Puppet 3 code, you must always include the parameter type with the `@param` tag:
235
-
236
- ```
237
- # @param first [String] The first parameter for this class.
238
- # @param second [Integer] The second parameter for this class.
239
- ```
240
-
241
- Defined types are documented in exactly the same way as classes:
242
-
243
- ```
244
- #
245
- # This is an example of how to document a defined type.
246
- # @param ports The array of port numbers to use.
247
- define example_type(
248
- Array[Integer] $ports = []
249
- ) {
250
- # ...
251
- }
252
- ```
253
-
254
- ### Documenting resource types and providers
255
-
256
- 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.
257
-
258
- ```ruby
259
- Puppet::Type.newtype(:example) do
260
- desc <<-DESC
261
- An example resource type.
262
- @example Using the type.
263
- example { foo:
264
- param => 'hi'
265
- }
266
- DESC
267
-
268
- newparam(:param) do
269
- desc 'An example parameter.'
270
- # ...
271
- end
272
-
273
- newproperty(:prop) do
274
- desc 'An example property.'
275
- #...
276
- end
277
-
278
- # ...
279
- end
280
- ```
281
-
282
- 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.
283
-
284
- ```ruby
285
- # @!puppet.type.param [value1, value2, value3] my_param Documentation for a dynamic parameter.
286
- # @!puppet.type.property [foo, bar, baz] my_prop Documentation for a dynamic property.
287
- Puppet::Type.newtype(:example) do
288
- #...
289
- end
290
- ```
291
-
292
- Document providers similarly, again using the `desc` method:
293
-
294
- ```ruby
295
- Puppet::Type.type(:example).provide :platform do
296
- desc 'An example provider.'
297
-
298
- # ...
299
- end
300
- ```
301
-
302
- 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.
303
-
304
- Document types that use the new [Resource API](https://github.com/puppetlabs/puppet-resource_api):
305
-
306
- ```ruby
307
- Puppet::ResourceApi.register_type(
308
- name: 'database',
309
- docs: 'An example database server resource type.',
310
- attributes: {
311
- ensure: {
312
- type: 'Enum[present, absent, up, down]',
313
- desc: 'What state the database should be in.',
314
- default: 'up',
315
- },
316
- address: {
317
- type: 'String',
318
- desc: 'The database server name.',
319
- behaviour: :namevar,
320
- },
321
- encrypt: {
322
- type: 'Boolean',
323
- desc: 'Whether or not to encrypt the database.',
324
- default: false,
325
- behaviour: :parameter,
326
- },
327
- },
328
- )
329
- ```
330
-
331
- Here, the `docs` key acts like the `desc` method of the traditional resource type. Everything else is the same, except that now everything is a value in the data structure, not passed to methods.
332
-
333
- **Note**: Puppet Strings can not evaluate your Ruby code, so only certain static expressions are supported.
334
-
335
- ### Documenting functions
336
-
337
- Puppet Strings supports the documenting of defined functions with the Puppet 4 API, the Puppet 3 API, or in the Puppet language itself.
338
-
339
- #### Document Puppet 4 functions
340
-
341
- To document a function in the Puppet 4 API, use a YARD docstring before the `create_function` call and before any `dispatch` calls:
342
-
343
- ```ruby
344
- # An example 4.x function.
345
- Puppet::Functions.create_function(:example) do
346
- # @param first The first parameter.
347
- # @param second The second parameter.
348
- # @return [String] Returns a string.
349
- # @example Calling the function
350
- # example('hi', 10)
351
- dispatch :example do
352
- param 'String', :first
353
- param 'Integer', :second
354
- end
355
-
356
- # ...
357
- end
358
- ```
359
-
360
- **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.
361
-
362
- If the Puppet 4 function contains multiple `dispatch` calls, Puppet Strings automatically creates `overload` tags to describe the function's overloads:
363
-
364
- ```ruby
365
- # An example 4.x function.
366
- Puppet::Functions.create_function(:example) do
367
- # Overload by string.
368
- # @param first The first parameter.
369
- # @return [String] Returns a string.
370
- # @example Calling the function
371
- # example('hi')
372
- dispatch :example_string do
373
- param 'String', :first
374
- end
375
-
376
- # Overload by integer.
377
- # @param first The first parameter.
378
- # @return [Integer] Returns an integer.
379
- # @example Calling the function
380
- # example(10)
381
- dispatch :example_integer do
382
- param 'Integer', :first
383
- end
384
-
385
- # ...
386
- ```
387
-
388
- The resulting HTML for this example function documents both `example(String $first)` and `example(Integer $first)`.
389
-
390
- #### Document Puppet 3 functions
391
-
392
- To document a function in the Puppet 3 API, use the `doc` option to `newfunction`:
393
-
394
- ```ruby
395
- Puppet::Parser::Functions.newfunction(:example, doc: <<-DOC
396
- Documentation for an example 3.x function.
397
- @param param1 [String] The first parameter.
398
- @param param2 [Integer] The second parameter.
399
- @return [Undef]
400
- @example Calling the function.
401
- example('hi', 10)
402
- DOC
403
- ) do |*args|
404
- #...
405
- end
406
- ```
407
-
408
- 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.
409
-
410
- #### Document Puppet language functions
411
-
412
- To document Puppet functions written in the Puppet language, use a YARD docstring before the function definition:
413
-
414
- ```puppet
415
- # An example function written in Pupppet.
416
- # @param name The name to say hello to.
417
- # @return [String] Returns a string.
418
- # @example Calling the function
419
- # example('world')
420
- function example(String $name) {
421
- "hello $name"
422
- }
423
- ```
424
-
425
- **Note**: Puppet Strings automatically uses the parameter type information from the function's parameter list to document the parameter types.
426
-
427
- ### Including examples in documentation
428
-
429
- The `@example` YARD tag adds usage examples to any Ruby or Puppet language code.
430
-
431
- ```puppet
432
- # @example String describing what this example demonstrates.
433
- # $content = example('world')
434
- # if $content == 'world' {
435
- # include world
436
- # }
437
- function example(string $name) {
438
- "hello $name"
439
- }
440
- ```
441
-
442
- The string following the `@example` tag is an optional title which is displayed prominently above the code block.
443
-
444
- The example body must begin on a newline underneath the tag, and each line of the example itself must be indented by
445
- at least one space. Further indentation is preserved as preformatted text in the generated documentation.
446
-
447
- ### Including multi-line tag descriptions
448
-
449
- 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.
450
-
451
- For example:
452
-
453
- ```puppet
454
- # @param name The name the function uses to say hello. Note that this
455
- # description is extra long, so we've broken it up onto newlines for the sake
456
- # of readability.
457
- function example(string $name) {
458
- "hello $name"
459
- }
460
- ```
461
-
462
- ## Reference
463
-
464
- ### Available Strings tags
465
-
466
- * `@api`: Describes the resource as private or public, most commonly used with classes or defined types.
467
- * `@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).
468
- * `@param`: Documents a parameter with a given name, type and optional description.
469
- * `@!puppet.type.param`: Documents dynamic type parameters. See [Documenting resource types and providers](#documenting-resource-types-and-providers) above.
470
- * `@!puppet.type.property`: Documents dynamic type properties. See [Documenting resource types and providers](#documenting-resource-types-and-providers) above.
471
- * `@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".
472
- * `@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.
473
- * `@since`: Lists the version in which the object was first added.
474
- * `@summary`: A short description of the documented item.
475
-
476
- ### Rake tasks
477
-
478
- 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/).
479
-
480
- The `strings:generate` and `strings:gh_pages:update` tasks are available in `puppet-strings/tasks`.
481
-
482
- First, update your Gemfile and your Rakefile.:
483
-
484
- 1. Add the following to your Gemfile to use `puppet-strings`:
485
-
486
- ```ruby
487
- gem 'puppet-strings'
488
- ```
489
-
490
- 2. Add the following to your `Rakefile` to use the `puppet-strings` tasks:
491
-
492
- ```ruby
493
- require 'puppet-strings/tasks'
494
- ```
495
-
496
- Adding this `require` automatically creates the Rake tasks below.
497
-
498
- #### Generate documentation with additional options
499
-
500
- Use the `strings:generate` task to generate documentation:
501
-
502
- ```
503
- $ rake strings:generate
504
- ```
505
-
506
- This command behaves exactly as `puppet strings generate`, but allows you to add the following parameters:
507
-
508
- * `patterns`: the search patterns to use for finding files to document (defaults to `manifests/**/*.pp functions/**/*.pp types/**/*.pp lib/**/*.rb`).
509
- * `debug`: enables debug output when set to `true`.
510
- * `backtrace`: enables backtraces for errors when set to `true`.
511
- * `markup`: the markup language to use (defaults to `markdown`).
512
- * `yard_args`: additional arguments to pass to YARD.
513
-
514
- 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`:
515
-
516
- ```
517
- $ rake strings:generate\['**/*{.pp\,.rb}, true, true, markdown, --readme README.md']
518
- ```
519
-
520
- #### Generate documentation on GitHub Pages
521
-
522
- To generate Puppet Strings documentation and make it available on [GitHub Pages](https://pages.github.com/), use the `strings:gh_pages:update` task.
44
+ By default, Puppet Strings outputs documentation as HTML, or you can specify JSON or Markdown output instead.
523
45
 
524
- This task:
46
+ Strings generates reference documentation based on the code and Strings code comments in all Puppet and Ruby source files under the `./manifests/`, `./functions/`, `./lib/`, `./types/`, and `./tasks/` directories.
525
47
 
526
- 1. Creates a `doc` directory in the root of your project.
527
- 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).
528
- 3. Generates Strings documentation with the `strings:generate` task.
529
- 4. Commits the changes and pushes them to the `gh-pages` branch **with the `--force` flag**.
48
+ Strings outputs HTML of the reference information and the module README to the module's `./doc/` directory. This output can be rendered in any browser.
530
49
 
531
- 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.
50
+ JSON and Markdown output include the reference documentation only. Strings sends JSON output to either STDOUT or to a file. Markdown output is written to a REFERENCE.md file in the module's main directory.
532
51
 
533
- **Please note this operation is destructive if not used properly.**
52
+ See the [Puppet Strings documentation](https://puppet.com/docs/puppet/latest/puppet_strings.html) for complete instructions for generating documentation with Strings. For code comment style guidelines and examples, see the [Puppet Strings style guide](https://puppet.com/docs/puppet/5.5/puppet_strings_style.html).
534
53
 
535
54
  ### Additional Resources
536
55
 
@@ -544,7 +63,7 @@ Here are a few other good resources for getting started with documentation:
544
63
 
545
64
  We love contributions from the community!
546
65
 
547
- 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.
66
+ 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.
548
67
 
549
68
  ### Running Specs
550
69
 
@@ -561,7 +80,6 @@ Please log tickets and issues in our [JIRA tracker][JIRA]. A [mailing list](http
561
80
 
562
81
  There is also an active #puppet channel on the Freenode IRC network.
563
82
 
564
- We use semantic version numbers for our releases and recommend that users upgrade to
565
- patch releases and minor releases as they become available.
83
+ We use semantic version numbers for our releases and recommend that users upgrade to patch releases and minor releases as they become available.
566
84
 
567
85
  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.