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.
1. Install the YARD gem by running `gem install yard`
1. Install the `puppet-strings` gem by running `gem install puppet-strings`
1.**Optional**: Set YARD options for Strings
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`.
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).
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.
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.
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.
To generate documentation for specific files or directories in a module, run the `puppet strings generate` subcommand and specify the files or directories as a space-separated list.
You can serve HTML documentation locally 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`.
By default, Markdown output generates a `REFERENCE.md` file, but you can specify a different location or filename if you prefer. The generated Markdown includes reference information only. The `REFERENCE.md` file is the same format and information we are introducing into Puppet Supported modules.
By default, running `puppet strings` generates HTML documentation for a module into a `doc/` directory within that module. To pass any options or arguments, use the `generate` action.
`generate` | Generates documentation with the specified parameters, including format and output location.
`server` | Serves documentation for all modules in the [module path](https://docs.puppet.com/puppet/latest/reference/dirs_modulepath.html) locally at `http://localhost:8808`.
`--out` | Specifies an output location for documentation | A valid directory location and filename. | If not specified, outputs to default locations depending on format: HTML (`/docs/`), Markdown (main module directory), or JSON (stdout).
Filenames or directory paths | Outputs documentation for only specified files or directories. | Markdown, JSON. | If not specified, Strings outputs HTML documentation.
`--verbose` | Logs verbosely. | none | If not specified, Strings logs basic information.
`--debug` | Logs debug information. | none | If not specified, Strings does not log debug information.
`--markup FORMAT` | The markup format to use for docstring text | "markdown", "textile", "rdoc", "ruby", "text", "html", or "none" | By default, Strings outputs HTML, if no `--format` is specified or Markdown if `--format markdown` is specified.
`--help` | Displays help documentation for the command. | Markdown, JSON | If not specified, Strings outputs HTML documentation.
Puppet Strings combines source code and code comments to create complete, user-friendly reference information for modules. Strings can generate module documentation for classes, defined types, functions, and resource types in HTML, JSON, and Markdown formats.
Instead of manually writing and formatting long reference lists, add a few descriptive tags and comments for each element (class, defined type, function) of your module. Whenever you update code, update your documentation comments at the same time. Strings automatically extracts some information, such as data types and attribute defaults from the code, so you need to add minimal documentation comments.
Module READMEs are where users can learn more about what a module does and how to use it. In the module README, include basic module information and extended usage examples that address common use cases.
Strings generates complete information about classes, defined types, functions, and resource types and providers. Strings does not yet generate information for type aliases, facts, or custom providers. If your module includes these elements, document them in your README.
* Module description: What the module does and why it is useful.
* Setup: Prerequisites for module use and getting started information.
* Usage: Instructions and examples for common use cases or advanced configuration options.
* Reference: If the module contains elements that Strings doesn't document, such as facts or type aliases, include a short Reference section for those elements.
* Limitations: OS compatibility and known issues.
* Development: Guide for contributing to the module.
* Comments must immediately precede the code for that element. You cannot have a blank return separating the comment section from the code it documents.
* Each comment tag (such as `@example`) can have more than one line of comments.
* Any additional lines following a tag should be uniformly indented by two spaces.
* Each comment line should be no more than 140 characters, to improve readability.
* Each section (such as `@summary`, `@example`, or the `@param` list) should be followed by a blank comment line to improve readability.
* All untagged comments are output in an overview section that precedes all tagged information for that code element.
1. A `@summary` tag with a summary describing the class or defined type. This summary should be 140 characters or fewer. If a class or defined type is deprecated, indicate it here with **Deprecated**.
1. Optional: Other tags such as `@see`, `@note`, or `@api`.
1. Optional: usage examples, each consisting of:
1. An `@example` tag with a description of a usage example on the same line
1. Code example showing how the class or defined type is used. This example should be directly under the `@example` tag and description, indented two spaces.
1. One `@param` tag for each parameter in the class or defined type. See the parameter section for formatting guidelines.
Add parameter information as part of any class, defined type, or function that accepts parameters. Parameter information should appear in the following order.
1. The `@param` tag, a space, and then the name of the parameter.
1. Description of what the parameter does. This may be on the same line as the `@param` tag or on the next line.
1. Any additional information about valid values that is not clear from the data type. For example, if the data type is [String], but the value must specifically be a path, say so here.
1. Any other information about the parameter, such as warnings or special behavior.
If there is than one potential return type, you can use the `@return` tag multiple times. In this case, begin each tag string with ‘if’ to differentiate between cases.
Strings automatically detects much of the information for types, including their parameters and properties. Add descriptions to the type and its attributes by passing either a here document (heredoc) or a short string to the `desc` method.
To document the resource type itself, pass a here document (heredoc) to the `desc` method immediately after the type definition. The heredoc allows you to use String comment tags and multiple lines for your type documentation.
For parameters, where a short description is usually enough, pass a string to `desc` in the attribute. Puppet Strings interprets strings passed to `desc` the same way in interprets the `@param` tag. Like `@param` tag strings, strings passed to `desc` should be no more than 140 characters. If you need a long description for a parameter, you can pass a heredoc to `desc` in the attribute.
Every other method call present in a resource type is automatically included and documented by Strings, and each parameter or property is updated accordingly in the final documentation. This includes method calls such as `defaultto`, `newvalue`, and `namevar`.
If your type dynamically generates parameters or properties, document those attributes with the `@!puppet.type.param` and `@!puppet.type.property` tags before the type definition. These are the only tags you can use before the resource type definition.
The resource type description should appear in the following order:
1. Directly under the type definition, indented two spaces, the `desc` method, with a heredoc including a descriptive delimiting keyword, such as `DESC`.
1. A `@summary` tag with a summary describing the type. This summary should be 140 characters or fewer.
1. Optionally, usage examples, each consisting of:
1. An `@example` tag with a description of a usage example on the same line.
1. Code example showing how the type is used. This example should be directly under the `@example` tag and description, indented two spaces.
Document resource API types the same way you would standard resource types, but pass the heredoc or documentation string to a `desc` key in the data structure. You can include tags and multiple lines with the heredoc. Strings pulls the heredoc information along with other information from this data structure.
*`@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).
*`@!puppet.type.param`: Documents dynamic type parameters. See [Documenting resource types and providers](#documenting-resource-types-and-providers) above.
*`@!puppet.type.property`: Documents dynamic type properties. See [Documenting resource types and providers](#documenting-resource-types-and-providers) above.
*`@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".
*`@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.
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.
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.
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.