puppet-strings 0.99.0 → 1.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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/Gemfile +7 -6
  4. data/JSON.md +193 -20
  5. data/README.md +231 -140
  6. data/lib/puppet-strings/json.rb +19 -10
  7. data/lib/puppet-strings/tasks/gh_pages.rb +15 -4
  8. data/lib/puppet-strings/yard/code_objects/function.rb +13 -3
  9. data/lib/puppet-strings/yard/code_objects/provider.rb +5 -6
  10. data/lib/puppet-strings/yard/code_objects/type.rb +2 -1
  11. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +9 -4
  12. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +13 -4
  13. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +11 -6
  14. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +3 -3
  15. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +8 -0
  16. data/lib/puppet-strings/yard/tags/overload_tag.rb +2 -2
  17. data/lib/puppet-strings/yard/templates/default/fulldoc/html/css/common.css +8 -0
  18. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/collection.erb +9 -2
  19. data/lib/puppet-strings/yard/templates/default/tags/html/puppet_overload.erb +1 -1
  20. data/lib/puppet-strings/yard/util.rb +17 -0
  21. data/spec/acceptance/emit_json_options.rb +15 -1
  22. data/spec/fixtures/unit/json/output.json +220 -9
  23. data/spec/fixtures/unit/json/output_without_puppet_function.json +179 -8
  24. data/spec/spec_helper.rb +3 -0
  25. data/spec/unit/puppet-strings/json_spec.rb +15 -4
  26. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +72 -0
  27. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +44 -0
  28. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +20 -2
  29. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +25 -1
  30. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +38 -0
  31. data/spec/unit/puppet-strings/yard/util_spec.rb +31 -0
  32. metadata +5 -2
@@ -55,6 +55,23 @@ SOURCE
55
55
  end
56
56
  end
57
57
 
58
+ describe 'parsing a type with a docstring which uses ruby `%Q` notation' do
59
+ let(:source) { <<-'SOURCE'
60
+ Puppet::Type.newtype(:database) do
61
+ test = 'hello world!'
62
+ desc %Q{This is a multi-line
63
+ doc in %Q with #{test}}
64
+ end
65
+ SOURCE
66
+ }
67
+
68
+ it 'should strip the `%Q{}` and render the interpolation expression literally' do
69
+ expect(subject.size).to eq(1)
70
+ object = subject.first
71
+ expect(object.docstring).to eq("This is a multi-line\ndoc in %Q with \#{test}")
72
+ end
73
+ end
74
+
58
75
  describe 'parsing a type definition' do
59
76
  let(:source) { <<-SOURCE
60
77
  # @!puppet.type.param [value1, value2] dynamic_param Documentation for a dynamic parameter.
@@ -62,6 +79,11 @@ SOURCE
62
79
  Puppet::Type.newtype(:database) do
63
80
  desc 'An example database server resource type.'
64
81
  feature :encryption, 'The provider supports encryption.', methods: [:encrypt]
82
+
83
+ feature :magic,
84
+ 'The feature docstring should have
85
+ whitespace and newlines stripped out.'
86
+
65
87
  ensurable do
66
88
  desc 'What state the database should be in.'
67
89
  defaultvalues
@@ -167,9 +189,11 @@ SOURCE
167
189
  expect(object.parameters[4].isnamevar).to eq(false)
168
190
  expect(object.parameters[4].default).to eq('never')
169
191
  expect(object.parameters[4].values).to eq(%w(daily monthly never))
170
- expect(object.features.size).to eq(1)
192
+ expect(object.features.size).to eq(2)
171
193
  expect(object.features[0].name).to eq('encryption')
172
194
  expect(object.features[0].docstring).to eq('The provider supports encryption.')
195
+ expect(object.features[1].name).to eq('magic')
196
+ expect(object.features[1].docstring).to eq('The feature docstring should have whitespace and newlines stripped out.')
173
197
  end
174
198
  end
175
199
 
@@ -168,4 +168,42 @@ SOURCE
168
168
  expect(statement.parameters[2].value).to eq('hi')
169
169
  end
170
170
  end
171
+
172
+ describe 'parsing puppet functions with return type in defintion', if: TEST_FUNCTION_RETURN_TYPE do
173
+ let(:source) { <<SOURCE
174
+ # A simple foo function.
175
+ # @return Returns a string
176
+ function foo() >> String {
177
+ notice world
178
+ }
179
+ SOURCE
180
+ }
181
+
182
+ it 'should parse the puppet function statement' do
183
+ subject.parse
184
+ expect(subject.enumerator.size).to eq(1)
185
+ statement = subject.enumerator.first
186
+ expect(statement).to be_a(PuppetStrings::Yard::Parsers::Puppet::FunctionStatement)
187
+ expect(statement.type).to eq('String')
188
+ end
189
+ end
190
+
191
+ describe 'parsing puppet functions with complex return types in defintion', if: TEST_FUNCTION_RETURN_TYPE do
192
+ let(:source) { <<SOURCE
193
+ # A simple foo function.
194
+ # @return Returns a struct with a hash including one key which must be an integer between 1 and 10.
195
+ function foo() >> Struct[{'a' => Integer[1, 10]}] {
196
+ notice world
197
+ }
198
+ SOURCE
199
+ }
200
+
201
+ it 'should parse the puppet function statement' do
202
+ subject.parse
203
+ expect(subject.enumerator.size).to eq(1)
204
+ statement = subject.enumerator.first
205
+ expect(statement).to be_a(PuppetStrings::Yard::Parsers::Puppet::FunctionStatement)
206
+ expect(statement.type).to eq("Struct\[{'a' => Integer[1, 10]}\]")
207
+ end
208
+ end
171
209
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'puppet-strings/yard'
3
+
4
+ describe PuppetStrings::Yard::Util do
5
+ subject {PuppetStrings::Yard::Util}
6
+
7
+ describe 'scrub_string' do
8
+ it 'should remove `%Q` and its brackets from a string ' do
9
+ str = "%Q{this is a test string}"
10
+ expect(subject.scrub_string(str)).to eq('this is a test string')
11
+ end
12
+
13
+ it 'should remove `%q` and its brackets from a string' do
14
+ str = "%q{this is a test string}"
15
+ expect(subject.scrub_string(str)).to eq('this is a test string')
16
+ end
17
+
18
+ it 'should not affect newlines when %Q notation is used' do
19
+ str = <<-STR
20
+ %Q{this is
21
+ a test string}
22
+ STR
23
+ expect(subject.scrub_string(str)).to eq("this is\na test string")
24
+ end
25
+
26
+ it 'should not affect a string which does not use %Q notation' do
27
+ str = "this is a test string"
28
+ expect(subject.scrub_string(str)).to eq('this is a test string')
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-strings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-10 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -73,6 +73,7 @@ files:
73
73
  - lib/puppet-strings/yard/tags/overload_tag.rb
74
74
  - lib/puppet-strings/yard/tags/parameter_directive.rb
75
75
  - lib/puppet-strings/yard/tags/property_directive.rb
76
+ - lib/puppet-strings/yard/templates/default/fulldoc/html/css/common.css
76
77
  - lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb
77
78
  - lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb
78
79
  - lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb
@@ -110,6 +111,7 @@ files:
110
111
  - lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb
111
112
  - lib/puppet-strings/yard/templates/default/tags/html/puppet_overload.erb
112
113
  - lib/puppet-strings/yard/templates/default/tags/setup.rb
114
+ - lib/puppet-strings/yard/util.rb
113
115
  - lib/puppet/application/strings.rb
114
116
  - lib/puppet/face/strings.rb
115
117
  - lib/puppet/feature/rgen.rb
@@ -137,6 +139,7 @@ files:
137
139
  - spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb
138
140
  - spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb
139
141
  - spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb
142
+ - spec/unit/puppet-strings/yard/util_spec.rb
140
143
  homepage: https://github.com/puppetlabs/puppet-strings
141
144
  licenses:
142
145
  - Apache-2.0