puppet-strings 2.8.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +267 -225
  3. data/README.md +52 -65
  4. data/lib/puppet/face/strings.rb +30 -50
  5. data/lib/puppet/feature/rgen.rb +1 -1
  6. data/lib/puppet/feature/yard.rb +1 -1
  7. data/lib/puppet-strings/describe.rb +18 -18
  8. data/lib/puppet-strings/markdown/base.rb +63 -28
  9. data/lib/puppet-strings/markdown/data_type.rb +4 -0
  10. data/lib/puppet-strings/markdown/defined_type.rb +4 -0
  11. data/lib/puppet-strings/markdown/function.rb +13 -8
  12. data/lib/puppet-strings/markdown/helpers.rb +21 -0
  13. data/lib/puppet-strings/markdown/puppet_class.rb +4 -0
  14. data/lib/puppet-strings/markdown/puppet_plan.rb +4 -0
  15. data/lib/puppet-strings/markdown/puppet_task.rb +4 -1
  16. data/lib/puppet-strings/markdown/resource_type.rb +13 -3
  17. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +4 -4
  18. data/lib/puppet-strings/markdown/templates/data_type.erb +5 -9
  19. data/lib/puppet-strings/markdown/templates/data_type_function.erb +1 -1
  20. data/lib/puppet-strings/markdown/templates/function.erb +1 -1
  21. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  22. data/lib/puppet-strings/markdown/templates/resource_type.erb +6 -6
  23. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +8 -8
  24. data/lib/puppet-strings/markdown.rb +62 -20
  25. data/lib/puppet-strings/monkey_patches/display_object_command.rb +4 -1
  26. data/lib/puppet-strings/tasks/generate.rb +8 -10
  27. data/lib/puppet-strings/tasks/gh_pages.rb +6 -5
  28. data/lib/puppet-strings/tasks/validate.rb +42 -0
  29. data/lib/puppet-strings/tasks.rb +5 -6
  30. data/lib/puppet-strings/version.rb +1 -1
  31. data/lib/puppet-strings/yard/code_objects/class.rb +2 -2
  32. data/lib/puppet-strings/yard/code_objects/data_type.rb +4 -4
  33. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +1 -1
  34. data/lib/puppet-strings/yard/code_objects/defined_type.rb +2 -2
  35. data/lib/puppet-strings/yard/code_objects/function.rb +11 -11
  36. data/lib/puppet-strings/yard/code_objects/group.rb +1 -1
  37. data/lib/puppet-strings/yard/code_objects/plan.rb +4 -2
  38. data/lib/puppet-strings/yard/code_objects/provider.rb +2 -2
  39. data/lib/puppet-strings/yard/code_objects/task.rb +6 -7
  40. data/lib/puppet-strings/yard/code_objects/type.rb +6 -5
  41. data/lib/puppet-strings/yard/handlers/helpers.rb +3 -4
  42. data/lib/puppet-strings/yard/handlers/json/base.rb +2 -1
  43. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +4 -4
  44. data/lib/puppet-strings/yard/handlers/puppet/base.rb +7 -2
  45. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -2
  46. data/lib/puppet-strings/yard/handlers/ruby/base.rb +3 -2
  47. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +19 -16
  48. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +70 -50
  49. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +2 -1
  50. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +12 -9
  51. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +27 -27
  52. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +2 -3
  53. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +2 -1
  54. data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -2
  55. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +3 -3
  56. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +7 -7
  57. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +16 -23
  58. data/lib/puppet-strings/yard/parsers.rb +1 -0
  59. data/lib/puppet-strings/yard/tags/enum_tag.rb +1 -2
  60. data/lib/puppet-strings/yard/tags/factory.rb +1 -1
  61. data/lib/puppet-strings/yard/tags/overload_tag.rb +7 -7
  62. data/lib/puppet-strings/yard/tags/parameter_directive.rb +2 -2
  63. data/lib/puppet-strings/yard/tags/property_directive.rb +2 -2
  64. data/lib/puppet-strings/yard/tags/summary_tag.rb +1 -2
  65. data/lib/puppet-strings/yard/util.rb +11 -4
  66. data/lib/puppet-strings/yard.rb +6 -6
  67. data/lib/puppet-strings.rb +7 -13
  68. metadata +15 -22
  69. data/lib/puppet-strings/markdown/data_types.rb +0 -43
  70. data/lib/puppet-strings/markdown/defined_types.rb +0 -39
  71. data/lib/puppet-strings/markdown/functions.rb +0 -40
  72. data/lib/puppet-strings/markdown/puppet_classes.rb +0 -39
  73. data/lib/puppet-strings/markdown/puppet_plans.rb +0 -39
  74. data/lib/puppet-strings/markdown/puppet_tasks.rb +0 -36
  75. data/lib/puppet-strings/markdown/resource_types.rb +0 -39
  76. data/lib/puppet-strings/markdown/table_of_contents.rb +0 -26
data/README.md CHANGED
@@ -1,24 +1,16 @@
1
- Puppet Strings
2
- ==============
3
- [![Build Status](https://travis-ci.org/puppetlabs/puppet-strings.png?branch=main)](https://travis-ci.org/puppetlabs/puppet-strings) [![Gem Version](https://badge.fury.io/rb/puppet-strings.svg)](https://badge.fury.io/rb/puppet-strings)
1
+ # Puppet strings
4
2
 
5
- 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.
3
+ [![ci](https://github.com/puppetlabs/puppet-strings/actions/workflows/ci.yml/badge.svg)](https://github.com/puppetlabs/puppet-strings/actions/workflows/ci.yml) [![Gem Version](https://badge.fury.io/rb/puppet-strings.svg)](https://badge.fury.io/rb/puppet-strings)
6
4
 
7
-
8
- | | |
9
- | -------------- |---------------------------------------------------------------- |
10
- | *Code* | [GitHub][repo] |
11
- | *Issues* | [GitHub issues][issues] |
12
- | *License* | [Apache 2.0][LICENSE] |
13
- | *Change log* | [CHANGELOG.md][changelog] |
14
- | *Contributing* | [CONTRIBUTING.md][contributing] and [COMMITTERS.md][committers] |
5
+ Puppet Strings generates documentation for Puppet code and extensions written in Puppet and Ruby.
6
+ Strings processes code and YARD-style code comments to create documentation in HTML, Markdown, or JSON formats.
15
7
 
16
8
  ## Installing Puppet Strings
17
9
 
18
10
  ### Requirements
19
11
 
20
- * Ruby 2.1.9 or newer
21
- * Puppet 4.0.0 or newer
12
+ * Ruby 2.7.0 or newer
13
+ * Puppet 6.0.0 or newer
22
14
 
23
15
  ### Install Puppet Strings
24
16
 
@@ -28,7 +20,7 @@ Installation instructions vary slightly depending on how you have installed Pupp
28
20
 
29
21
  Install the `puppet-strings` gem into the `puppet-agent` environment:
30
22
 
31
- ```
23
+ ``` bash
32
24
  sudo /opt/puppetlabs/puppet/bin/gem install puppet-strings
33
25
  ```
34
26
 
@@ -36,35 +28,44 @@ sudo /opt/puppetlabs/puppet/bin/gem install puppet-strings
36
28
 
37
29
  Install the `puppet-strings` gem into the same Ruby installation where you have installed the `puppet` gem:
38
30
 
39
- ```
31
+ ``` bash
40
32
  gem install puppet-strings
41
33
  ```
42
34
 
43
35
  ### Configure Puppet Strings (Optional)
44
36
 
45
- 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`.
37
+ To use YARD options with Puppet Strings, specify a `.yardopts` file in the same directory in which you run `puppet strings`.
38
+
39
+ Puppet Strings supports the Markdown format and automatically sets the YARD `markup` option to `markdown`.
40
+
41
+ To see a list of available YARD options, run `yard help doc`.
46
42
 
47
- 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).
43
+ For details about YARD options configuration, see the [YARD docs](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md#config).
48
44
 
49
45
  ## Generating documentation with Puppet Strings
50
46
 
51
47
  By default, Puppet Strings outputs documentation as HTML, or you can specify JSON or Markdown output instead.
52
48
 
53
- 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.
49
+ Strings generates reference documentation based on the code and Strings code comments in all Puppet and
50
+ Ruby source files under the `./manifests/`, `./functions/`, `./lib/`, `./types/`, and `./tasks/` directories.
54
51
 
55
52
  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.
56
53
 
57
- 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.
54
+ JSON and Markdown output include the reference documentation only.
55
+ Strings sends JSON output to either STDOUT or to a file.
56
+ Markdown output is written to a REFERENCE.md file in the module's main directory.
58
57
 
59
- See the [Puppet Strings documentation](https://puppet.com/docs/puppet/latest/puppet_strings.html) for complete instructions for generating documentation with Strings. For code comment style guidelines and examples, see the [Puppet Strings style guide](https://puppet.com/docs/puppet/5.5/puppet_strings_style.html).
58
+ See the [Puppet Strings documentation](https://puppet.com/docs/puppet/latest/puppet_strings.html) for complete instructions for generating documentation with Strings.
59
+
60
+ For code comment style guidelines and examples, see the [Puppet Strings style guide](https://puppet.com/docs/puppet/latest/puppet_strings_style.html).
60
61
 
61
62
  ### Additional Resources
62
63
 
63
64
  Here are a few other good resources for getting started with documentation:
64
65
 
65
- * [Module README Template](https://puppet.com/docs/puppet/latest/puppet_strings.html)
66
- * [YARD Getting Started Guide](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
67
- * [YARD Tags Overview](http://www.rubydoc.info/gems/yard/file/docs/Tags.md)
66
+ * [Module README Template](https://puppet.com/docs/puppet/latest/puppet_strings.html)
67
+ * [YARD Getting Started Guide](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
68
+ * [YARD Tags Overview](http://www.rubydoc.info/gems/yard/file/docs/Tags.md)
68
69
 
69
70
  ## Developing and Contributing
70
71
 
@@ -78,72 +79,58 @@ If you plan on developing features or fixing bugs in Puppet Strings, it is essen
78
79
 
79
80
  To run specs, run the `spec` rake task:
80
81
 
81
- $ bundle install --path .bundle/gems
82
- $ bundle exec rake spec
82
+ ``` bash
83
+ bundle install --path .bundle/gems
84
+ bundle exec rake spec
85
+ ```
83
86
 
84
87
  ### Running Acceptance Tests
85
88
 
86
- We are experimenting with a new tool for running acceptance tests. It's name is [puppet_litmus](https://github.com/puppetlabs/puppet_litmus) and replaces beaker as the test runner.
89
+ Acceptance tests can be executed with [puppet_litmus](https://github.com/puppetlabs/puppet_litmus).
87
90
 
88
91
  An example of running the acceptance tests locally with Docker:
89
92
 
90
93
  1. Ensure [Docker](https://www.docker.com/products/docker-desktop) is installed and running.
91
94
 
92
- 2. Install Ruby gems. This step can be skipped if you have already followed the [Running Specs](#running-specs) instructions
95
+ 2. Install Ruby gems. This step can be skipped if you have already followed the [Running Specs](#running-specs) instructions.
93
96
 
94
- ``` text
95
- $ bundle install --path .bundle/gems
96
- ```
97
+ ``` bash
98
+ bundle install --path .bundle/gems
99
+ ```
97
100
 
98
101
  3. Provision a docker container, in this case CentOS 7
99
102
 
100
- ``` text
101
- $ bundle exec rake 'litmus:provision[docker, centos:7]'
102
- ```
103
+ ``` bash
104
+ bundle exec rake 'litmus:provision[docker, centos:7]'
105
+ ```
103
106
 
104
107
  4. Install test items; Puppet Agent, our test module, and the puppet-strings gem built from this source code
105
108
 
106
- ``` text
107
- $ bundle exec rake 'litmus:install_agent[puppet6]'
108
- $ bundle exec rake 'litmus:install_modules_from_directory[./spec/fixtures/acceptance/modules]'
109
- $ bundle exec rake litmus:install_gems
110
- ```
109
+ ``` bash
110
+ bundle exec rake 'litmus:install_agent[puppet6]'
111
+ bundle exec rake 'litmus:install_modules_from_directory[./spec/fixtures/acceptance/modules]'
112
+ bundle exec rake litmus:install_gems
113
+ ```
111
114
 
112
115
  5. Run the acceptance tests. These tests can be run more than once without the need to run the provisioning steps again
113
116
 
114
- ``` text
115
- $ bundle exec rake litmus:acceptance:parallel
116
- ```
117
+ ``` bash
118
+ bundle exec rake litmus:acceptance:parallel
119
+ ```
117
120
 
118
121
  6. Remove any test containers
119
122
 
120
- ``` text
121
- $ bundle exec rake litmus:tear_down
122
- ```
123
-
124
- The [Litmus Wiki](https://github.com/puppetlabs/puppet_litmus/wiki) contains more indepth information about Litmus. There is also a tutorial on using Litmus with an example [Puppet Module](https://github.com/puppetlabs/puppet_litmus/wiki/Tutorial:-use-Litmus-to-execute-acceptance-tests-with-a-sample-module-(MoTD)#install-the-necessary-gems-for-the-module)
125
-
126
-
127
- An example of run the acceptance tests follow the instructions [here].
123
+ ``` bash
124
+ bundle exec rake litmus:tear_down
125
+ ```
128
126
 
129
127
  ## Support
130
128
 
131
- Please log issues in [GitHub issues][issues]. Check out [CONTRIBUTING.md][contributing] for tips on writing _the best_ issues.
129
+ Please log issues in [GitHub issues](https://github.com/puppetlabs/puppet-strings/issues).
130
+ Check out [CONTRIBUTING.md](https://github.com/puppetlabs/puppet-strings/blob/main/CONTRIBUTING.md) for tips on writing _the best_ issues.
132
131
 
133
- A [mailing list](https://groups.google.com/forum/?fromgroups#!forum/puppet-users) is available for asking questions and getting help from others.
134
-
135
- There is also an active community on the [Puppet community Slack][] in the #forge-modules channel.
132
+ There is also an active community on the [Puppet community Slack](https://slack.puppet.com) in the #forge-modules channel.
136
133
 
137
134
  We use semantic version numbers for our releases and recommend that users upgrade to patch releases and minor releases as they become available.
138
135
 
139
- 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.
140
-
141
-
142
- [repo]: https://github.com/puppetlabs/puppet-strings
143
- [issues]: https://github.com/puppetlabs/puppet-strings/issues
144
- [LICENSE]: https://github.com/puppetlabs/puppet-strings/blob/main/LICENSE
145
- [changelog]: https://github.com/puppetlabs/puppet-strings/blob/main/CHANGELOG.md
146
- [contributing]: https://github.com/puppetlabs/puppet-strings/blob/main/CONTRIBUTING.md
147
- [committers]: https://github.com/puppetlabs/puppet-strings/blob/main/COMMITTERS.md
148
- [Puppet community Slack]: https://slack.puppet.com
149
-
136
+ Bug fixes and ongoing development will occur in minor releases for the current major version.
@@ -18,12 +18,6 @@ Puppet::Face.define(:strings, '0.0.1') do
18
18
  option '--markup FORMAT' do
19
19
  summary "The markup format to use for docstring text (defaults to 'markdown')."
20
20
  end
21
- option '--emit-json-stdout' do
22
- summary 'DEPRECATED: Print JSON representation of the documentation to stdout.'
23
- end
24
- option '--emit-json PATH' do
25
- summary 'DEPRECATED: Write JSON representation of the documentation to the given file.'
26
- end
27
21
 
28
22
  summary 'Generate documentation from files.'
29
23
  arguments '[[search_pattern] ...]'
@@ -32,9 +26,9 @@ Puppet::Face.define(:strings, '0.0.1') do
32
26
  check_required_features
33
27
  require 'puppet-strings'
34
28
 
35
- PuppetStrings::generate(
29
+ PuppetStrings.generate(
36
30
  args.count > 1 ? args[0..-2] : PuppetStrings::DEFAULT_SEARCH_PATTERNS,
37
- build_generate_options(args.last)
31
+ build_generate_options(args.last),
38
32
  )
39
33
  nil
40
34
  end
@@ -79,35 +73,34 @@ Puppet::Face.define(:strings, '0.0.1') do
79
73
  return
80
74
  end
81
75
  puts 'Starting YARD documentation server.'
82
- PuppetStrings::run_server('-m', *module_docs)
76
+ PuppetStrings.run_server('-m', *module_docs)
83
77
  nil
84
78
  end
85
79
  end
86
80
 
87
- action(:describe) do #This is Kris' experiment with string based describe
88
- option "--list" do
89
- summary "list types"
81
+ action(:describe) do # This is Kris' experiment with string based describe
82
+ option '--list' do
83
+ summary 'list types'
90
84
  end
91
- option "--providers" do
92
- summary "provide details on providers"
85
+ option '--providers' do
86
+ summary 'provide details on providers'
93
87
  end
94
88
 
95
- #TODO: Implement the rest of describe behavior
96
- # * --help:
97
- # Print this help text
89
+ # TODO: Implement the rest of describe behavior
90
+ # * --help:
91
+ # Print this help text
98
92
 
99
- # * --providers:
100
- # Describe providers in detail for each type
93
+ # * --providers:
94
+ # Describe providers in detail for each type
101
95
 
102
- # * --list:
103
- # List all types
96
+ # * --list:
97
+ # List all types
104
98
 
105
- # * --meta:
106
- # List all metaparameters
107
-
108
- # * --short:
109
- # List only parameters without detail
99
+ # * --meta:
100
+ # List all metaparameters
110
101
 
102
+ # * --short:
103
+ # List only parameters without detail
111
104
 
112
105
  when_invoked do |*args|
113
106
  check_required_features
@@ -117,27 +110,24 @@ Puppet::Face.define(:strings, '0.0.1') do
117
110
  options[:describe] = true
118
111
  options[:stdout] = true
119
112
  options[:format] = 'json'
120
-
113
+
121
114
  if args.length > 1
122
115
  if options[:list]
123
- warn "WARNING: ignoring types when listing all types."
116
+ warn 'WARNING: ignoring types when listing all types.'
124
117
  else
125
118
  options[:describe_types] = args[0..-2]
126
119
  end
127
120
  end
128
121
 
129
- #TODO: Set up search_patterns and whatever else needed to collect data for describe - currently missing some
122
+ # TODO: Set up search_patterns and whatever else needed to collect data for describe - currently missing some
130
123
  # manifests/**/*.pp
131
124
  # functions/**/*.pp
132
125
  # tasks/*.json
133
126
  # plans/*.pp
134
- search_patterns = %w(
135
- types/**/*.pp
136
- lib/**/*.rb
137
- )
138
- PuppetStrings::generate(
127
+ search_patterns = ['types/**/*.pp', 'lib/**/*.rb']
128
+ PuppetStrings.generate(
139
129
  search_patterns,
140
- build_generate_options(options)
130
+ build_generate_options(options),
141
131
  )
142
132
  nil
143
133
  end
@@ -146,9 +136,9 @@ Puppet::Face.define(:strings, '0.0.1') do
146
136
  # Checks that the required features are installed.
147
137
  # @return [void]
148
138
  def check_required_features
149
- raise RuntimeError, "The 'yard' gem must be installed in order to use this face." unless Puppet.features.yard?
150
- raise RuntimeError, "The 'rgen' gem must be installed in order to use this face." unless Puppet.features.rgen?
151
- raise RuntimeError, 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION.match?(/^1\.8/)
139
+ raise "The 'yard' gem must be installed in order to use this face." unless Puppet.features.yard?
140
+ raise "The 'rgen' gem must be installed in order to use this face." unless Puppet.features.rgen?
141
+ raise 'This face requires Ruby 1.9 or greater.' if RUBY_VERSION.match?(%r{^1\.8})
152
142
  end
153
143
 
154
144
  # Builds the options to PuppetStrings.generate.
@@ -161,12 +151,6 @@ Puppet::Face.define(:strings, '0.0.1') do
161
151
  generate_options[:backtrace] = Puppet[:trace]
162
152
  generate_options[:yard_args] = yard_args unless yard_args.empty?
163
153
  if options
164
- if options[:emit_json]
165
- warn "WARNING: '--emit-json PATH' is deprecated. Use '--format json --out PATH' instead."
166
- end
167
- if options[:emit_json_stdout]
168
- warn "WARNING: '--emit-json-stdout' is deprecated. Use '--format json' instead."
169
- end
170
154
  markup = options[:markup]
171
155
  generate_options[:markup] = markup if markup
172
156
  generate_options[:path] = options[:out] if options[:out]
@@ -182,15 +166,11 @@ Puppet::Face.define(:strings, '0.0.1') do
182
166
  if format
183
167
  if format.casecmp('markdown').zero?
184
168
  generate_options[:markdown] = true
185
- elsif format.casecmp('json').zero? || options[:emit_json] || options[:emit_json_stdout]
169
+ elsif format.casecmp('json').zero?
186
170
  generate_options[:json] = true
187
- generate_options[:path] ||= options[:emit_json] if options[:emit_json]
188
171
  else
189
- raise RuntimeError, "Invalid format #{options[:format]}. Please select 'json' or 'markdown'."
172
+ raise "Invalid format #{options[:format]}. Please select 'json' or 'markdown'."
190
173
  end
191
- elsif options[:emit_json] || options[:emit_json_stdout]
192
- generate_options[:json] = true
193
- generate_options[:path] ||= options[:emit_json] if options[:emit_json]
194
174
  end
195
175
  end
196
176
  generate_options
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'puppet/util/feature'
4
4
 
5
- Puppet.features.add(:rgen, :libs => ['rgen/metamodel_builder', 'rgen/ecore/ecore'])
5
+ Puppet.features.add(:rgen, libs: ['rgen/metamodel_builder', 'rgen/ecore/ecore'])
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'puppet/util/feature'
4
4
 
5
- Puppet.features.add(:yard, :libs => ['yard'])
5
+ Puppet.features.add(:yard, libs: ['yard'])
@@ -8,16 +8,16 @@ module PuppetStrings::Describe
8
8
  # Renders requested types or a summarized list in the current YARD registry to STDOUT.
9
9
  # @param [Array] describe_types The list of names of the types to be displayed.
10
10
  # @param [bool] list Create the summarized list instead of describing each type.
11
- # @param [bool] providers Show details of the providers.
11
+ # @param [bool] _providers Show details of the providers.
12
12
  # @return [void]
13
- def self.render(describe_types = [], list = false, providers = false)
13
+ def self.render(describe_types = [], list = false, _providers = false)
14
14
  document = {
15
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),
16
+ resource_types: YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash),
17
17
  }
18
18
 
19
19
  if list
20
- puts "These are the types known to puppet:"
20
+ puts 'These are the types known to puppet:'
21
21
  document[:resource_types].each { |t| list_one_type(t) }
22
22
  else
23
23
  document[:providers] = YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash)
@@ -26,31 +26,31 @@ module PuppetStrings::Describe
26
26
  describe_types.each { |name| type_names[name] = true }
27
27
 
28
28
  document[:resource_types].each do |t|
29
- show_one_type(t, providers) if type_names[t[:name].to_s]
29
+ show_one_type(t) if type_names[t[:name].to_s]
30
30
  end
31
31
  end
32
32
  end
33
33
 
34
- def self.show_one_type(resource_type, providers = false)
35
- puts "\n%{name}\n%{underscore}" % { name: resource_type[:name], underscore: "=" * resource_type[:name].length }
34
+ def self.show_one_type(resource_type)
35
+ puts "\n%{name}\n%{underscore}" % { name: resource_type[:name], underscore: '=' * resource_type[:name].length }
36
36
  puts resource_type[:docstring][:text]
37
37
 
38
38
  combined_list = (resource_type[:parameters].nil? ? [] : resource_type[:parameters]) +
39
39
  (resource_type[:properties].nil? ? [] : resource_type[:properties])
40
40
 
41
- if combined_list.any?
42
- puts "\nParameters\n----------"
43
- combined_list.sort_by { |p| p[:name] }.each { |p| show_one_parameter(p) }
44
- puts "\nProviders\n---------"
45
- end
46
- #Show providers here - list or provide details
41
+ return unless combined_list.any?
42
+
43
+ puts "\nParameters\n----------"
44
+ combined_list.sort_by { |p| p[:name] }.each { |p| show_one_parameter(p) }
45
+ puts "\nProviders\n---------"
46
+ # Show providers here - list or provide details
47
47
  end
48
48
 
49
49
  def self.show_one_parameter(parameter)
50
50
  puts "\n- **%{name}**\n" % { name: parameter[:name] }
51
51
  puts parameter[:description]
52
- puts "Valid values are `%{values}`." % { values: parameter[:values].join("`, `") } unless parameter[:values].nil?
53
- puts "Requires features %{required_features}." % { required_features: parameter[:required_features] } unless parameter[:required_features].nil?
52
+ puts 'Valid values are `%{values}`.' % { values: parameter[:values].join('`, `') } unless parameter[:values].nil?
53
+ puts 'Requires features %{required_features}.' % { required_features: parameter[:required_features] } unless parameter[:required_features].nil?
54
54
  end
55
55
 
56
56
  def self.list_one_type(type)
@@ -58,13 +58,13 @@ module PuppetStrings::Describe
58
58
  shortento = targetlength - 4
59
59
  contentstring = type[:docstring][:text]
60
60
  end_of_line = contentstring.index("\n") # "." gives closer results to old describeb, but breaks for '.k5login'
61
- if !end_of_line.nil?
61
+ unless end_of_line.nil?
62
62
  contentstring = contentstring[0..end_of_line]
63
63
  end
64
64
  if contentstring.length > targetlength
65
65
  contentstring = contentstring[0..shortento] + ' ...'
66
66
  end
67
-
68
- puts "%-15s - %-s" % [type[:name], contentstring]
67
+
68
+ puts "#{type[:name].to_s.ljust(15)} - #{contentstring}"
69
69
  end
70
70
  end
@@ -3,12 +3,14 @@
3
3
  require 'puppet-strings'
4
4
  require 'puppet-strings/json'
5
5
  require 'puppet-strings/yard'
6
+ require 'puppet-strings/markdown/helpers'
6
7
 
8
+ # Implements classes that make elements in a YARD::Registry hash easily accessible for template.
7
9
  module PuppetStrings::Markdown
8
10
  # This class makes elements in a YARD::Registry hash easily accessible for templates.
9
11
  #
10
12
  # Here's an example hash:
11
- #{:name=>:klass,
13
+ # {:name=>:klass,
12
14
  # :file=>"(stdin)",
13
15
  # :line=>16,
14
16
  # :inherits=>"foo::bar",
@@ -49,6 +51,36 @@ module PuppetStrings::Markdown
49
51
  # ") inherits foo::bar {\n" +
50
52
  # "}"}
51
53
  class Base
54
+ # Helpers for ERB templates
55
+ include PuppetStrings::Markdown::Helpers
56
+
57
+ # Set or return the name of the group
58
+ #
59
+ # @param [Optional[String]] Name of the group to set
60
+ # @return [String] Name of the group
61
+ def self.group_name(name = nil)
62
+ @group_name = name if name
63
+ @group_name
64
+ end
65
+
66
+ # Set or return the types registered with YARD
67
+ #
68
+ # @param [Optional[Array[Symbol]]] Array of symbols registered with YARD to set
69
+ # @return [Array[Symbol]] Array of symbols registered with YARD
70
+ def self.yard_types(types = nil)
71
+ @yard_types = types if types
72
+ @yard_types
73
+ end
74
+
75
+ # @return [Array] list of items
76
+ def self.items
77
+ yard_types
78
+ .flat_map { |type| YARD::Registry.all(type) }
79
+ .sort_by(&:name)
80
+ .map(&:to_hash)
81
+ .map { |i| new(i) }
82
+ end
83
+
52
84
  def initialize(registry, component_type)
53
85
  @type = component_type
54
86
  @registry = registry
@@ -57,11 +89,11 @@ module PuppetStrings::Markdown
57
89
 
58
90
  # generate 1:1 tag methods
59
91
  # e.g. {:tag_name=>"author", :text=>"eputnam"}
60
- { :return_val => 'return',
61
- :since => 'since',
62
- :summary => 'summary',
63
- :note => 'note',
64
- :todo => 'todo' }.each do |method_name, tag_name|
92
+ { return_val: 'return',
93
+ since: 'since',
94
+ summary: 'summary',
95
+ note: 'note',
96
+ todo: 'todo' }.each do |method_name, tag_name|
65
97
  # @return [String] unless the tag is nil or the string.empty?
66
98
  define_method method_name do
67
99
  @tags.find { |tag| tag[:tag_name] == tag_name && !tag[:text].empty? }[:text] if @tags.any? { |tag| tag[:tag_name] == tag_name && !tag[:text].empty? }
@@ -95,7 +127,11 @@ module PuppetStrings::Markdown
95
127
 
96
128
  # @return [Array] parameter tag hashes
97
129
  def params
98
- select_tags('param')
130
+ tags = @tags.select { |tag| tag[:tag_name] == 'param' }.map do |param|
131
+ param[:link] = clean_link("$#{name}::#{param[:name]}")
132
+ param
133
+ end
134
+ tags.empty? ? nil : tags
99
135
  end
100
136
 
101
137
  # @return [Array] example tag hashes
@@ -144,27 +180,14 @@ module PuppetStrings::Markdown
144
180
  {
145
181
  name: name.to_s,
146
182
  link: link,
147
- desc: summary || @registry[:docstring][:text][0..140].gsub("\n",' '),
183
+ desc: summary || @registry[:docstring][:text][0..140].tr("\n", ' '),
148
184
  private: private?
149
185
  }
150
186
  end
151
187
 
152
188
  # @return [String] makes the component name suitable for a GitHub markdown link
153
189
  def link
154
- name.delete('::').strip.gsub(' ','-').downcase
155
- end
156
-
157
- # Some return, default, or valid values need to be in backticks. Instead of fu in the handler or code_object, this just does the change on the front.
158
- # @param value
159
- # any string
160
- # @return [String] value or value in backticks if it is in a list
161
- def value_string(value)
162
- to_symbol = %w[undef true false]
163
- if to_symbol.include? value
164
- return "`#{value}`"
165
- else
166
- return value
167
- end
190
+ clean_link(name)
168
191
  end
169
192
 
170
193
  def private?
@@ -174,18 +197,18 @@ module PuppetStrings::Markdown
174
197
  def word_wrap(text, line_width: 120, break_sequence: "\n")
175
198
  return unless text
176
199
 
177
- text.split("\n").collect! do |line|
178
- line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1#{break_sequence}").strip : line
179
- end * break_sequence
200
+ text.split("\n").map! { |line|
201
+ line.length > line_width ? line.gsub(%r{(.{1,#{line_width}})(\s+|$)}, "\\1#{break_sequence}").strip : line
202
+ } * break_sequence
180
203
  end
181
204
 
182
205
  # @return [String] full markdown rendering of a component
183
206
  def render(template)
207
+ file = File.join(File.dirname(__FILE__), 'templates', template)
184
208
  begin
185
- file = File.join(File.dirname(__FILE__),"templates/#{template}")
186
- ERB.new(File.read(file), nil, '-').result(binding)
209
+ PuppetStrings::Markdown.erb(file).result(binding)
187
210
  rescue StandardError => e
188
- fail "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}"
211
+ raise "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}"
189
212
  end
190
213
  end
191
214
 
@@ -195,5 +218,17 @@ module PuppetStrings::Markdown
195
218
  tags = @tags.select { |tag| tag[:tag_name] == name }
196
219
  tags.empty? ? nil : tags
197
220
  end
221
+
222
+ # Convert an input into a string appropriate for an anchor name.
223
+ #
224
+ # This converts any character not suitable for an id attribute into a '-'. Generally we're running this on Puppet identifiers for types and
225
+ # variables, so we only need to worry about the special characters ':' and '$'. With namespaces Puppet variables this should always be produce a
226
+ # unique result from a unique input, since ':' only appears in pairs, '$' only appears at the beginning, and '-' never appears.
227
+ #
228
+ # @param [String] the input to convert
229
+ # @return [String] the anchor-safe string
230
+ def clean_link(input)
231
+ input.tr('^a-zA-Z0-9_-', '-')
232
+ end
198
233
  end
199
234
  end
@@ -8,6 +8,9 @@ module PuppetStrings::Markdown
8
8
  attr_reader :alias_of
9
9
  attr_reader :functions
10
10
 
11
+ group_name 'Data types'
12
+ yard_types [:puppet_data_type, :puppet_data_type_alias]
13
+
11
14
  def initialize(registry)
12
15
  @template = 'data_type.erb'
13
16
  super(registry, 'data type')
@@ -20,6 +23,7 @@ module PuppetStrings::Markdown
20
23
  end
21
24
  end
22
25
 
26
+ # Generates Markdown for a Puppet Function.
23
27
  class DataType::Function < Base
24
28
  def initialize(registry)
25
29
  super(registry, 'data_type_function')
@@ -3,7 +3,11 @@
3
3
  require 'puppet-strings/markdown/base'
4
4
 
5
5
  module PuppetStrings::Markdown
6
+ # Generates Markdown for a Puppet Defined Type.
6
7
  class DefinedType < Base
8
+ group_name 'Defined types'
9
+ yard_types [:puppet_defined_type]
10
+
7
11
  def initialize(registry)
8
12
  @template = 'classes_and_defines.erb'
9
13
  super(registry, 'defined type')