-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9463 from joshcooper/references_function_12064
(PUP-12064) Add task to generate function reference
- Loading branch information
Showing
6 changed files
with
5,634 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
layout: default | ||
built_from_commit: <%= sha %> | ||
title: Built-in function reference | ||
canonical: "/puppet/latest/function.html" | ||
toc_levels: 2 | ||
toc: columns | ||
--- | ||
|
||
# Built-in function reference | ||
|
||
> **NOTE:** This page was generated from the Puppet source code on <%= now %> | ||
|
||
|
||
|
||
This page is a list of Puppet's built-in functions, with descriptions of what they do and how to use them. | ||
|
||
Functions are plugins you can call during catalog compilation. A call to any function is an expression that resolves to a value. For more information on how to call functions, see [the language reference page about function calls.](lang_functions.dita) | ||
|
||
Many of these function descriptions include auto-detected _signatures,_ which are short reminders of the function's allowed arguments. These signatures aren't identical to the syntax you use to call the function; instead, they resemble a parameter list from a Puppet [class](lang_classes.dita), [defined resource type](lang_defined_types.dita), [function](lang_write_functions_in_puppet.dita), or [lambda](lang_lambdas.dita). The syntax of a signature is: | ||
|
||
``` | ||
<FUNCTION NAME>(<DATA TYPE> <ARGUMENT NAME>, ...) | ||
``` | ||
|
||
The `<DATA TYPE>` is a [Puppet data type value](lang_data_type.dita), like `String` or `Optional[Array[String]]`. The `<ARGUMENT NAME>` is a descriptive name chosen by the function's author to indicate what the argument is used for. | ||
|
||
* Any arguments with an `Optional` data type can be omitted from the function call. | ||
* Arguments that start with an asterisk (like `*$values`) can be repeated any number of times. | ||
* Arguments that start with an ampersand (like `&$block`) aren't normal arguments; they represent a code block, provided with [Puppet's lambda syntax.](lang_lambdas.dita) | ||
|
||
## `undef` values in Puppet 6 | ||
|
||
In Puppet 6, many Puppet types were moved out of the Puppet codebase, and into modules on the Puppet Forge. The new functions handle `undef` values more strictly than their stdlib counterparts. In Puppet 6, code that relies on `undef` values being implicitly treated as other types will return an evaluation error. For more information on which types were moved into modules, see the [Puppet 6 release notes](https://puppet.com/docs/puppet/6.0/release_notes_puppet.html#select-types-moved-to-modules). | ||
|
||
|
||
<%= body %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<% functions.sort{|a,b| a['name'] <=> b['name'] }.each do |func| -%> | ||
## `<%= func['name'] %>` | ||
|
||
<%= func['docstring']['text'] %> | ||
|
||
<% func_signatures = func['signatures'] | ||
multiple_signatures = func_signatures.count > 1 | ||
if func_signatures | ||
func['signatures'].each_with_index do |signature, index| -%> | ||
|
||
<% if multiple_signatures -%> | ||
Signature <%= index+1 %> | ||
|
||
<% end -%> | ||
`<%= signature['signature'] %>` | ||
<% has_parameters = signature.dig('docstring', 'tags')&.detect {|tag| tag['tag_name'] == 'param' && tag['text'] != '' && tag['text'] != nil } || false | ||
if has_parameters -%> | ||
|
||
### Parameters | ||
|
||
<% signature['docstring']['tags'].select {|tag| tag['tag_name'] == 'param' && tag['text'] != '' && tag['text'] != nil}.each do |param| -%> | ||
|
||
* `<%= param['name'] %>` --- <%= param['text'] %> | ||
<% end # each param | ||
|
||
return_types = signature['docstring']['tags'].detect {|tag| tag['tag_name'] == 'return'} | ||
if return_types -%> | ||
|
||
Return type(s): <%= return_types['types'].map {|t| "`#{t}`"}.join(', ') %>. <%= return_types['text'] %> | ||
<% end # if return_types | ||
has_examples = signature['docstring']['tags'].detect {|tag| tag['tag_name'] == 'example' && tag['text'] != '' && tag['text'] != nil } | ||
if has_examples %> | ||
|
||
### Examples | ||
|
||
<% signature['docstring']['tags'].select {|tag| tag['tag_name'] == 'example' && tag['text'] != '' && tag['text'] != nil}.each do |example| -%> | ||
<%= example['name'] %> | ||
|
||
<%= example['text'] %> | ||
|
||
<% end # each example | ||
end # if has_examples | ||
end-%> | ||
<% end # each signature | ||
end -%> | ||
|
||
<% end -%> |
Oops, something went wrong.