openvox-strings 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +407 -0
- data/LICENSE +177 -0
- data/README.md +116 -0
- data/lib/openvox-strings/describe.rb +75 -0
- data/lib/openvox-strings/json.rb +33 -0
- data/lib/openvox-strings/markdown/base.rb +236 -0
- data/lib/openvox-strings/markdown/data_type.rb +39 -0
- data/lib/openvox-strings/markdown/defined_type.rb +20 -0
- data/lib/openvox-strings/markdown/function.rb +59 -0
- data/lib/openvox-strings/markdown/helpers.rb +21 -0
- data/lib/openvox-strings/markdown/puppet_class.rb +20 -0
- data/lib/openvox-strings/markdown/puppet_plan.rb +20 -0
- data/lib/openvox-strings/markdown/puppet_task.rb +29 -0
- data/lib/openvox-strings/markdown/resource_type.rb +56 -0
- data/lib/openvox-strings/markdown/templates/classes_and_defines.erb +94 -0
- data/lib/openvox-strings/markdown/templates/data_type.erb +101 -0
- data/lib/openvox-strings/markdown/templates/data_type_function.erb +67 -0
- data/lib/openvox-strings/markdown/templates/function.erb +106 -0
- data/lib/openvox-strings/markdown/templates/puppet_task.erb +28 -0
- data/lib/openvox-strings/markdown/templates/resource_type.erb +156 -0
- data/lib/openvox-strings/markdown/templates/table_of_contents.erb +26 -0
- data/lib/openvox-strings/markdown.rb +81 -0
- data/lib/openvox-strings/monkey_patches/display_object_command.rb +16 -0
- data/lib/openvox-strings/tasks/generate.rb +54 -0
- data/lib/openvox-strings/tasks/gh_pages.rb +72 -0
- data/lib/openvox-strings/tasks/validate.rb +42 -0
- data/lib/openvox-strings/tasks.rb +14 -0
- data/lib/openvox-strings/version.rb +5 -0
- data/lib/openvox-strings/yard/code_objects/base.rb +16 -0
- data/lib/openvox-strings/yard/code_objects/class.rb +60 -0
- data/lib/openvox-strings/yard/code_objects/data_type.rb +102 -0
- data/lib/openvox-strings/yard/code_objects/data_type_alias.rb +60 -0
- data/lib/openvox-strings/yard/code_objects/defined_type.rb +59 -0
- data/lib/openvox-strings/yard/code_objects/function.rb +106 -0
- data/lib/openvox-strings/yard/code_objects/group.rb +33 -0
- data/lib/openvox-strings/yard/code_objects/plan.rb +59 -0
- data/lib/openvox-strings/yard/code_objects/provider.rb +98 -0
- data/lib/openvox-strings/yard/code_objects/task.rb +69 -0
- data/lib/openvox-strings/yard/code_objects/type.rb +196 -0
- data/lib/openvox-strings/yard/code_objects.rb +14 -0
- data/lib/openvox-strings/yard/handlers/helpers.rb +10 -0
- data/lib/openvox-strings/yard/handlers/json/base.rb +8 -0
- data/lib/openvox-strings/yard/handlers/json/task_handler.rb +34 -0
- data/lib/openvox-strings/yard/handlers/puppet/base.rb +52 -0
- data/lib/openvox-strings/yard/handlers/puppet/class_handler.rb +29 -0
- data/lib/openvox-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
- data/lib/openvox-strings/yard/handlers/puppet/defined_type_handler.rb +29 -0
- data/lib/openvox-strings/yard/handlers/puppet/function_handler.rb +54 -0
- data/lib/openvox-strings/yard/handlers/puppet/plan_handler.rb +29 -0
- data/lib/openvox-strings/yard/handlers/ruby/base.rb +55 -0
- data/lib/openvox-strings/yard/handlers/ruby/data_type_handler.rb +411 -0
- data/lib/openvox-strings/yard/handlers/ruby/function_handler.rb +386 -0
- data/lib/openvox-strings/yard/handlers/ruby/provider_handler.rb +127 -0
- data/lib/openvox-strings/yard/handlers/ruby/rsapi_handler.rb +157 -0
- data/lib/openvox-strings/yard/handlers/ruby/type_base.rb +146 -0
- data/lib/openvox-strings/yard/handlers/ruby/type_extras_handler.rb +65 -0
- data/lib/openvox-strings/yard/handlers/ruby/type_handler.rb +105 -0
- data/lib/openvox-strings/yard/handlers.rb +28 -0
- data/lib/openvox-strings/yard/parsers/json/parser.rb +38 -0
- data/lib/openvox-strings/yard/parsers/json/task_statement.rb +37 -0
- data/lib/openvox-strings/yard/parsers/puppet/parser.rb +89 -0
- data/lib/openvox-strings/yard/parsers/puppet/statement.rb +182 -0
- data/lib/openvox-strings/yard/parsers.rb +14 -0
- data/lib/openvox-strings/yard/tags/enum_tag.rb +13 -0
- data/lib/openvox-strings/yard/tags/factory.rb +18 -0
- data/lib/openvox-strings/yard/tags/overload_tag.rb +112 -0
- data/lib/openvox-strings/yard/tags/parameter_directive.rb +25 -0
- data/lib/openvox-strings/yard/tags/property_directive.rb +25 -0
- data/lib/openvox-strings/yard/tags/summary_tag.rb +10 -0
- data/lib/openvox-strings/yard/tags.rb +11 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/css/common.css +8 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_plan.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_task.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/fulldoc/html/setup.rb +93 -0
- data/lib/openvox-strings/yard/templates/default/layout/html/footer.erb +3 -0
- data/lib/openvox-strings/yard/templates/default/layout/html/objects.erb +37 -0
- data/lib/openvox-strings/yard/templates/default/layout/html/setup.rb +231 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/box_info.erb +26 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/setup.rb +16 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_class/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/setup.rb +15 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +19 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/setup.rb +7 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_defined_type/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/box_info.erb +14 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/overview.erb +18 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/setup.rb +7 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_function/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/box_info.erb +10 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/setup.rb +13 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/source.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_plan/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/box_info.erb +14 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/collection.erb +17 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/features.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/setup.rb +31 -0
- data/lib/openvox-strings/yard/templates/default/puppet_provider/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/box_info.erb +9 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/input.erb +5 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/parameters.erb +16 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/setup.rb +24 -0
- data/lib/openvox-strings/yard/templates/default/puppet_task/html/supports_noop.erb +3 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/box_info.erb +20 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/deprecated.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/features.erb +13 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/header.erb +1 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/note.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/overview.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/parameters.erb +35 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/setup.rb +36 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/summary.erb +4 -0
- data/lib/openvox-strings/yard/templates/default/puppet_type/html/todo.erb +6 -0
- data/lib/openvox-strings/yard/templates/default/tags/html/enum.erb +17 -0
- data/lib/openvox-strings/yard/templates/default/tags/html/puppet_overload.erb +12 -0
- data/lib/openvox-strings/yard/templates/default/tags/setup.rb +20 -0
- data/lib/openvox-strings/yard/util.rb +87 -0
- data/lib/openvox-strings/yard.rb +132 -0
- data/lib/openvox-strings.rb +88 -0
- data/lib/puppet/application/strings.rb +7 -0
- data/lib/puppet/face/strings.rb +185 -0
- data/lib/puppet/feature/rgen.rb +5 -0
- data/lib/puppet/feature/yard.rb +5 -0
- metadata +263 -0
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# openvox-strings
|
2
|
+
|
3
|
+
[](https://github.com/voxpupuli/openvox-strings/blob/master/LICENSE)
|
4
|
+
[](https://github.com/voxpupuli/openvox-strings/actions/workflows/release.yml)
|
5
|
+
[](https://github.com/voxpupuli/openvox-strings/actions/workflows/ci.yml)
|
6
|
+
[](https://rubygems.org/gems/openvox-strings)
|
7
|
+
[](https://rubygems.org/gems/openvox-strings)
|
8
|
+
|
9
|
+
openvox-strings generates documentation for Puppet code and extensions written in Puppet and Ruby.
|
10
|
+
Strings processes code and YARD-style code comments to create documentation in HTML, Markdown, or JSON formats.
|
11
|
+
|
12
|
+
It's a fork of https://github.com/puppetlabs/puppet-strings.
|
13
|
+
Some parts of the documentation still refer to to "Puppet Strings"
|
14
|
+
|
15
|
+
## Installing Puppet Strings
|
16
|
+
|
17
|
+
### Requirements
|
18
|
+
|
19
|
+
* Ruby 2.7 or newer
|
20
|
+
* OpenVox 7 or newer
|
21
|
+
|
22
|
+
For detailed dependencies, please checkout the gemspec file.
|
23
|
+
|
24
|
+
### Install Puppet Strings
|
25
|
+
|
26
|
+
Installation instructions vary slightly depending on how you have installed Puppet:
|
27
|
+
|
28
|
+
#### Installing Puppet Strings with [`puppet-agent`](https://puppet.com/docs/puppet/6.4/about_agent.html#what-puppet-agent-and-puppetserver-are) package
|
29
|
+
|
30
|
+
Install the `openvox-strings` gem into the `puppet-agent` environment:
|
31
|
+
|
32
|
+
``` bash
|
33
|
+
sudo /opt/puppetlabs/puppet/bin/gem install openvox-strings
|
34
|
+
```
|
35
|
+
|
36
|
+
#### Installing Puppet Strings with standalone `openvox` gem
|
37
|
+
|
38
|
+
Install the `openvox-strings` gem into the same Ruby installation where you have installed the `openvox` gem:
|
39
|
+
|
40
|
+
``` bash
|
41
|
+
gem install openvox-strings
|
42
|
+
```
|
43
|
+
|
44
|
+
### Configure Puppet Strings (Optional)
|
45
|
+
|
46
|
+
To use YARD options with Puppet Strings, specify a `.yardopts` file in the same directory in which you run `puppet strings`.
|
47
|
+
|
48
|
+
Puppet Strings supports the Markdown format and automatically sets the YARD `markup` option to `markdown`.
|
49
|
+
|
50
|
+
To see a list of available YARD options, run `yard help doc`.
|
51
|
+
|
52
|
+
For details about YARD options configuration, see the [YARD docs](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md#config).
|
53
|
+
|
54
|
+
## Generating documentation with Puppet Strings
|
55
|
+
|
56
|
+
By default, Puppet Strings outputs documentation as HTML, or you can specify JSON or Markdown output instead.
|
57
|
+
|
58
|
+
Strings generates reference documentation based on the code and Strings code comments in all Puppet and
|
59
|
+
Ruby source files under the `./manifests/`, `./functions/`, `./lib/`, `./types/`, and `./tasks/` directories.
|
60
|
+
|
61
|
+
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.
|
62
|
+
|
63
|
+
JSON and Markdown output include the reference documentation only.
|
64
|
+
Strings sends JSON output to either STDOUT or to a file.
|
65
|
+
Markdown output is written to a REFERENCE.md file in the module's main directory.
|
66
|
+
|
67
|
+
See the [Puppet Strings documentation](https://puppet.com/docs/puppet/latest/puppet_strings.html) for complete instructions for generating documentation with Strings.
|
68
|
+
|
69
|
+
For code comment style guidelines and examples, see the [Puppet Strings style guide](https://puppet.com/docs/puppet/latest/puppet_strings_style.html).
|
70
|
+
|
71
|
+
### Additional Resources
|
72
|
+
|
73
|
+
Here are a few other good resources for getting started with documentation:
|
74
|
+
|
75
|
+
* [Module README Template](https://puppet.com/docs/puppet/latest/puppet_strings.html)
|
76
|
+
* [YARD Getting Started Guide](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
|
77
|
+
* [YARD Tags Overview](http://www.rubydoc.info/gems/yard/file/docs/Tags.md)
|
78
|
+
|
79
|
+
## Developing and Contributing
|
80
|
+
|
81
|
+
We love contributions from the community!
|
82
|
+
|
83
|
+
If you'd like to contribute to `openvox-strings`, check out [CONTRIBUTING.md](https://github.com/voxpupuli/openvox-strings/blob/main/CONTRIBUTING.md) to get information on the contribution process.
|
84
|
+
|
85
|
+
### Running Specs
|
86
|
+
|
87
|
+
If you plan on developing features or fixing bugs in Puppet Strings, it is essential that you run specs before opening a pull request.
|
88
|
+
|
89
|
+
To run specs, run the `spec` rake task:
|
90
|
+
|
91
|
+
``` bash
|
92
|
+
bundle install --path .bundle/gems
|
93
|
+
bundle exec rake spec
|
94
|
+
```
|
95
|
+
|
96
|
+
### Running Acceptance Tests
|
97
|
+
|
98
|
+
To run specs, run the `acceptance` rake task:
|
99
|
+
|
100
|
+
``` bash
|
101
|
+
bundle install --path .bundle/gems
|
102
|
+
bundle exec rake acceptance
|
103
|
+
```
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
This codebase is licensed under Apache 2.0. However, the open source dependencies included in this codebase might be subject to other software licenses such as AGPL, GPL2.0, and MIT.
|
108
|
+
|
109
|
+
## Support
|
110
|
+
|
111
|
+
Please log issues in [GitHub issues](https://github.com/voxpupuli/openvox-strings/issues).
|
112
|
+
Check out [CONTRIBUTING.md](https://github.com/voxpupuli/openvox-strings/blob/main/CONTRIBUTING.md) for tips on writing _the best_ issues.
|
113
|
+
|
114
|
+
We use semantic version numbers for our releases and recommend that users upgrade to patch releases and minor releases as they become available.
|
115
|
+
|
116
|
+
Bug fixes and ongoing development will occur in minor releases for the current major version.
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'openvox-strings/json'
|
5
|
+
|
6
|
+
# The module for command line documentation related functionality.
|
7
|
+
module OpenvoxStrings::Describe
|
8
|
+
# Renders requested types or a summarized list in the current YARD registry to STDOUT.
|
9
|
+
# @param [Array] describe_types The list of names of the types to be displayed.
|
10
|
+
# @param [bool] list_types Create the summarized list instead of describing each type.
|
11
|
+
# @param [bool] show_type_providers Show details of the providers of a specified type.
|
12
|
+
# @param [bool] list_providers Create a summarized list of providers.
|
13
|
+
# @return [void]
|
14
|
+
def self.render(describe_types = [], list_types = false, show_type_providers = true, list_providers = false)
|
15
|
+
document = {
|
16
|
+
defined_types: YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash),
|
17
|
+
resource_types: YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash),
|
18
|
+
providers: YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash)
|
19
|
+
}
|
20
|
+
# if --list flag passed, produce a summarized list of types
|
21
|
+
if list_types
|
22
|
+
puts 'These are the types known to puppet:'
|
23
|
+
document[:resource_types].each { |t| list_one(t) }
|
24
|
+
|
25
|
+
# if a type(s) has been passed, show the details of that type(s)
|
26
|
+
elsif describe_types
|
27
|
+
type_names = {}
|
28
|
+
describe_types.each { |name| type_names[name] = true }
|
29
|
+
|
30
|
+
document[:resource_types].each do |t|
|
31
|
+
show_one_type(t, show_type_providers) if type_names[t[:name].to_s]
|
32
|
+
end
|
33
|
+
|
34
|
+
# if --providers flag passed, produce a summarized list of providers
|
35
|
+
elsif list_providers
|
36
|
+
puts 'These are the providers known to puppet:'
|
37
|
+
document[:providers].each { |t| list_one(t) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.show_one_type(resource_type, providers = true)
|
42
|
+
puts format("\n%<name>s\n%<underscore>s", name: resource_type[:name], underscore: '=' * resource_type[:name].length)
|
43
|
+
puts resource_type[:docstring][:text]
|
44
|
+
|
45
|
+
combined_list = (resource_type[:parameters].nil? ? [] : resource_type[:parameters]) +
|
46
|
+
(resource_type[:properties].nil? ? [] : resource_type[:properties])
|
47
|
+
|
48
|
+
return unless combined_list.any?
|
49
|
+
|
50
|
+
puts "\nParameters\n----------"
|
51
|
+
combined_list.sort_by { |p| p[:name] }.each { |p| show_one_parameter(p) }
|
52
|
+
return unless providers
|
53
|
+
|
54
|
+
puts "\nProviders\n---------"
|
55
|
+
resource_type[:providers]&.sort_by { |p| p[:name] }&.each { |p| puts p[:name].to_s.ljust(15) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.show_one_parameter(parameter)
|
59
|
+
puts format("\n- **%<name>s**\n", name: parameter[:name])
|
60
|
+
puts parameter[:description]
|
61
|
+
puts format('Valid values are `%<values>s`.', values: parameter[:values].join('`, `')) unless parameter[:values].nil?
|
62
|
+
puts format('Requires features %<required_features>s.', required_features: parameter[:required_features]) unless parameter[:required_features].nil?
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.list_one(object)
|
66
|
+
targetlength = 48
|
67
|
+
shortento = targetlength - 4
|
68
|
+
contentstring = object[:docstring][:text]
|
69
|
+
end_of_line = contentstring.index("\n") # "." gives closer results to old describeb, but breaks for '.k5login'
|
70
|
+
contentstring = contentstring[0..end_of_line] unless end_of_line.nil?
|
71
|
+
contentstring = "#{contentstring[0..shortento]} ..." if contentstring.length > targetlength
|
72
|
+
|
73
|
+
puts "#{object[:name].to_s.ljust(15)} - #{contentstring}"
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# The module for JSON related functionality.
|
6
|
+
module OpenvoxStrings::Json
|
7
|
+
# Renders the current YARD registry as JSON to the given file (or STDOUT if nil).
|
8
|
+
# @param [String] file The path to the output file to render the registry to. If nil, output will be to STDOUT.
|
9
|
+
# @return [void]
|
10
|
+
def self.render(file = nil)
|
11
|
+
document = {
|
12
|
+
puppet_classes: YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash),
|
13
|
+
data_types: YARD::Registry.all(:puppet_data_type).sort_by!(&:name).map!(&:to_hash),
|
14
|
+
data_type_aliases: YARD::Registry.all(:puppet_data_type_alias).sort_by!(&:name).map!(&:to_hash),
|
15
|
+
defined_types: YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash),
|
16
|
+
resource_types: YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash),
|
17
|
+
providers: YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash),
|
18
|
+
puppet_functions: YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash),
|
19
|
+
puppet_tasks: YARD::Registry.all(:puppet_task).sort_by!(&:name).map!(&:to_hash),
|
20
|
+
puppet_plans: YARD::Registry.all(:puppet_plan).sort_by!(&:name).map!(&:to_hash)
|
21
|
+
# TODO: Need Ruby documentation?
|
22
|
+
}
|
23
|
+
|
24
|
+
if file
|
25
|
+
File.open(file, 'w') do |f|
|
26
|
+
f.write(JSON.pretty_generate(document))
|
27
|
+
f.write("\n")
|
28
|
+
end
|
29
|
+
else
|
30
|
+
puts JSON.pretty_generate(document)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings'
|
4
|
+
require 'openvox-strings/json'
|
5
|
+
require 'openvox-strings/yard'
|
6
|
+
require 'openvox-strings/markdown/helpers'
|
7
|
+
|
8
|
+
# Implements classes that make elements in a YARD::Registry hash easily accessible for template.
|
9
|
+
module OpenvoxStrings::Markdown
|
10
|
+
# This class makes elements in a YARD::Registry hash easily accessible for templates.
|
11
|
+
#
|
12
|
+
# Here's an example hash:
|
13
|
+
# {:name=>:klass,
|
14
|
+
# :file=>"(stdin)",
|
15
|
+
# :line=>16,
|
16
|
+
# :inherits=>"foo::bar",
|
17
|
+
# :docstring=>
|
18
|
+
# {:text=>"An overview for a simple class.",
|
19
|
+
# :tags=>
|
20
|
+
# [{:tag_name=>"summary", :text=>"A simple class."},
|
21
|
+
# {:tag_name=>"since", :text=>"1.0.0"},
|
22
|
+
# {:tag_name=>"see", :name=>"www.puppet.com"},
|
23
|
+
# {:tag_name=>"deprecated", :text=>"No longer supported and will be removed in a future release"},
|
24
|
+
# {:tag_name=>"example",
|
25
|
+
# :text=>
|
26
|
+
# "class { 'klass':\n" +
|
27
|
+
# " param1 => 1,\n" +
|
28
|
+
# " param3 => 'foo',\n" +
|
29
|
+
# "}",
|
30
|
+
# :name=>"This is an example"},
|
31
|
+
# {:tag_name=>"author", :text=>"eputnam"},
|
32
|
+
# {:tag_name=>"option", :name=>"opts"},
|
33
|
+
# {:tag_name=>"raise", :text=>"SomeError"},
|
34
|
+
# {:tag_name=>"param",
|
35
|
+
# :text=>"First param.",
|
36
|
+
# :types=>["Integer"],
|
37
|
+
# :name=>"param1"},
|
38
|
+
# {:tag_name=>"param",
|
39
|
+
# :text=>"Second param.",
|
40
|
+
# :types=>["Any"],
|
41
|
+
# :name=>"param2"},
|
42
|
+
# {:tag_name=>"param",
|
43
|
+
# :text=>"Third param.",
|
44
|
+
# :types=>["String"],
|
45
|
+
# :name=>"param3"}]},
|
46
|
+
# :defaults=>{"param1"=>"1", "param2"=>"undef", "param3"=>"'hi'"},
|
47
|
+
# :source=>
|
48
|
+
# "class klass (\n" +
|
49
|
+
# " Integer $param1 = 1,\n" +
|
50
|
+
# " $param2 = undef,\n" +
|
51
|
+
# " String $param3 = 'hi'\n" +
|
52
|
+
# ") inherits foo::bar {\n" +
|
53
|
+
# "}"}
|
54
|
+
class Base
|
55
|
+
# Helpers for ERB templates
|
56
|
+
include OpenvoxStrings::Markdown::Helpers
|
57
|
+
|
58
|
+
# Set or return the name of the group
|
59
|
+
#
|
60
|
+
# @param [Optional[String]] Name of the group to set
|
61
|
+
# @return [String] Name of the group
|
62
|
+
def self.group_name(name = nil)
|
63
|
+
@group_name = name if name
|
64
|
+
@group_name
|
65
|
+
end
|
66
|
+
|
67
|
+
# Set or return the types registered with YARD
|
68
|
+
#
|
69
|
+
# @param [Optional[Array[Symbol]]] Array of symbols registered with YARD to set
|
70
|
+
# @return [Array[Symbol]] Array of symbols registered with YARD
|
71
|
+
def self.yard_types(types = nil)
|
72
|
+
@yard_types = types if types
|
73
|
+
@yard_types
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [Array] list of items
|
77
|
+
def self.items
|
78
|
+
yard_types
|
79
|
+
.flat_map { |type| YARD::Registry.all(type) }
|
80
|
+
.sort_by(&:name)
|
81
|
+
.map(&:to_hash)
|
82
|
+
.map { |i| new(i) }
|
83
|
+
end
|
84
|
+
|
85
|
+
def initialize(registry, component_type)
|
86
|
+
@type = component_type
|
87
|
+
@registry = registry
|
88
|
+
@tags = registry[:docstring][:tags] || []
|
89
|
+
end
|
90
|
+
|
91
|
+
# generate 1:1 tag methods
|
92
|
+
# e.g. {:tag_name=>"author", :text=>"eputnam"}
|
93
|
+
{ return_val: 'return',
|
94
|
+
since: 'since',
|
95
|
+
summary: 'summary',
|
96
|
+
note: 'note',
|
97
|
+
todo: 'todo',
|
98
|
+
deprecated: 'deprecated', }.each do |method_name, tag_name|
|
99
|
+
# @return [String] unless the tag is nil or the string.empty?
|
100
|
+
define_method method_name do
|
101
|
+
@tags.find { |tag| tag[:tag_name] == tag_name && !tag[:text].empty? }[:text] if @tags.any? { |tag| tag[:tag_name] == tag_name && !tag[:text].empty? }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# @return [String] top-level name
|
106
|
+
def name
|
107
|
+
@registry[:name]&.to_s
|
108
|
+
end
|
109
|
+
|
110
|
+
# @return [String] 'Overview' text (untagged text)
|
111
|
+
def text
|
112
|
+
@registry[:docstring][:text] unless @registry[:docstring][:text].empty?
|
113
|
+
end
|
114
|
+
|
115
|
+
# @return [String] data type of return value
|
116
|
+
def return_type
|
117
|
+
@tags.find { |tag| tag[:tag_name] == 'return' }[:types][0] if @tags.any? { |tag| tag[:tag_name] == 'return' }
|
118
|
+
end
|
119
|
+
|
120
|
+
# @return [String] text from @since tag
|
121
|
+
def since
|
122
|
+
@tags.find { |tag| tag[:tag_name] == 'since' }[:text] if @tags.any? { |tag| tag[:tag_name] == 'since' }
|
123
|
+
end
|
124
|
+
|
125
|
+
# @return [Array] @see tag hashes
|
126
|
+
def see
|
127
|
+
select_tags('see')
|
128
|
+
end
|
129
|
+
|
130
|
+
# @return [Array] parameter tag hashes
|
131
|
+
def params
|
132
|
+
tags = @tags.select { |tag| tag[:tag_name] == 'param' }.map do |param|
|
133
|
+
param[:link] = clean_link("$#{name}::#{param[:name]}")
|
134
|
+
param
|
135
|
+
end
|
136
|
+
tags.empty? ? nil : tags
|
137
|
+
end
|
138
|
+
|
139
|
+
# @return [Array] example tag hashes
|
140
|
+
def examples
|
141
|
+
select_tags('example')
|
142
|
+
end
|
143
|
+
|
144
|
+
# @return [Array] raise tag hashes
|
145
|
+
def raises
|
146
|
+
select_tags('raise')
|
147
|
+
end
|
148
|
+
|
149
|
+
# @return [Array] option tag hashes
|
150
|
+
def options
|
151
|
+
select_tags('option')
|
152
|
+
end
|
153
|
+
|
154
|
+
# @return [Array] enum tag hashes
|
155
|
+
def enums
|
156
|
+
select_tags('enum')
|
157
|
+
end
|
158
|
+
|
159
|
+
# @param parameter_name
|
160
|
+
# parameter name to match to option tags
|
161
|
+
# @return [Array] option tag hashes that have a parent parameter_name
|
162
|
+
def options_for_param(parameter_name)
|
163
|
+
opts_for_p = options.select { |o| o[:parent] == parameter_name } unless options.nil?
|
164
|
+
opts_for_p unless opts_for_p.nil? || opts_for_p.empty?
|
165
|
+
end
|
166
|
+
|
167
|
+
# @param parameter_name
|
168
|
+
# parameter name to match to enum tags
|
169
|
+
# @return [Array] enum tag hashes that have a parent parameter_name
|
170
|
+
def enums_for_param(parameter_name)
|
171
|
+
enums_for_p = enums.select { |e| e[:parent] == parameter_name } unless enums.nil?
|
172
|
+
enums_for_p unless enums_for_p.nil? || enums_for_p.empty?
|
173
|
+
end
|
174
|
+
|
175
|
+
# @return [Hash] any defaults found for the component
|
176
|
+
def defaults
|
177
|
+
@registry[:defaults] unless @registry[:defaults].nil?
|
178
|
+
end
|
179
|
+
|
180
|
+
# @return [Hash] information needed for the table of contents
|
181
|
+
def toc_info
|
182
|
+
{
|
183
|
+
name: name.to_s,
|
184
|
+
link: link,
|
185
|
+
desc: summary || @registry[:docstring][:text][0..140].tr("\n", ' '),
|
186
|
+
private: private?,
|
187
|
+
}
|
188
|
+
end
|
189
|
+
|
190
|
+
# @return [String] makes the component name suitable for a GitHub markdown link
|
191
|
+
def link
|
192
|
+
clean_link(name)
|
193
|
+
end
|
194
|
+
|
195
|
+
def private?
|
196
|
+
@tags.any? { |tag| tag[:tag_name] == 'api' && tag[:text] == 'private' }
|
197
|
+
end
|
198
|
+
|
199
|
+
def word_wrap(text, line_width: 120, break_sequence: "\n")
|
200
|
+
return unless text
|
201
|
+
|
202
|
+
text.split("\n").map! do |line|
|
203
|
+
(line.length > line_width) ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1#{break_sequence}").strip : line
|
204
|
+
end * break_sequence
|
205
|
+
end
|
206
|
+
|
207
|
+
# @return [String] full markdown rendering of a component
|
208
|
+
def render(template)
|
209
|
+
file = File.join(File.dirname(__FILE__), 'templates', template)
|
210
|
+
begin
|
211
|
+
OpenvoxStrings::Markdown.erb(file).result(binding)
|
212
|
+
rescue StandardError => e
|
213
|
+
raise "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
private
|
218
|
+
|
219
|
+
def select_tags(name)
|
220
|
+
tags = @tags.select { |tag| tag[:tag_name] == name }
|
221
|
+
tags.empty? ? nil : tags
|
222
|
+
end
|
223
|
+
|
224
|
+
# Convert an input into a string appropriate for an anchor name.
|
225
|
+
#
|
226
|
+
# This converts any character not suitable for an id attribute into a '-'. Generally we're running this on Puppet identifiers for types and
|
227
|
+
# variables, so we only need to worry about the special characters ':' and '$'. With namespaces Puppet variables this should always be produce a
|
228
|
+
# unique result from a unique input, since ':' only appears in pairs, '$' only appears at the beginning, and '-' never appears.
|
229
|
+
#
|
230
|
+
# @param [String] the input to convert
|
231
|
+
# @return [String] the anchor-safe string
|
232
|
+
def clean_link(input)
|
233
|
+
input.tr('^a-zA-Z0-9_-', '-')
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/markdown/base'
|
4
|
+
|
5
|
+
module OpenvoxStrings::Markdown
|
6
|
+
# This class encapsualtes ruby data types and puppet type aliases
|
7
|
+
class DataType < Base
|
8
|
+
attr_reader :alias_of, :functions
|
9
|
+
|
10
|
+
group_name 'Data types'
|
11
|
+
yard_types %i[puppet_data_type puppet_data_type_alias]
|
12
|
+
|
13
|
+
def initialize(registry)
|
14
|
+
@template = 'data_type.erb'
|
15
|
+
super(registry, 'data type')
|
16
|
+
@alias_of = registry[:alias_of] unless registry[:alias_of].nil?
|
17
|
+
@functions = @registry[:functions]&.map { |func| DataType::Function.new(func) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def render
|
21
|
+
super(@template)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Generates Markdown for a Puppet Function.
|
26
|
+
class DataType::Function < Base
|
27
|
+
def initialize(registry)
|
28
|
+
super(registry, 'data_type_function')
|
29
|
+
end
|
30
|
+
|
31
|
+
def render
|
32
|
+
super('data_type_function.erb')
|
33
|
+
end
|
34
|
+
|
35
|
+
def signature
|
36
|
+
@registry[:signature]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/markdown/base'
|
4
|
+
|
5
|
+
module OpenvoxStrings::Markdown
|
6
|
+
# Generates Markdown for a Puppet Defined Type.
|
7
|
+
class DefinedType < Base
|
8
|
+
group_name 'Defined types'
|
9
|
+
yard_types [:puppet_defined_type]
|
10
|
+
|
11
|
+
def initialize(registry)
|
12
|
+
@template = 'classes_and_defines.erb'
|
13
|
+
super(registry, 'defined type')
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
super(@template)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/markdown/base'
|
4
|
+
|
5
|
+
module OpenvoxStrings::Markdown
|
6
|
+
# Generates Markdown for a Puppet Function.
|
7
|
+
class Function < Base
|
8
|
+
attr_reader :signatures
|
9
|
+
|
10
|
+
group_name 'Functions'
|
11
|
+
yard_types [:puppet_function]
|
12
|
+
|
13
|
+
def initialize(registry)
|
14
|
+
@template = 'function.erb'
|
15
|
+
super(registry, 'function')
|
16
|
+
@signatures = []
|
17
|
+
registry[:signatures].each do |sig|
|
18
|
+
@signatures.push(Signature.new(sig))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def render
|
23
|
+
super(@template)
|
24
|
+
end
|
25
|
+
|
26
|
+
def type
|
27
|
+
t = @registry[:type]
|
28
|
+
if t.include?('ruby4x')
|
29
|
+
'Ruby 4.x API'
|
30
|
+
elsif t.include?('ruby3')
|
31
|
+
'Ruby 3.x API'
|
32
|
+
elsif t.include?('ruby')
|
33
|
+
'Ruby'
|
34
|
+
else
|
35
|
+
'Puppet Language'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def error_type(type)
|
40
|
+
"`#{type.split[0]}`"
|
41
|
+
end
|
42
|
+
|
43
|
+
def error_text(text)
|
44
|
+
text.split.drop(1).join(' ').to_s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Implements methods to retrieve information about a function signature.
|
49
|
+
class Function::Signature < Base
|
50
|
+
def initialize(registry)
|
51
|
+
@registry = registry
|
52
|
+
super(@registry, 'function signature')
|
53
|
+
end
|
54
|
+
|
55
|
+
def signature
|
56
|
+
@registry[:signature]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Helpers for rendering Markdown
|
4
|
+
module OpenvoxStrings::Markdown::Helpers
|
5
|
+
# Formats code as either inline or a block.
|
6
|
+
#
|
7
|
+
# Note that this does not do any escaping even if the code contains ` or ```.
|
8
|
+
#
|
9
|
+
# @param [String] code The code to format.
|
10
|
+
# @param [Symbol] type The type of the code, e.g. :text, :puppet, or :ruby.
|
11
|
+
# @param [String] block_prefix String to insert before if it’s a block.
|
12
|
+
# @param [String] inline_prefix String to insert before if it’s inline.
|
13
|
+
# @returns [String] Markdown
|
14
|
+
def code_maybe_block(code, type: :puppet, block_prefix: "\n\n", inline_prefix: ' ')
|
15
|
+
if code.to_s.include?("\n")
|
16
|
+
"#{block_prefix}```#{type}\n#{code}\n```"
|
17
|
+
else
|
18
|
+
"#{inline_prefix}`#{code}`"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/markdown/base'
|
4
|
+
|
5
|
+
module OpenvoxStrings::Markdown
|
6
|
+
# Generates Markdown for a Puppet Class.
|
7
|
+
class PuppetClass < Base
|
8
|
+
group_name 'Classes'
|
9
|
+
yard_types [:puppet_class]
|
10
|
+
|
11
|
+
def initialize(registry)
|
12
|
+
@template = 'classes_and_defines.erb'
|
13
|
+
super(registry, 'class')
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
super(@template)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/markdown/base'
|
4
|
+
|
5
|
+
module OpenvoxStrings::Markdown
|
6
|
+
# Generates Markdown for a Puppet Plan.
|
7
|
+
class PuppetPlan < Base
|
8
|
+
group_name 'Plans'
|
9
|
+
yard_types [:puppet_plan]
|
10
|
+
|
11
|
+
def initialize(registry)
|
12
|
+
@template = 'classes_and_defines.erb'
|
13
|
+
super(registry, 'plan')
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
super(@template)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openvox-strings/markdown/base'
|
4
|
+
|
5
|
+
module OpenvoxStrings::Markdown
|
6
|
+
# Generates Markdown for a Puppet Task.
|
7
|
+
class PuppetTask < Base
|
8
|
+
group_name 'Tasks'
|
9
|
+
yard_types [:puppet_task]
|
10
|
+
|
11
|
+
def initialize(registry)
|
12
|
+
@template = 'puppet_task.erb'
|
13
|
+
@registry = registry
|
14
|
+
super(registry, 'task')
|
15
|
+
end
|
16
|
+
|
17
|
+
def render
|
18
|
+
super(@template)
|
19
|
+
end
|
20
|
+
|
21
|
+
def supports_noop
|
22
|
+
@registry[:supports_noop]
|
23
|
+
end
|
24
|
+
|
25
|
+
def input_method
|
26
|
+
@registry[:input_method]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|