(PDOC-128) Add explanation of @example tag usage in README

This commit is contained in:
Will Hopper 2016-10-12 14:57:24 -07:00
parent d057028975
commit 89658718c8
1 changed files with 35 additions and 12 deletions

View File

@ -7,7 +7,7 @@ A Puppet command built on [YARD](http://yardoc.org/).
Puppet Strings generates HTML documentation for Puppet extensions written in Puppet and Ruby. Puppet Strings generates HTML documentation for Puppet extensions written in Puppet and Ruby.
This tool will eventually place the existing `puppet doc` command once feature parity has been achieved. This tool will eventually place the existing `puppet doc` command once feature parity has been achieved.
| | | | | |
| -------------- |---------------------------------------------------------------- | | -------------- |---------------------------------------------------------------- |
| *Code* | [GitHub][repo] | | *Code* | [GitHub][repo] |
@ -169,7 +169,7 @@ define example_type(
} }
``` ```
***Note: unlike Ruby, Puppet 4.x is a typed language; Puppet Strings will automatically use the parameter type information to ***Note: unlike Ruby, Puppet 4.x is a typed language; Puppet Strings will automatically use the parameter type information to
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.*** 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.***
### Resource Types ### Resource Types
@ -185,17 +185,17 @@ An example resource type.
param => 'hi' param => 'hi'
} }
DESC DESC
newparam(:param) do newparam(:param) do
desc 'An example parameter.' desc 'An example parameter.'
# ... # ...
end end
newproperty(:prop) do newproperty(:prop) do
desc 'An example property.' desc 'An example property.'
#... #...
end end
# ... # ...
end end
``` ```
@ -222,7 +222,7 @@ To document providers, use the `desc` method or assign a value to the `doc` attr
```ruby ```ruby
Puppet::Type.type(:example).provide :platform do Puppet::Type.type(:example).provide :platform do
desc 'An example provider.' desc 'An example provider.'
# ... # ...
end end
``` ```
@ -273,12 +273,12 @@ Puppet::Functions.create_function(:example) do
param 'String', :first param 'String', :first
param 'Integer', :second param 'Integer', :second
end end
# ... # ...
end end
``` ```
***Note: Puppet Strings will automatically use the parameter type information from the `dispatch` block to document ***Note: Puppet Strings will automatically use 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.*** the parameter types. Only document your parameter types when the Puppet 4.x function contains no `dispatch` calls.***
If the Puppet 4.x function contains multiple `dispatch` calls, Puppet Strings will automatically create `overload` tags If the Puppet 4.x function contains multiple `dispatch` calls, Puppet Strings will automatically create `overload` tags
@ -295,7 +295,7 @@ Puppet::Functions.create_function(:example) do
dispatch :example_string do dispatch :example_string do
param 'String', :first param 'String', :first
end end
# Overload by integer. # Overload by integer.
# @param first The first parameter. # @param first The first parameter.
# @return [Integer] Returns an integer. # @return [Integer] Returns an integer.
@ -304,11 +304,11 @@ Puppet::Functions.create_function(:example) do
dispatch :example_integer do dispatch :example_integer do
param 'Integer', :first param 'Integer', :first
end end
# ... # ...
``` ```
The resulting HTML for this example function will document both `example(String $first)` and `example(Integer $first)`. The resulting HTML for this example function will document both `example(String $first)` and `example(Integer $first)`.
#### Puppet Language Functions #### Puppet Language Functions
@ -325,9 +325,32 @@ function example(String $name) {
} }
``` ```
***Note: Puppet Strings will automatically use the parameter type information from the function's parameter list to document ***Note: Puppet Strings will automatically use the parameter type information from the function's parameter list to document
the parameter types.*** the parameter types.***
Further examples
----------------
#### Using The `@example` Tag
The `@example` YARD tag can be used to add usage examples to any Ruby or Puppet language code.
```puppet
# @example String describing what this example demonstrates.
# $content = example('world')
# if $content == 'world' {
# include world
# }
function example(string $name) {
"hello $name"
}
```
The string following the `@example` tag is an optional title which is displayed prominently above the code block.
The example body must begin on a newline underneath the tag, and each line of the example itself must be indented by
at least one space. Further indentation is preserved as preformatted text in the generated documentation.
Additional Resources Additional Resources
-------------------- --------------------