puppet-strings 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/Gemfile +4 -2
  4. data/README.md +53 -10
  5. data/codecov.yml +3 -0
  6. data/lib/puppet-strings.rb +30 -11
  7. data/lib/puppet-strings/json.rb +7 -0
  8. data/lib/puppet-strings/markdown.rb +35 -0
  9. data/lib/puppet-strings/markdown/base.rb +168 -0
  10. data/lib/puppet-strings/markdown/defined_type.rb +14 -0
  11. data/lib/puppet-strings/markdown/defined_types.rb +37 -0
  12. data/lib/puppet-strings/markdown/function.rb +52 -0
  13. data/lib/puppet-strings/markdown/functions.rb +38 -0
  14. data/lib/puppet-strings/markdown/puppet_class.rb +14 -0
  15. data/lib/puppet-strings/markdown/puppet_classes.rb +37 -0
  16. data/lib/puppet-strings/markdown/resource_type.rb +27 -0
  17. data/lib/puppet-strings/markdown/resource_types.rb +37 -0
  18. data/lib/puppet-strings/markdown/table_of_contents.rb +21 -0
  19. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +63 -0
  20. data/lib/puppet-strings/markdown/templates/function.erb +50 -0
  21. data/lib/puppet-strings/markdown/templates/resource_type.erb +114 -0
  22. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +21 -0
  23. data/lib/puppet-strings/tasks/generate.rb +24 -5
  24. data/lib/puppet-strings/yard/code_objects/function.rb +3 -3
  25. data/lib/puppet-strings/yard/code_objects/type.rb +3 -1
  26. data/lib/puppet-strings/yard/handlers.rb +1 -0
  27. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +1 -1
  28. data/lib/puppet-strings/yard/handlers/ruby/base.rb +1 -1
  29. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +141 -0
  30. data/lib/puppet/face/strings.rb +28 -7
  31. data/spec/acceptance/emit_json_options.rb +4 -4
  32. data/spec/acceptance/generate_markdown_spec.rb +49 -0
  33. data/spec/fixtures/unit/json/output.json +43 -0
  34. data/spec/fixtures/unit/markdown/output.md +383 -0
  35. data/spec/spec_helper.rb +19 -1
  36. data/spec/unit/puppet-strings/json_spec.rb +40 -0
  37. data/spec/unit/puppet-strings/markdown/base_spec.rb +146 -0
  38. data/spec/unit/puppet-strings/markdown_spec.rb +248 -0
  39. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +16 -1
  40. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +1 -1
  41. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +213 -0
  42. metadata +38 -2
@@ -0,0 +1,14 @@
1
+ require 'puppet-strings/markdown/base'
2
+
3
+ module PuppetStrings::Markdown
4
+ class DefinedType < Base
5
+ def initialize(registry)
6
+ @template = 'classes_and_defines.erb'
7
+ super(registry, 'defined type')
8
+ end
9
+
10
+ def render
11
+ super(@template)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'defined_type'
2
+
3
+ module PuppetStrings::Markdown
4
+ module DefinedTypes
5
+
6
+ # @return [Array] list of defined types
7
+ def self.in_dtypes
8
+ arr = YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash)
9
+ arr.map! { |a| PuppetStrings::Markdown::DefinedType.new(a) }
10
+ end
11
+
12
+ def self.contains_private?
13
+ result = false
14
+ unless in_dtypes.nil?
15
+ in_dtypes.find { |type| type.private? }.nil? ? false : true
16
+ end
17
+ end
18
+
19
+ def self.render
20
+ final = in_dtypes.length > 0 ? "## Defined types\n\n" : ""
21
+ in_dtypes.each do |type|
22
+ final << type.render unless type.private?
23
+ end
24
+ final
25
+ end
26
+
27
+ def self.toc_info
28
+ final = ["Defined types"]
29
+
30
+ in_dtypes.each do |type|
31
+ final.push(type.toc_info)
32
+ end
33
+
34
+ final
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ require 'puppet-strings/markdown/base'
2
+
3
+ module PuppetStrings::Markdown
4
+ class Function < Base
5
+ attr_reader :signatures
6
+
7
+ def initialize(registry)
8
+ @template = 'function.erb'
9
+ super(registry, 'function')
10
+ @signatures = []
11
+ registry[:signatures].each do |sig|
12
+ @signatures.push(Signature.new(sig))
13
+ end
14
+ end
15
+
16
+ def render
17
+ super(@template)
18
+ end
19
+
20
+ def type
21
+ t = @registry[:type]
22
+ if t =~ /ruby4x/
23
+ "Ruby 4.x API"
24
+ elsif t =~ /ruby3/
25
+ "Ruby 3.x API"
26
+ elsif t =~ /ruby/
27
+ "Ruby"
28
+ else
29
+ "Puppet Language"
30
+ end
31
+ end
32
+
33
+ def error_type(r)
34
+ "`#{r.split(' ')[0]}`"
35
+ end
36
+
37
+ def error_text(r)
38
+ "#{r.split(' ').drop(1).join(' ')}"
39
+ end
40
+ end
41
+
42
+ class Function::Signature < Base
43
+ def initialize(registry)
44
+ @registry = registry
45
+ super(@registry, 'function signature')
46
+ end
47
+
48
+ def signature
49
+ @registry[:signature]
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'function'
2
+
3
+ module PuppetStrings::Markdown
4
+ module Functions
5
+
6
+ # @return [Array] list of functions
7
+ def self.in_functions
8
+ arr = YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash)
9
+ arr.map! { |a| PuppetStrings::Markdown::Function.new(a) }
10
+ end
11
+
12
+ def self.contains_private?
13
+ result = false
14
+ unless in_functions.nil?
15
+ in_functions.find { |func| func.private? }.nil? ? false : true
16
+ end
17
+ end
18
+
19
+ def self.render
20
+ final = in_functions.length > 0 ? "## Functions\n\n" : ""
21
+ in_functions.each do |func|
22
+ final << func.render unless func.private?
23
+ end
24
+ final
25
+ end
26
+
27
+ def self.toc_info
28
+ final = ["Functions"]
29
+
30
+ in_functions.each do |func|
31
+ final.push(func.toc_info)
32
+ end
33
+
34
+ final
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,14 @@
1
+ require 'puppet-strings/markdown/base'
2
+
3
+ module PuppetStrings::Markdown
4
+ class PuppetClass < Base
5
+ def initialize(registry)
6
+ @template = 'classes_and_defines.erb'
7
+ super(registry, 'class')
8
+ end
9
+
10
+ def render
11
+ super(@template)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'puppet_class'
2
+
3
+ module PuppetStrings::Markdown
4
+ module PuppetClasses
5
+
6
+ # @return [Array] list of classes
7
+ def self.in_classes
8
+ arr = YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)
9
+ arr.map! { |a| PuppetStrings::Markdown::PuppetClass.new(a) }
10
+ end
11
+
12
+ def self.contains_private?
13
+ result = false
14
+ unless in_classes.nil?
15
+ in_classes.find { |klass| klass.private? }.nil? ? false : true
16
+ end
17
+ end
18
+
19
+ def self.render
20
+ final = in_classes.length > 0 ? "## Classes\n\n" : ""
21
+ in_classes.each do |klass|
22
+ final << klass.render unless klass.private?
23
+ end
24
+ final
25
+ end
26
+
27
+ def self.toc_info
28
+ final = ["Classes"]
29
+
30
+ in_classes.each do |klass|
31
+ final.push(klass.toc_info)
32
+ end
33
+
34
+ final
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ require 'puppet-strings/markdown/base'
2
+
3
+ module PuppetStrings::Markdown
4
+ class ResourceType < Base
5
+ def initialize(registry)
6
+ @template = 'resource_type.erb'
7
+ super(registry, 'type')
8
+ end
9
+
10
+ def render
11
+ super(@template)
12
+ end
13
+
14
+ def properties
15
+ @registry[:properties]
16
+ end
17
+
18
+ def parameters
19
+ @registry[:parameters]
20
+ end
21
+
22
+ def regex_in_data_type?(data_type)
23
+ m = data_type.match(/\w+\[\/.*\/\]/)
24
+ m unless m.nil? || m.length.zero?
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'resource_type'
2
+
3
+ module PuppetStrings::Markdown
4
+ module ResourceTypes
5
+
6
+ # @return [Array] list of resource types
7
+ def self.in_rtypes
8
+ arr = YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash)
9
+ arr.map! { |a| PuppetStrings::Markdown::ResourceType.new(a) }
10
+ end
11
+
12
+ def self.contains_private?
13
+ result = false
14
+ unless in_rtypes.nil?
15
+ in_rtypes.find { |type| type.private? }.nil? ? false : true
16
+ end
17
+ end
18
+
19
+ def self.render
20
+ final = in_rtypes.length > 0 ? "## Resource types\n\n" : ""
21
+ in_rtypes.each do |type|
22
+ final << type.render unless type.private?
23
+ end
24
+ final
25
+ end
26
+
27
+ def self.toc_info
28
+ final = ["Resource types"]
29
+
30
+ in_rtypes.each do |type|
31
+ final.push(type.toc_info)
32
+ end
33
+
34
+ final
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ module PuppetStrings::Markdown
2
+ module TableOfContents
3
+ def self.render
4
+ final = ""
5
+
6
+ [PuppetStrings::Markdown::PuppetClasses,
7
+ PuppetStrings::Markdown::DefinedTypes,
8
+ PuppetStrings::Markdown::ResourceTypes,
9
+ PuppetStrings::Markdown::Functions].each do |r|
10
+ toc = r.toc_info
11
+ group_name = toc.shift
12
+ group = toc
13
+ priv = r.contains_private?
14
+
15
+ template = File.join(File.dirname(__FILE__),"templates/table_of_contents.erb")
16
+ final << ERB.new(File.read(template), nil, '-').result(binding)
17
+ end
18
+ final
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,63 @@
1
+ ### <%= name %>
2
+
3
+ <% if text -%>
4
+ <%= text %>
5
+
6
+ <% elsif summary -%>
7
+ <%= summary %>
8
+
9
+ <% else -%>
10
+ <%= "The #{name} class." %>
11
+
12
+ <% end -%>
13
+ <% if since -%>
14
+ * **Since** <%= since %>
15
+
16
+ <% end -%>
17
+ <% if see -%>
18
+ * **See also**
19
+ <% see.each do |sa| -%>
20
+ <%= sa[:name] %>
21
+ <%= sa[:text] %>
22
+ <% end -%>
23
+
24
+ <% end -%>
25
+ <% if examples -%>
26
+ #### Examples
27
+ <% examples.each do |eg| -%>
28
+ ##### <%= eg[:name] %>
29
+ ```puppet
30
+ <%= eg[:text] %>
31
+ ```
32
+
33
+ <% end -%>
34
+ <% end -%>
35
+ <% if params %>
36
+ #### Parameters
37
+
38
+ The following parameters are available in the `<%= name %>` <%= @type %>.
39
+
40
+ <% params.each do |param| -%>
41
+ ##### `<%= param[:name] %>`
42
+
43
+ <% if param[:types] -%>
44
+ Data type: `<%= param[:types].join(', ') -%>`
45
+
46
+ <% end -%>
47
+ <%= param[:text] %>
48
+
49
+ <% if options_for_param(param[:name]) -%>
50
+ Options:
51
+
52
+ <% options_for_param(param[:name]).each do |o| -%>
53
+ * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
54
+ <% end -%>
55
+
56
+ <% end -%>
57
+ <% if defaults && defaults[param[:name]] -%>
58
+ Default value: <%= value_string(defaults[param[:name]]) %>
59
+
60
+ <% end -%>
61
+ <% end -%>
62
+ <% end -%>
63
+
@@ -0,0 +1,50 @@
1
+ ### <%= name %>
2
+ Type: <%= type %>
3
+
4
+ <% if text -%>
5
+ <%= text %>
6
+
7
+ <% elsif summary -%>
8
+ <%= summary %>
9
+
10
+ <% else -%>
11
+ <%= "The #{name} class." %>
12
+
13
+ <% end -%>
14
+ <% signatures.each do |sig| -%>
15
+ #### `<%= sig.signature %>`
16
+
17
+ <% if sig.text -%>
18
+ <%= sig.text %>
19
+
20
+ <% end -%>
21
+ <% if sig.return_type -%>
22
+ Returns: `<%= sig.return_type %>`<% if sig.return_val %> <%= sig.return_val %><% end %>
23
+
24
+ <% end -%>
25
+ <% if raises -%>
26
+ Raises:
27
+ <% raises.each do |r| -%>
28
+ * <%= error_type(r[:text]) %> <%= error_text(r[:text]) %>
29
+ <% end -%>
30
+
31
+ <% end -%>
32
+ <% if sig.params -%>
33
+ <% sig.params.each do |param| -%>
34
+ ##### `<%= param[:name] %>`
35
+
36
+ Data type: `<%= param[:types][0] %>`
37
+
38
+ <%= param[:text] %>
39
+
40
+ <% if sig.options_for_param(param[:name]) -%>
41
+ Options:
42
+
43
+ <% sig.options_for_param(param[:name]).each do |o| -%>
44
+ * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
45
+ <% end -%>
46
+
47
+ <% end -%>
48
+ <% end -%>
49
+ <% end -%>
50
+ <% end -%>
@@ -0,0 +1,114 @@
1
+ ### <%= name %>
2
+
3
+ <% if text -%>
4
+ <%= text %>
5
+
6
+ <% elsif summary -%>
7
+ <%= summary %>
8
+
9
+ <% else -%>
10
+ <%= "The #{name} type." %>
11
+
12
+ <% end -%>
13
+ <% if since -%>
14
+ * **Since** <%= since %>
15
+
16
+ <% end -%>
17
+ <% if see -%>
18
+ * **See also**
19
+ <% see.each do |sa| -%>
20
+ <%= sa[:name] %>
21
+ <%= sa[:text] %>
22
+ <% end -%>
23
+
24
+ <% end -%>
25
+ <% if examples -%>
26
+ #### Examples
27
+ <% examples.each do |eg| -%>
28
+ ##### <%= eg[:name] %>
29
+ ```puppet
30
+ <%= eg[:text] %>
31
+ ```
32
+ <% end -%>
33
+ <% end -%>
34
+ <% if properties %>
35
+ #### Properties
36
+
37
+ The following properties are available in the `<%= name %>` <%= @type %>.
38
+
39
+ <% properties.each do |prop| -%>
40
+ ##### `<%= prop[:name] %>`
41
+
42
+ <% if prop[:values] -%>
43
+ Valid values: <%= prop[:values].map { |value| value_string(value) }.join(', ') %>
44
+
45
+ <% end -%>
46
+ <% if prop[:isnamevar] -%>
47
+ namevar
48
+
49
+ <% end -%>
50
+ <% if prop[:aliases] -%>
51
+ Aliases: <%= prop[:aliases].to_s.delete('{').delete('}') %>
52
+
53
+ <% end -%>
54
+ <% if prop[:data_type] -%>
55
+ Data type: `<%= prop[:data_type] %>`<%= "\n_\*this data type contains a regex that may not be accurately reflected in generated documentation_" if regex_in_data_type?(prop[:data_type]) %>
56
+
57
+ <% end -%>
58
+ <%= prop[:description] %>
59
+
60
+ <% if options_for_param(prop[:name]) -%>
61
+ Options:
62
+
63
+ <% options_for_param(prop[:name]).each do |o| -%>
64
+ * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
65
+ <% end -%>
66
+
67
+ <% end -%>
68
+ <% if prop[:default] -%>
69
+ Default value: <%= prop[:default] %>
70
+
71
+ <% end -%>
72
+ <% end -%>
73
+ <% end -%>
74
+ <% if parameters -%>
75
+ #### Parameters
76
+
77
+ The following parameters are available in the `<%= name %>` <%= @type %>.
78
+
79
+ <% parameters.each do |param| -%>
80
+ ##### `<%= param[:name] %>`
81
+
82
+ <% if param[:values] -%>
83
+ Valid values: <%= param[:values].map { |value| value_string(value) }.join(', ') %>
84
+
85
+ <% end -%>
86
+ <% if param[:isnamevar] -%>
87
+ namevar
88
+
89
+ <% end -%>
90
+ <% if param[:aliases] -%>
91
+ Aliases: <%= param[:aliases].to_s.delete('{').delete('}') %>
92
+
93
+ <% end -%>
94
+ <% if param[:data_type] -%>
95
+ Data type: `<%= param[:data_type] %>`<%= "\n_\*this data type contains a regex that may not be accurately reflected in generated documentation_" if regex_in_data_type?(param[:data_type]) %>
96
+
97
+ <% end -%>
98
+ <%= param[:description] %>
99
+
100
+ <% if options_for_param(param[:name]) -%>
101
+ Options:
102
+
103
+ <% options_for_param(param[:name]).each do |o| -%>
104
+ * **<%= o[:opt_name] %>** `<%= o[:opt_types][0] %>`: <%= o[:opt_text] %>
105
+ <% end -%>
106
+
107
+ <% end -%>
108
+ <% if param[:default] -%>
109
+ Default value: <%= value_string(param[:default]) %>
110
+
111
+ <% end -%>
112
+ <% end -%>
113
+ <% end -%>
114
+