puppet-strings 1.2.1 → 2.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 +26 -0
  3. data/CONTRIBUTING.md +3 -7
  4. data/JSON.md +126 -8
  5. data/README.md +16 -498
  6. data/lib/puppet-strings.rb +6 -0
  7. data/lib/puppet-strings/json.rb +2 -0
  8. data/lib/puppet-strings/markdown.rb +6 -1
  9. data/lib/puppet-strings/markdown/puppet_plan.rb +14 -0
  10. data/lib/puppet-strings/markdown/puppet_plans.rb +37 -0
  11. data/lib/puppet-strings/markdown/puppet_task.rb +24 -0
  12. data/lib/puppet-strings/markdown/puppet_tasks.rb +34 -0
  13. data/lib/puppet-strings/markdown/table_of_contents.rb +3 -1
  14. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +8 -5
  15. data/lib/puppet-strings/markdown/templates/function.erb +2 -3
  16. data/lib/puppet-strings/markdown/templates/puppet_task.erb +28 -0
  17. data/lib/puppet-strings/markdown/templates/resource_type.erb +9 -5
  18. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +5 -0
  19. data/lib/puppet-strings/monkey_patches/display_object_command.rb +11 -0
  20. data/lib/puppet-strings/yard.rb +15 -1
  21. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  22. data/lib/puppet-strings/yard/code_objects/plan.rb +56 -0
  23. data/lib/puppet-strings/yard/code_objects/task.rb +70 -0
  24. data/lib/puppet-strings/yard/handlers.rb +6 -0
  25. data/lib/puppet-strings/yard/handlers/json/base.rb +5 -0
  26. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +31 -0
  27. data/lib/puppet-strings/yard/handlers/puppet/base.rb +1 -1
  28. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +1 -1
  29. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +1 -1
  30. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +1 -1
  31. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +27 -0
  32. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +4 -1
  33. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +12 -2
  34. data/lib/puppet-strings/yard/parsers.rb +4 -0
  35. data/lib/puppet-strings/yard/parsers/json/parser.rb +33 -0
  36. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +35 -0
  37. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +11 -0
  38. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +14 -0
  39. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_plan.erb +9 -0
  40. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_task.erb +9 -0
  41. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +18 -0
  42. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +42 -2
  43. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/box_info.erb +10 -0
  44. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/header.erb +1 -0
  45. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/overview.erb +6 -0
  46. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/setup.rb +11 -0
  47. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/source.erb +12 -0
  48. data/lib/puppet-strings/yard/templates/default/puppet_plan/html/summary.erb +4 -0
  49. data/lib/puppet-strings/yard/templates/default/puppet_task/html/box_info.erb +9 -0
  50. data/lib/puppet-strings/yard/templates/default/puppet_task/html/header.erb +1 -0
  51. data/lib/puppet-strings/yard/templates/default/puppet_task/html/input.erb +5 -0
  52. data/lib/puppet-strings/yard/templates/default/puppet_task/html/overview.erb +6 -0
  53. data/lib/puppet-strings/yard/templates/default/puppet_task/html/parameters.erb +16 -0
  54. data/lib/puppet-strings/yard/templates/default/puppet_task/html/setup.rb +22 -0
  55. data/lib/puppet-strings/yard/templates/default/puppet_task/html/supports_noop.erb +3 -0
  56. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +3 -1
  57. data/lib/puppet-strings/yard/util.rb +14 -0
  58. data/spec/fixtures/unit/json/output.json +50 -0
  59. data/spec/fixtures/unit/json/output_with_plan.json +689 -0
  60. data/spec/fixtures/unit/markdown/output.md +63 -8
  61. data/spec/fixtures/unit/markdown/output_with_plan.md +472 -0
  62. data/spec/spec_helper.rb +5 -2
  63. data/spec/unit/puppet-strings/json_spec.rb +42 -2
  64. data/spec/unit/puppet-strings/markdown_spec.rb +41 -8
  65. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +92 -0
  66. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +124 -0
  67. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +1 -1
  68. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +19 -12
  69. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +33 -0
  70. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +8 -7
  71. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +70 -0
  72. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +56 -0
  73. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +1 -1
  74. data/spec/unit/puppet-strings/yard/util_spec.rb +17 -0
  75. metadata +38 -5
  76. data/MAINTAINERS +0 -17
@@ -6,6 +6,8 @@ module PuppetStrings
6
6
  functions/**/*.pp
7
7
  types/**/*.pp
8
8
  lib/**/*.rb
9
+ tasks/*.json
10
+ plans/*.pp
9
11
  ).freeze
10
12
 
11
13
  # Generates documentation.
@@ -61,6 +63,10 @@ module PuppetStrings
61
63
  end
62
64
  end
63
65
 
66
+ def self.puppet_5?
67
+ Puppet::Util::Package.versioncmp(Puppet.version, "5.0.0") >= 0
68
+ end
69
+
64
70
  def self.render_json(path)
65
71
  require 'puppet-strings/json'
66
72
  PuppetStrings::Json.render(path)
@@ -12,6 +12,8 @@ module PuppetStrings::Json
12
12
  resource_types: YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash),
13
13
  providers: YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash),
14
14
  puppet_functions: YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash),
15
+ puppet_tasks: YARD::Registry.all(:puppet_task).sort_by!(&:name).map!(&:to_hash),
16
+ puppet_plans: YARD::Registry.all(:puppet_plan).sort_by!(&:name).map!(&:to_hash)
15
17
  # TODO: Need Ruby documentation?
16
18
  }
17
19
 
@@ -6,17 +6,22 @@ module PuppetStrings::Markdown
6
6
  require_relative 'markdown/functions'
7
7
  require_relative 'markdown/defined_types'
8
8
  require_relative 'markdown/resource_types'
9
+ require_relative 'markdown/puppet_tasks'
10
+ require_relative 'markdown/puppet_plans'
9
11
  require_relative 'markdown/table_of_contents'
10
12
 
11
13
  # generates markdown documentation
12
14
  # @return [String] markdown doc
13
15
  def self.generate
14
- final = "# Reference\n\n"
16
+ final = "# Reference\n"
17
+ final << "<!-- DO NOT EDIT: This document was generated by Puppet Strings -->\n\n"
15
18
  final << PuppetStrings::Markdown::TableOfContents.render
16
19
  final << PuppetStrings::Markdown::PuppetClasses.render
17
20
  final << PuppetStrings::Markdown::DefinedTypes.render
18
21
  final << PuppetStrings::Markdown::ResourceTypes.render
19
22
  final << PuppetStrings::Markdown::Functions.render
23
+ final << PuppetStrings::Markdown::PuppetTasks.render
24
+ final << PuppetStrings::Markdown::PuppetPlans.render
20
25
 
21
26
  final
22
27
  end
@@ -0,0 +1,14 @@
1
+ require 'puppet-strings/markdown/base'
2
+
3
+ module PuppetStrings::Markdown
4
+ class PuppetPlan < Base
5
+ def initialize(registry)
6
+ @template = 'classes_and_defines.erb'
7
+ super(registry, 'plan')
8
+ end
9
+
10
+ def render
11
+ super(@template)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'puppet_plan'
2
+
3
+ module PuppetStrings::Markdown
4
+ module PuppetPlans
5
+
6
+ # @return [Array] list of classes
7
+ def self.in_plans
8
+ arr = YARD::Registry.all(:puppet_plan).sort_by!(&:name).map!(&:to_hash)
9
+ arr.map! { |a| PuppetStrings::Markdown::PuppetPlan.new(a) }
10
+ end
11
+
12
+ def self.contains_private?
13
+ result = false
14
+ unless in_plans.nil?
15
+ in_plans.find { |plan| plan.private? }.nil? ? false : true
16
+ end
17
+ end
18
+
19
+ def self.render
20
+ final = in_plans.length > 0 ? "## Plans\n\n" : ""
21
+ in_plans.each do |plan|
22
+ final << plan.render unless plan.private?
23
+ end
24
+ final
25
+ end
26
+
27
+ def self.toc_info
28
+ final = ["Plans"]
29
+
30
+ in_plans.each do |plan|
31
+ final.push(plan.toc_info)
32
+ end
33
+
34
+ final
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ require 'puppet-strings/markdown/base'
2
+
3
+ module PuppetStrings::Markdown
4
+ class PuppetTask < Base
5
+ def initialize(registry)
6
+ @template = 'puppet_task.erb'
7
+ @registry = registry
8
+ super(registry, 'task')
9
+ end
10
+
11
+ def render
12
+ super(@template)
13
+ end
14
+
15
+ def supports_noop
16
+ @registry[:supports_noop]
17
+ end
18
+
19
+ def input_method
20
+ @registry[:input_method]
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ require_relative 'puppet_task'
2
+
3
+ module PuppetStrings::Markdown
4
+ module PuppetTasks
5
+
6
+ # @return [Array] list of classes
7
+ def self.in_tasks
8
+ arr = YARD::Registry.all(:puppet_task).sort_by!(&:name).map!(&:to_hash)
9
+ arr.map! { |a| PuppetStrings::Markdown::PuppetTask.new(a) }
10
+ end
11
+
12
+ def self.contains_private?
13
+ false
14
+ end
15
+
16
+ def self.render
17
+ final = in_tasks.length > 0 ? "## Tasks\n\n" : ""
18
+ in_tasks.each do |task|
19
+ final << task.render unless task.private?
20
+ end
21
+ final
22
+ end
23
+
24
+ def self.toc_info
25
+ final = ["Tasks"]
26
+
27
+ in_tasks.each do |task|
28
+ final.push(task.toc_info)
29
+ end
30
+
31
+ final
32
+ end
33
+ end
34
+ end
@@ -6,7 +6,9 @@ module PuppetStrings::Markdown
6
6
  [PuppetStrings::Markdown::PuppetClasses,
7
7
  PuppetStrings::Markdown::DefinedTypes,
8
8
  PuppetStrings::Markdown::ResourceTypes,
9
- PuppetStrings::Markdown::Functions].each do |r|
9
+ PuppetStrings::Markdown::Functions,
10
+ PuppetStrings::Markdown::PuppetTasks,
11
+ PuppetStrings::Markdown::PuppetPlans].each do |r|
10
12
  toc = r.toc_info
11
13
  group_name = toc.shift
12
14
  group = toc
@@ -2,14 +2,12 @@
2
2
 
3
3
  <% if text -%>
4
4
  <%= text %>
5
-
6
5
  <% elsif summary -%>
7
6
  <%= summary %>
8
-
9
7
  <% else -%>
10
8
  <%= "The #{name} class." %>
11
-
12
9
  <% end -%>
10
+
13
11
  <% if since -%>
14
12
  * **Since** <%= since %>
15
13
 
@@ -17,22 +15,28 @@
17
15
  <% if see -%>
18
16
  * **See also**
19
17
  <% see.each do |sa| -%>
18
+ <% if sa[:name] -%>
20
19
  <%= sa[:name] %>
20
+ <% end -%>
21
+ <% if sa[:text] -%>
21
22
  <%= sa[:text] %>
22
23
  <% end -%>
24
+ <% end -%>
23
25
 
24
26
  <% end -%>
25
27
  <% if examples -%>
26
28
  #### Examples
29
+
27
30
  <% examples.each do |eg| -%>
28
31
  ##### <%= eg[:name] %>
32
+
29
33
  ```puppet
30
34
  <%= eg[:text] %>
31
35
  ```
32
36
 
33
37
  <% end -%>
34
38
  <% end -%>
35
- <% if params %>
39
+ <% if params -%>
36
40
  #### Parameters
37
41
 
38
42
  The following parameters are available in the `<%= name %>` <%= @type %>.
@@ -60,4 +64,3 @@ Default value: <%= value_string(defaults[param[:name]]) %>
60
64
  <% end -%>
61
65
  <% end -%>
62
66
  <% end -%>
63
-
@@ -1,16 +1,15 @@
1
1
  ### <%= name %>
2
+
2
3
  Type: <%= type %>
3
4
 
4
5
  <% if text -%>
5
6
  <%= text %>
6
-
7
7
  <% elsif summary -%>
8
8
  <%= summary %>
9
-
10
9
  <% else -%>
11
10
  <%= "The #{name} class." %>
12
-
13
11
  <% end -%>
12
+
14
13
  <% signatures.each do |sig| -%>
15
14
  #### `<%= sig.signature %>`
16
15
 
@@ -0,0 +1,28 @@
1
+ ### <%= name %>
2
+
3
+ <% if text -%>
4
+ <%= text %>
5
+
6
+ <% elsif summary -%>
7
+ <%= summary %>
8
+
9
+ <% else -%>
10
+ <%= "The #{name} task." %>
11
+
12
+ <% end -%>
13
+ **Supports noop?** <%= supports_noop %>
14
+
15
+ <% if params -%>
16
+ #### Parameters
17
+
18
+ <% params.each do |param| -%>
19
+ ##### `<%= param[:name] %>`
20
+
21
+ <% if param[:types] -%>
22
+ Data type: `<%= param[:types].join(', ') -%>`
23
+
24
+ <% end -%>
25
+ <%= param[:text] %>
26
+
27
+ <% end -%>
28
+ <% end -%>
@@ -2,14 +2,12 @@
2
2
 
3
3
  <% if text -%>
4
4
  <%= text %>
5
-
6
5
  <% elsif summary -%>
7
6
  <%= summary %>
8
-
9
7
  <% else -%>
10
8
  <%= "The #{name} type." %>
11
-
12
9
  <% end -%>
10
+
13
11
  <% if since -%>
14
12
  * **Since** <%= since %>
15
13
 
@@ -17,21 +15,28 @@
17
15
  <% if see -%>
18
16
  * **See also**
19
17
  <% see.each do |sa| -%>
18
+ <% if sa[:name] -%>
20
19
  <%= sa[:name] %>
20
+ <% end -%>
21
+ <% if sa[:text] -%>
21
22
  <%= sa[:text] %>
22
23
  <% end -%>
24
+ <% end -%>
23
25
 
24
26
  <% end -%>
25
27
  <% if examples -%>
26
28
  #### Examples
29
+
27
30
  <% examples.each do |eg| -%>
28
31
  ##### <%= eg[:name] %>
32
+
29
33
  ```puppet
30
34
  <%= eg[:text] %>
31
35
  ```
36
+
32
37
  <% end -%>
33
38
  <% end -%>
34
- <% if properties %>
39
+ <% if properties -%>
35
40
  #### Properties
36
41
 
37
42
  The following properties are available in the `<%= name %>` <%= @type %>.
@@ -111,4 +116,3 @@ Default value: <%= value_string(param[:default]) %>
111
116
  <% end -%>
112
117
  <% end -%>
113
118
  <% end -%>
114
-
@@ -1,13 +1,17 @@
1
1
  <% if group.length > 0 -%>
2
2
  ## <%= group_name %>
3
+
3
4
  <% if priv -%>
4
5
  ### Public <%= group_name %>
6
+
5
7
  <% group.each do |item| -%>
6
8
  <% unless item[:private] -%>
7
9
  * [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
8
10
  <% end -%>
9
11
  <% end -%>
12
+
10
13
  ### Private <%= group_name %>
14
+
11
15
  <% group.each do |item| -%>
12
16
  <% if item[:private] -%>
13
17
  * `<%= item[:name] %>`: <%= item[:desc] %>
@@ -18,4 +22,5 @@
18
22
  * [`<%= item[:name] %>`](#<%= item[:link] %>): <%= item[:desc] %>
19
23
  <% end -%>
20
24
  <% end -%>
25
+
21
26
  <% end -%>
@@ -0,0 +1,11 @@
1
+ # Monkey patch URL decoding in object displays. Usually :: is interpreted as a
2
+ # namespace, but this is disabled in our base object, and so instead gets
3
+ # URL-encoded.
4
+ require 'yard/server/commands/display_object_command'
5
+ class YARD::Server::Commands::DisplayObjectCommand
6
+ private
7
+ alias_method :object_path_yard, :object_path
8
+ def object_path
9
+ object_path_yard.gsub('_3A', ':')
10
+ end
11
+ end
@@ -6,6 +6,7 @@ module PuppetStrings::Yard
6
6
  require 'puppet-strings/yard/handlers'
7
7
  require 'puppet-strings/yard/tags'
8
8
  require 'puppet-strings/yard/parsers'
9
+ require 'puppet-strings/monkey_patches/display_object_command'
9
10
 
10
11
  # Sets up YARD for use with puppet-strings.
11
12
  # @return [void]
@@ -15,10 +16,12 @@ module PuppetStrings::Yard
15
16
 
16
17
  # Register the Puppet parser
17
18
  YARD::Parser::SourceParser.register_parser_type(:puppet, PuppetStrings::Yard::Parsers::Puppet::Parser, ['pp'])
19
+ YARD::Parser::SourceParser.register_parser_type(:json, PuppetStrings::Yard::Parsers::JSON::Parser, ['json'])
18
20
 
19
21
  # Register our handlers
20
22
  YARD::Handlers::Processor.register_handler_namespace(:puppet, PuppetStrings::Yard::Handlers::Puppet)
21
23
  YARD::Handlers::Processor.register_handler_namespace(:puppet_ruby, PuppetStrings::Yard::Handlers::Ruby)
24
+ YARD::Handlers::Processor.register_handler_namespace(:json, PuppetStrings::Yard::Handlers::JSON)
22
25
 
23
26
  # Register the tag directives
24
27
  PuppetStrings::Yard::Tags::ParameterDirective.register!
@@ -46,7 +49,9 @@ class YARD::CLI::Yardoc
46
49
  :puppet_defined_type,
47
50
  :puppet_type,
48
51
  :puppet_provider,
49
- :puppet_function
52
+ :puppet_function,
53
+ :puppet_task,
54
+ :puppet_plan
50
55
  )
51
56
  end
52
57
  end
@@ -75,6 +80,15 @@ class YARD::CLI::Stats
75
80
  output 'Puppet Functions', *type_statistics_all(:puppet_function)
76
81
  end
77
82
 
83
+ def stats_for_puppet_tasks
84
+ output 'Puppet Tasks', *type_statistics_all(:puppet_task)
85
+ end
86
+
87
+ def stats_for_puppet_plans
88
+ return unless PuppetStrings.puppet_5?
89
+ output 'Puppet Plans', *type_statistics_all(:puppet_plan)
90
+ end
91
+
78
92
  def output(name, data, undoc = nil)
79
93
  # Monkey patch output to accommodate our larger header widths
80
94
  @total += data if data.is_a?(Integer) && undoc
@@ -5,4 +5,6 @@ module PuppetStrings::Yard::CodeObjects
5
5
  require 'puppet-strings/yard/code_objects/type'
6
6
  require 'puppet-strings/yard/code_objects/provider'
7
7
  require 'puppet-strings/yard/code_objects/function'
8
+ require 'puppet-strings/yard/code_objects/task'
9
+ require 'puppet-strings/yard/code_objects/plan'
8
10
  end
@@ -0,0 +1,56 @@
1
+ require 'puppet-strings/yard/code_objects/group'
2
+
3
+ class PuppetStrings::Yard::CodeObjects::Plans < PuppetStrings::Yard::CodeObjects::Group
4
+ # Gets the singleton instance of the group.
5
+ # @return Returns the singleton instance of the group.
6
+ def self.instance
7
+ super(:puppet_plans)
8
+ end
9
+
10
+ # Gets the display name of the group.
11
+ # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
12
+ # @return [String] Returns the display name of the group.
13
+ def name(prefix = false)
14
+ 'Puppet Plans'
15
+ end
16
+ end
17
+
18
+ class PuppetStrings::Yard::CodeObjects::Plan < PuppetStrings::Yard::CodeObjects::Base
19
+ attr_reader :statement
20
+ attr_reader :parameters
21
+
22
+ # Initializes a Puppet plan code object.
23
+ # @param [PuppetStrings::Parsers::PlanStatement] statement The plan statement that was parsed.
24
+ # @return [void]
25
+ def initialize(statement)
26
+ @statement = statement
27
+ @parameters = statement.parameters.map { |p| [p.name, p.value] }
28
+ super(PuppetStrings::Yard::CodeObjects::Plans.instance, statement.name)
29
+ end
30
+
31
+ # Gets the type of the code object.
32
+ # @return Returns the type of the code object.
33
+ def type
34
+ :puppet_plan
35
+ end
36
+
37
+ # Gets the source of the code object.
38
+ # @return Returns the source of the code object.
39
+ def source
40
+ @statement.source
41
+ end
42
+
43
+ # Converts the code object to a hash representation.
44
+ # @return [Hash] Returns a hash representation of the code object.
45
+ def to_hash
46
+ hash = {}
47
+ hash[:name] = name
48
+ hash[:file] = file
49
+ hash[:line] = line
50
+ hash[:docstring] = PuppetStrings::Json.docstring_to_hash(docstring)
51
+ defaults = Hash[*parameters.select{ |p| !p[1].nil? }.flatten]
52
+ hash[:defaults] = defaults unless defaults.empty?
53
+ hash[:source] = source unless source && source.empty?
54
+ hash
55
+ end
56
+ end