puppet-strings 2.2.0 → 2.3.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.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +14 -5
  4. data/JSON.md +41 -11
  5. data/README.md +66 -7
  6. data/Rakefile +99 -29
  7. data/lib/puppet-strings/json.rb +2 -0
  8. data/lib/puppet-strings/markdown.rb +2 -0
  9. data/lib/puppet-strings/markdown/data_type.rb +18 -0
  10. data/lib/puppet-strings/markdown/data_types.rb +41 -0
  11. data/lib/puppet-strings/markdown/function.rb +2 -2
  12. data/lib/puppet-strings/markdown/table_of_contents.rb +1 -0
  13. data/lib/puppet-strings/markdown/templates/data_type.erb +78 -0
  14. data/lib/puppet-strings/tasks/generate.rb +3 -2
  15. data/lib/puppet-strings/version.rb +1 -1
  16. data/lib/puppet-strings/yard.rb +10 -0
  17. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  18. data/lib/puppet-strings/yard/code_objects/class.rb +1 -1
  19. data/lib/puppet-strings/yard/code_objects/data_type.rb +80 -0
  20. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +58 -0
  21. data/lib/puppet-strings/yard/code_objects/defined_type.rb +1 -1
  22. data/lib/puppet-strings/yard/code_objects/function.rb +3 -3
  23. data/lib/puppet-strings/yard/code_objects/plan.rb +1 -1
  24. data/lib/puppet-strings/yard/handlers.rb +2 -0
  25. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +24 -0
  26. data/lib/puppet-strings/yard/handlers/ruby/base.rb +2 -2
  27. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +236 -0
  28. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +1 -3
  29. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +2 -2
  30. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +5 -6
  31. data/lib/puppet-strings/yard/parsers/json/parser.rb +1 -1
  32. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +14 -7
  33. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +25 -0
  34. data/lib/puppet-strings/yard/tags/overload_tag.rb +1 -1
  35. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
  36. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
  37. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
  38. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
  39. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
  40. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
  41. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
  42. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
  43. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +5 -0
  44. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
  45. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
  46. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
  47. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
  48. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
  49. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
  50. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
  51. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
  52. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
  53. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
  54. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
  55. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
  56. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +1 -0
  57. data/lib/puppet/face/strings.rb +3 -3
  58. data/spec/acceptance/emit_json_options_spec.rb +69 -0
  59. data/spec/acceptance/generate_markdown_spec.rb +13 -15
  60. data/spec/acceptance/running_strings_generate_spec.rb +78 -0
  61. data/spec/fixtures/acceptance/modules/test/metadata.json +5 -1
  62. data/spec/fixtures/acceptance/modules/test/types/elephant.pp +2 -0
  63. data/spec/fixtures/unit/markdown/output_with_data_types.md +553 -0
  64. data/spec/spec_helper.rb +3 -0
  65. data/spec/spec_helper_acceptance.rb +52 -22
  66. data/spec/spec_helper_acceptance_local.rb +10 -0
  67. data/spec/unit/puppet-strings/describe_spec.rb +7 -7
  68. data/spec/unit/puppet-strings/json_spec.rb +23 -4
  69. data/spec/unit/puppet-strings/markdown/base_spec.rb +3 -3
  70. data/spec/unit/puppet-strings/markdown_spec.rb +84 -23
  71. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +1 -1
  72. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +4 -4
  73. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +8 -8
  74. data/spec/unit/puppet-strings/yard/handlers/puppet/data_type_alias_handler_spec.rb +65 -0
  75. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +8 -8
  76. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +13 -13
  77. data/spec/unit/puppet-strings/yard/handlers/ruby/data_type_handler_spec.rb +232 -0
  78. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +36 -19
  79. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +26 -7
  80. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +7 -7
  81. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +26 -10
  82. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +2 -2
  83. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +42 -0
  84. data/spec/unit/puppet-strings/yard/util_spec.rb +1 -1
  85. metadata +35 -7
  86. data/spec/acceptance/emit_json_options.rb +0 -71
  87. data/spec/acceptance/lib/util.rb +0 -163
  88. data/spec/acceptance/running_strings_generate.rb +0 -54
@@ -301,9 +301,7 @@ class PuppetStrings::Yard::Handlers::Ruby::FunctionHandler < PuppetStrings::Yard
301
301
  name = '&' + name
302
302
  end
303
303
 
304
- unless type
305
- type = tag && tag.types ? tag.type : 'Any'
306
- end
304
+ type ||= tag && tag.types ? tag.type : 'Any'
307
305
  type = optional ? "Optional[#{type}]" : type
308
306
 
309
307
  object.parameters << [name, to_puppet_literal(default)]
@@ -15,7 +15,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
15
15
  # Only accept calls to Puppet::ResourceApi
16
16
  return unless statement.count > 1
17
17
  module_name = statement[0].source
18
- return unless [ 'Puppet::ResourceApi' ].include? module_name
18
+ return unless ['Puppet::ResourceApi'].include? module_name
19
19
 
20
20
  schema = extract_schema
21
21
 
@@ -92,7 +92,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H
92
92
  # puts "hash from #{node.inspect}"
93
93
 
94
94
  kv_pairs = node.children.collect do |assoc|
95
- [ value_from_node(assoc.children[0]), value_from_node(assoc.children[1]) ]
95
+ [value_from_node(assoc.children[0]), value_from_node(assoc.children[1])]
96
96
  end
97
97
  Hash[kv_pairs]
98
98
  end
@@ -15,7 +15,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
15
15
  register object
16
16
  object
17
17
  end
18
-
18
+
19
19
  def find_docstring(node, kind)
20
20
  # Walk the tree searching for assignments or calls to desc/doc=
21
21
  node.traverse do |child|
@@ -98,10 +98,10 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
98
98
  next unless kvp.count == 2
99
99
  next unless node_as_string(kvp[0]) == 'parent'
100
100
  if kvp[1].source == 'Puppet::Parameter::Boolean'
101
- object.add('true') unless object.values.include? 'true'
102
- object.add('false') unless object.values.include? 'false'
103
- object.add('yes') unless object.values.include? 'yes'
104
- object.add('no') unless object.values.include? 'no'
101
+ object.add('true') unless object.values.include? 'true' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
102
+ object.add('false') unless object.values.include? 'false' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
103
+ object.add('yes') unless object.values.include? 'yes' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
104
+ object.add('no') unless object.values.include? 'no' # rubocop:disable Performance/InefficientHashSearch Not supported on Ruby 2.1
105
105
  end
106
106
  break
107
107
  end
@@ -127,4 +127,3 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeBase < PuppetStrings::Yard::Handl
127
127
  default.isnamevar = true if default
128
128
  end
129
129
  end
130
-
@@ -25,7 +25,7 @@ class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
25
25
  # TODO: this should compare json to a Task metadata json-schema or perform some other hueristics
26
26
  # to determine what type of statement it represents
27
27
  @statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) unless json.empty?
28
- rescue
28
+ rescue # rubocop:disable Style/RescueStandardError Just catch everything
29
29
  log.error "Failed to parse #{@file}: "
30
30
  @statements = []
31
31
  end
@@ -41,41 +41,48 @@ class PuppetStrings::Yard::Parsers::Puppet::Parser < YARD::Parser::Base
41
41
  end
42
42
 
43
43
  private
44
- def transform_Program(o)
44
+
45
+ def transform_Program(o) # rubocop:disable Naming/UncommunicativeMethodParamName
45
46
  # Cache the lines of the source text; we'll use this to locate comments
46
47
  @lines = o.source_text.lines.to_a
47
48
  o.definitions.map { |d| @visitor.visit(d) }
48
49
  end
49
50
 
50
- def transform_Factory(o)
51
+ def transform_Factory(o) # rubocop:disable Naming/UncommunicativeMethodParamName
51
52
  @visitor.visit(o.current)
52
53
  end
53
54
 
54
- def transform_HostClassDefinition(o)
55
+ def transform_HostClassDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
55
56
  statement = PuppetStrings::Yard::Parsers::Puppet::ClassStatement.new(o, @file)
56
57
  statement.extract_docstring(@lines)
57
58
  statement
58
59
  end
59
60
 
60
- def transform_ResourceTypeDefinition(o)
61
+ def transform_ResourceTypeDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
61
62
  statement = PuppetStrings::Yard::Parsers::Puppet::DefinedTypeStatement.new(o, @file)
62
63
  statement.extract_docstring(@lines)
63
64
  statement
64
65
  end
65
66
 
66
- def transform_FunctionDefinition(o)
67
+ def transform_FunctionDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
67
68
  statement = PuppetStrings::Yard::Parsers::Puppet::FunctionStatement.new(o, @file)
68
69
  statement.extract_docstring(@lines)
69
70
  statement
70
71
  end
71
72
 
72
- def transform_PlanDefinition(o)
73
+ def transform_PlanDefinition(o) # rubocop:disable Naming/UncommunicativeMethodParamName
73
74
  statement = PuppetStrings::Yard::Parsers::Puppet::PlanStatement.new(o, @file)
74
75
  statement.extract_docstring(@lines)
75
76
  statement
76
77
  end
77
78
 
78
- def transform_Object(o)
79
+ def transform_TypeAlias(o) # rubocop:disable Naming/UncommunicativeMethodParamName
80
+ statement = PuppetStrings::Yard::Parsers::Puppet::DataTypeAliasStatement.new(o, @file)
81
+ statement.extract_docstring(@lines)
82
+ statement
83
+ end
84
+
85
+ def transform_Object(o) # rubocop:disable Naming/UncommunicativeMethodParamName
79
86
  # Ignore anything else (will be compacted out of the resulting array)
80
87
  end
81
88
  end
@@ -165,4 +165,29 @@ module PuppetStrings::Yard::Parsers::Puppet
165
165
  end
166
166
  end
167
167
 
168
+ # Implements the Puppet data type alias statement.
169
+ class DataTypeAliasStatement < Statement
170
+ attr_reader :name
171
+ attr_reader :alias_of
172
+
173
+ # Initializes the Puppet data type alias statement.
174
+ # @param [Puppet::Pops::Model::TypeAlias] object The model object for the type statement.
175
+ # @param [String] file The file containing the statement.
176
+ def initialize(object, file)
177
+ super(object, file)
178
+
179
+ type_expr = object.type_expr
180
+ case type_expr
181
+ when Puppet::Pops::Model::AccessExpression
182
+ # TODO: I don't like rebuilding the source from the AST, but AccessExpressions don't expose the original source
183
+ @alias_of = ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(type_expr.left_expr).extract_text + '['
184
+ @alias_of << type_expr.keys.map { |key| ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(key).extract_text }.join(', ')
185
+ @alias_of << ']'
186
+ else
187
+ adapter = ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(type_expr)
188
+ @alias_of = adapter.extract_text
189
+ end
190
+ @name = object.name
191
+ end
192
+ end
168
193
  end
@@ -100,7 +100,7 @@ class PuppetStrings::Yard::Tags::OverloadTag < YARD::Tags::Tag
100
100
  hash[:text] = text if text
101
101
  hash[:signature] = signature
102
102
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring) if !docstring.blank?
103
- defaults = Hash[*parameters.select{ |p| !p[1].nil? }.flatten]
103
+ defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
104
104
  hash[:defaults] = defaults unless defaults.empty?
105
105
  hash[:types] = types if types
106
106
  hash[:name] = name if name
@@ -0,0 +1,10 @@
1
+ <% even = false %>
2
+ <% @items.each do |item| %>
3
+ <li id="object_<%=item.path%>" class="<%= even ? 'even' : 'odd' %>">
4
+ <div class="item">
5
+ <%= linkify item, h(item.name(false)) %>
6
+ <% if item.type == :puppet_data_type_alias %><small>Alias</small><% end %>
7
+ </div>
8
+ </li>
9
+ <% even = !even %>
10
+ <% end %>
@@ -7,6 +7,15 @@ def generate_puppet_class_list
7
7
  generate_list_contents
8
8
  end
9
9
 
10
+ # Generates the searchable Puppet data type list.
11
+ # @return [void]
12
+ def generate_puppet_data_type_list
13
+ @items = Registry.all(:puppet_data_type, :puppet_data_type_alias).sort_by {|dt| dt.name.to_s }
14
+ @list_title = 'Data Type List'
15
+ @list_type = 'puppet_data_type'
16
+ generate_list_contents
17
+ end
18
+
10
19
  # Generates the searchable Puppet defined type list.
11
20
  # @return [void]
12
21
  def generate_puppet_defined_type_list
@@ -23,6 +23,8 @@
23
23
  <small>(Resource type: <%= obj.type_name %>)</small>
24
24
  <% elsif obj.type == :puppet_function %>
25
25
  <small>(<%= obj.function_type %>)</small>
26
+ <% elsif obj.type == :puppet_data_type_alias %>
27
+ <small>(Alias)</small>
26
28
  <% end %>
27
29
  </li>
28
30
  <% end %>
@@ -4,7 +4,7 @@ def init
4
4
  case object
5
5
  when '_index.html'
6
6
  @page_title = options.title
7
- sections :layout, [:index, [:listing, [:classes, :defined_types, :types, :providers, :functions, :tasks, :plans, :files, :objects]]]
7
+ sections :layout, [:index, [:listing, [:classes, :data_types, :defined_types, :types, :providers, :functions, :tasks, :plans, :files, :objects]]]
8
8
  else
9
9
  super
10
10
  end
@@ -30,6 +30,10 @@ def layout
30
30
  @nav_url = url_for_list('puppet_class')
31
31
  @page_title = "Puppet Class: #{object.name}"
32
32
  @path = object.path
33
+ when PuppetStrings::Yard::CodeObjects::DataType, PuppetStrings::Yard::CodeObjects::DataTypeAlias
34
+ @nav_url = url_for_list('puppet_data_type')
35
+ @page_title = "Data Type: #{object.name}"
36
+ @path = object.path
33
37
  when PuppetStrings::Yard::CodeObjects::DefinedType
34
38
  @nav_url = url_for_list('puppet_defined_type')
35
39
  @page_title = "Defined Type: #{object.name}"
@@ -76,6 +80,11 @@ def create_menu_lists
76
80
  title: 'Puppet Classes',
77
81
  search_title: 'Puppet Classes'
78
82
  },
83
+ {
84
+ type: 'puppet_data_type',
85
+ title: 'Data Types',
86
+ search_title: 'Data Types',
87
+ },
79
88
  {
80
89
  type: 'puppet_defined_type',
81
90
  title: 'Defined Types',
@@ -155,6 +164,14 @@ def classes
155
164
  erb(:objects)
156
165
  end
157
166
 
167
+ # Renders the data types section.
168
+ # @return [String] Returns the rendered section.
169
+ def data_types
170
+ @title = 'Data Type Listing A-Z'
171
+ @objects_by_letter = objects_by_letter(:puppet_data_type, :puppet_data_type_alias)
172
+ erb(:objects)
173
+ end
174
+
158
175
  # Renders the defined types section.
159
176
  # @return [String] Returns the rendered section.
160
177
  def defined_types
@@ -0,0 +1,10 @@
1
+ <div class="box_info">
2
+ <dl>
3
+ <dt>Defined in:</dt>
4
+ <dd>
5
+ <%= object.file %><% if object.files.size > 1 %><span class="defines">,<br />
6
+ <%= object.files[1..-1].map {|f| f.first }.join(",<br /> ") %></div>
7
+ <% end %>
8
+ </dd>
9
+ </dl>
10
+ </div>
@@ -0,0 +1 @@
1
+ <h1>Puppet Data Type: <%= object.name %></h1>
@@ -0,0 +1,6 @@
1
+ <% object.tags(:note).each do |tag| %>
2
+ <div class="note notetag">
3
+ <strong>Note:</strong>
4
+ <%= htmlify_line tag.text %>
5
+ </div>
6
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h2>Overview</h2>
2
+ <div class="docstring">
3
+ <div class="discussion">
4
+ <%= htmlify(object.docstring) %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,5 @@
1
+ # Initializes the template.
2
+ # @return [void]
3
+ def init
4
+ sections :header, :box_info, :summary, :overview, :note, :todo, T('tags'), :source
5
+ end
@@ -0,0 +1,12 @@
1
+ <div class="method_details_list">
2
+ <table class="source_code">
3
+ <tr>
4
+ <td>
5
+ <pre class="lines"><%= "\n\n\n" %><%= h format_lines(object) %></pre>
6
+ </td>
7
+ <td>
8
+ <pre class="code"><span class="info file"># File '<%= h object.file %>'<% if object.line %>, line <%= object.line %><% end %></span><%= "\n\n" %><%= html_syntax_highlight object.source %></pre>
9
+ </td>
10
+ </tr>
11
+ </table>
12
+ </div>
@@ -0,0 +1,4 @@
1
+ <% if object.docstring.has_tag?(:summary) %>
2
+ <h2>Summary</h2>
3
+ <%= object.docstring.tag(:summary).text %>
4
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% object.tags(:todo).each do |tag| %>
2
+ <div class="note todo">
3
+ <strong>TODO:</strong>
4
+ <%= htmlify_line tag.text %>
5
+ </div>
6
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <% if @alias_of && !@alias_of.empty? %>
2
+ <div class="tags">
3
+ <p class="tag_title"><%= @tag_title %></p>
4
+ <div class="docstring">
5
+ <div class="discussion">
6
+ <pre class="code"><span class="info"><%= @alias_of %></span></pre>
7
+ </div>
8
+ </div>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <div class="box_info">
2
+ <dl>
3
+ <dt>Defined in:</dt>
4
+ <dd>
5
+ <%= object.file %><% if object.files.size > 1 %><span class="defines">,<br />
6
+ <%= object.files[1..-1].map {|f| f.first }.join(",<br /> ") %></div>
7
+ <% end %>
8
+ </dd>
9
+ </dl>
10
+ </div>
@@ -0,0 +1 @@
1
+ <h1>Puppet Data Type Alias: <%= object.name %></h1>
@@ -0,0 +1,6 @@
1
+ <% object.tags(:note).each do |tag| %>
2
+ <div class="note notetag">
3
+ <strong>Note:</strong>
4
+ <%= htmlify_line tag.text %>
5
+ </div>
6
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h2>Overview</h2>
2
+ <div class="docstring">
3
+ <div class="discussion">
4
+ <%= htmlify(object.docstring) %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,17 @@
1
+ # Initializes the template.
2
+ # @return [void]
3
+ def init
4
+ sections :header, :box_info, :summary, :overview, :alias_of, :note, :todo, T('tags'), :source
5
+ end
6
+
7
+ # Renders the alias_of section.
8
+ # @return [String] Returns the rendered section.
9
+ def alias_of
10
+ # Properties are the same thing as parameters (from the documentation standpoint),
11
+ # so reuse the same template but with a different title and data source.
12
+ #@parameters = object.properties || []
13
+ #@parameters.sort_by! { |p| p.name }
14
+ @tag_title = 'Alias of'
15
+ @alias_of = object.alias_of
16
+ erb(:alias_of)
17
+ end
@@ -0,0 +1,12 @@
1
+ <div class="method_details_list">
2
+ <table class="source_code">
3
+ <tr>
4
+ <td>
5
+ <pre class="lines"><%= "\n\n\n" %><%= h format_lines(object) %></pre>
6
+ </td>
7
+ <td>
8
+ <pre class="code"><span class="info file"># File '<%= h object.file %>'<% if object.line %>, line <%= object.line %><% end %></span><%= "\n\n" %><%= html_syntax_highlight object.source %></pre>
9
+ </td>
10
+ </tr>
11
+ </table>
12
+ </div>
@@ -0,0 +1,4 @@
1
+ <% if object.docstring.has_tag?(:summary) %>
2
+ <h2>Summary</h2>
3
+ <%= object.docstring.tag(:summary).text %>
4
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% object.tags(:todo).each do |tag| %>
2
+ <div class="note todo">
3
+ <strong>TODO:</strong>
4
+ <%= htmlify_line tag.text %>
5
+ </div>
6
+ <% end %>
@@ -4,6 +4,7 @@ def param
4
4
  tag(:param) if
5
5
  object.type == :method ||
6
6
  object.type == :puppet_class ||
7
+ object.type == :puppet_data_type ||
7
8
  object.type == :puppet_defined_type ||
8
9
  object.type == :puppet_function ||
9
10
  object.type == :puppet_task ||
@@ -117,7 +117,7 @@ Puppet::Face.define(:strings, '0.0.1') do
117
117
 
118
118
  if args.length > 1
119
119
  if options[:list]
120
- $stderr.puts "WARNING: ignoring types when listing all types."
120
+ warn "WARNING: ignoring types when listing all types."
121
121
  else
122
122
  options[:describe_types] = args[0..-2]
123
123
  end
@@ -159,10 +159,10 @@ Puppet::Face.define(:strings, '0.0.1') do
159
159
  generate_options[:yard_args] = yard_args unless yard_args.empty?
160
160
  if options
161
161
  if options[:emit_json]
162
- $stderr.puts "WARNING: '--emit-json PATH' is deprecated. Use '--format json --out PATH' instead."
162
+ warn "WARNING: '--emit-json PATH' is deprecated. Use '--format json --out PATH' instead."
163
163
  end
164
164
  if options[:emit_json_stdout]
165
- $stderr.puts "WARNING: '--emit-json-stdout' is deprecated. Use '--format json' instead."
165
+ warn "WARNING: '--emit-json-stdout' is deprecated. Use '--format json' instead."
166
166
  end
167
167
  markup = options[:markup]
168
168
  generate_options[:markup] = markup if markup
@@ -0,0 +1,69 @@
1
+ require 'spec_helper_acceptance'
2
+
3
+ describe 'Emitting JSON' do
4
+ before(:all) do
5
+ @test_module_path = sut_module_path(/Module test/)
6
+ @remote_tmp_path = sut_tmp_path
7
+ end
8
+
9
+ let(:expected) do
10
+ {
11
+ "puppet_classes" => [],
12
+ "data_types" => [],
13
+ "data_type_aliases" => [],
14
+ "defined_types" => [],
15
+ "resource_types" => [],
16
+ "providers" => [],
17
+ "puppet_functions" => [
18
+ "name" => "function3x",
19
+ "file" => "#{@test_module_path}/lib/puppet/parser/functions/function3x.rb",
20
+ "line" => 1,
21
+ "type" => "ruby3x",
22
+ "signatures" => [
23
+ {
24
+ "signature" =>"function3x()",
25
+ "docstring" => {
26
+ "text" => "This is the function documentation for `function3x`",
27
+ "tags" => [
28
+ {
29
+ "tag_name"=>"return",
30
+ "text"=>"",
31
+ "types"=>["Any"]
32
+ }
33
+ ]
34
+ }
35
+ },
36
+ ],
37
+ "docstring" => {
38
+ "text" => "This is the function documentation for `function3x`",
39
+ "tags" => ["tag_name" => "return", "text" => "", "types" => ["Any"]]},
40
+ "source" => "Puppet::Parser::Functions.newfunction(:function3x, :doc => \"This is the function documentation for `function3x`\") do |args|\nend"
41
+ ],
42
+ "puppet_tasks" => [],
43
+ "puppet_plans" => []
44
+ }
45
+ end
46
+
47
+ [
48
+ { :title => '--format json and STDOUT', :cmd_line => '--format json' },
49
+ { :title => '--emit-json-stdout', :cmd_line => '--emit-json-stdout' }
50
+ ].each do |testcase|
51
+ it "should emit JSON to stdout when using #{testcase[:title]}" do
52
+ output = PuppetLitmus::Serverspec.run_shell("puppet strings generate #{testcase[:cmd_line]} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\"").stdout.chomp
53
+ expect(JSON.parse(output)).to eq(expected)
54
+ end
55
+ end
56
+
57
+ [
58
+ { :title => '--format json and --out', :cmd_line => '--format json --out "TMPFILE"' },
59
+ { :title => '--emit-json', :cmd_line => '--emit-json "TMPFILE"' },
60
+ ].each do |testcase|
61
+ it "should write JSON to a file when using #{testcase[:title]}" do
62
+ tmpfile = File.join(@remote_tmp_path, 'json_output.json')
63
+ cmd = "puppet strings generate #{testcase[:cmd_line].gsub('TMPFILE', tmpfile)} \"#{@test_module_path}/lib/puppet/parser/functions/function3x.rb\""
64
+ PuppetLitmus::Serverspec.run_shell(cmd)
65
+ output = JSON.parse(file(tmpfile).content)
66
+ expect(output).to eq(expected)
67
+ end
68
+ end
69
+ end