- The module README
- Comment style guidelines
- Classes and defined types
- Parameters
- Example class
- Example defined type
- Functions
- Example Ruby function with one potential return type
- Example Ruby function with multiple potential return types
- Puppet function example
- Resource types
- Example resource API type
- Puppet tasks and plans
To document your module with Puppet Strings, add descriptive tags and comments to your module code. Write consistent, clear code comments, and include at least basic information about each element of your module (such as classes or defined types).
Strings uses YARD-style tags and comments, along with the structure of the module code, to generate complete reference information for your module. Whenever you update your code, update your documentation comments at the same time.
Puppet Strings version 2.0 or later
Puppet 4.0 or later
For information about the specific meaning of the terms 'must,' 'must not,' 'required,' 'should,' 'should not,' 'recommend,' 'may,' and 'optional,' see RFC 2119.
The module README
In your module README, include basic module information and extended usage examples for common use cases. The README tells users what your module does and how to use it. Strings generates reference documentation, so typically, there is no need to include a reference section in your README. However, Strings does not generate information for type aliases or facts; if your module includes these elements, include a short reference section in your README with information about these elements only.
Include the following sections in the 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
- Only if the module contains facts or type aliases, include a short Reference section. Other reference information is handled by Strings, so don't repeat it in the README.
- Limitations
- Operating system compatibility and known issues.
- Development
- Guidelines for contributing to the module
Comment style guidelines
Place an element's documentation comment immediately before the code for that element. Do not put a blank line between the comment and its corresponding code.
Each comment tag (such as
@example)
may have more than one line of comments. Indent additional lines with two spaces.Keep each comment line to no more than 140 characters, to improve readability.
Separate comment sections (such as
@summary
,@example
, or the@param
list) with a blank comment line (that is, a#
with no additional content), to improve readability.Untagged comments for a given element are output in an overview section that precedes all tagged information for that code element.
If an element, such as a class or parameter, is deprecated, indicate it in the description for that element with Deprecated in bold.
Classes and defined types
A
@summary
tag, a space, and then a summary describing the class or defined type.Other tags such as
@see
,@note
, or@api private
.Usage examples, each consisting of:
An
@example
tag with a description of a usage example on the same line.A code example showing how the class or defined type is used. Place this example directly under the
@example
tag and description, indented two spaces.
One
@param
tag for each parameter in the class or defined type. See the parameters section for formatting guidelines.
Parameters
The
@param
tag, a space, and then the name of the parameter.A description of what the parameter does. This may be either on the same line as the
@param
tag or on the next line, indented with two spaces.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.Other information about the parameter, such as warnings or special behavior. For example:
Example class
Example defined type
Functions
For custom Ruby functions, place documentation strings immediately before each dispatch call. For functions written in Puppet, place documentation strings immediately before the function name.
An untagged docstring describing what the function does.
One
@param
tag for each parameter in the function. See the parameters section for formatting guidelines.A
@return
tag with the data type and a description of the returned value.Optionally, a usage example, consisting of:
An
@example
tag with a description of a usage example on the same line.A code example showing how the function is used. Place this example directly under the
@example
tag and description, indented two spaces.
Ruby function with one potential return type
ExampleRuby function with multiple potential return types
ExampleIf the function has more than one potential return type, specify a @return
tag for each. Begin each tag string with "if" to differentiate between cases.
Puppet function example
Resource types
Add descriptions to the type and its attributes by passing either a here document (or "heredoc") or a short string to the desc
method.
Strings automatically detects much of the information for types, including the parameters and properties, collectively known as attributes. To document the resource type itself, pass a heredoc to the desc
method immediately after the type definition. Using a heredoc allows you to use multiple lines and Strings comment tags for your type documentation. For details about heredocs in Puppet, see the topic about heredocs in the language reference.
For attributes, where a short description is usually enough, pass a string to desc
in the attribute. As with the @param
tag, keep descriptions to 140 or fewer characters. If you need a longer description for an attribute, pass a heredoc to desc
in the attribute itself.
You do not need to add tags for other method calls. Every other method call present in a resource type is automatically included and documented by Strings, and each attribute is updated accordingly in the final documentation. This includes method calls such as defaultto
, newvalue
, and namevar
. If your type dynamically generates attributes, document those attributes with the @!puppet.type.param
and @!puppet.type.property
tags before the type definition. You may not use any other tags before the resource type definition.
Directly under the type definition, indented two spaces, the
desc
method, with a heredoc including a descriptive delimiting keyword, such asDESC
.A
@summary
tag with a summary describing the type.Optionally, usage examples, each consisting of:
An
@example
tag with a description of a usage example on the same line.Code example showing how the type is used. Place this example directly under the
@example
tag and description, indented two spaces.
For types created with the resource API, follow the guidelines for 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 extracts the heredoc information along with other information from this data structure.
Example resource API type
The heredoc and documentation strings that Strings uses are called out in bold in this code example:
Puppet tasks and plans
Strings documents Puppet tasks automatically, taking all information from the task metadata. Document task plans just as you would a class or defined type, with tags and descriptions in the plan file.
A
@summary
tag, a space, and then a summary describing the plan.Other tags such as
@see
,@note
, or@api private
.Usage examples, each consisting of:
An
@example
tag with a description of a usage example on the same line.Code example showing how the plan is used. Place this example directly under the
@example
tag and description, indented two spaces.
- One
@param
tag for each parameter in the plan. See the parameters section for formatting guidelines. For example: