knife-cookbook-doc 0.25.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbbc143a652e8129c85a65adcf70802ae67bcbd0
4
- data.tar.gz: 1630f21c869c7a02da034b4fc23057e0f16f3121
3
+ metadata.gz: 7d4e4e61d176043dd41fa77782ac36203bc1251a
4
+ data.tar.gz: 49a72076fe65ea3f15878479e7c709394e2bc14c
5
5
  SHA512:
6
- metadata.gz: 26328bdf572cfc2b4585ce9ba1164420f3e530f225be7cbbfc37b4370c9dc4ce8a9dbe037b14d1968f948878602661ce48f5d9251bda5b720e69bcd7edb10259
7
- data.tar.gz: 92b78ebc35f1e540e42b2b167149d529cdf3d42bf81ac94aec3f2b4c63fcb36088b50a47a11b14f2868df4d0cbcbaf9d512990966cef047cd94267dcdab2ce38
6
+ metadata.gz: 325f8c3e22e8f67778480106847aafbccc2d7da9d58831005f3fa09b7e3de3c4710c9a05e6023718a8669c064e51c94f3cc8cf5305752704e5d6a587d5c89fae
7
+ data.tar.gz: 876de6b5caff31196e93bd7dd71c8b5fb1c6bec5725a95c24644595ae19954de6a043d1e987be44df56c67c1e376eec46bec027bcd9ef285ce0b7393347e97da
@@ -0,0 +1,47 @@
1
+ <!--
2
+ Thanks for your interest in the project. I appreciate bugs filed and PRs submitted!
3
+ Please make sure that you are familiar with and follow the Code of Conduct for
4
+ this project (found in the CODE_OF_CONDUCT.md file).
5
+
6
+ Please fill out this template with all the relevant information so we can
7
+ understand what's going on and fix the issue.
8
+
9
+ I may ask you to submit the fix (after giving some direction).
10
+ -->
11
+
12
+ Environment:
13
+
14
+ <!--
15
+ Please provide the version of this project where the issue occurred as well as the
16
+ versions of other environmental factors. This could be virtual machine version, os
17
+ version, browser version etc.
18
+ -->
19
+
20
+ Relevant code or config:
21
+
22
+ ```
23
+
24
+ ```
25
+
26
+ What you did:
27
+
28
+
29
+
30
+ What happened:
31
+
32
+ <!-- Please provide the full error message/screenshots/anything -->
33
+
34
+ Reproduction repository:
35
+
36
+ <!--
37
+ If possible, please create a repository that reproduces the issue with the
38
+ minimal amount of code possible. It is highly recommended you take the time
39
+ to read "How to create a Minimal, Complete, and Verifiable example" at
40
+ https://stackoverflow.com/help/mcve
41
+ -->
42
+
43
+ Problem description:
44
+
45
+
46
+
47
+ Suggested solution:
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  /Gemfile.lock
2
+ /*.gem
3
+ /fixture/README-generated.md
2
4
 
3
5
  # Intermediate package dir
4
6
  /pkg
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  cache: bundler
3
- sudo: false
4
3
  gemfile: fixture/gemfile
5
4
 
6
5
  rvm:
@@ -1,3 +1,31 @@
1
+ # v0.29.0 (Jun 26 2020)
2
+
3
+ * Extract descriptions from `libraries/*.rb`. Submitted by Joe Nuspl.
4
+
5
+ # v0.28.0 (Jun 11 2020)
6
+
7
+ * If `Berksfile` exists, add source_url links to cookbooks. Submitted by Joe Nuspl.
8
+
9
+ # v0.27.0 (Jun 20 2019)
10
+
11
+ * Add support for Chef 15. Submitted by grozan.
12
+
13
+ # v0.26.0 (Mar 4 2019)
14
+
15
+ * Display `lazy` defaults as such. Submitted by Joe Nuspl.
16
+
17
+ # v0.25.2 (Dec 18 2018)
18
+
19
+ * Re-release gem with the appropriate version.
20
+
21
+ # v0.24.2 (Dec 17 2018)
22
+
23
+ * Add chef_versions support. Submitted by Nikolay Antsiferov.
24
+
25
+ # v0.25.0 (Mar 7 2018)
26
+
27
+ * Remove deprecated metadata for >= Chef 13. Submitted by Jamie Tanna.
28
+
1
29
  # v0.24.1 (Oct 2 2017)
2
30
 
3
31
  * Fix the markdown spacing for maintainer/source/issues URL. Submitted by Jamie Tanna.
@@ -1,19 +1,34 @@
1
1
  # How to Contribute
2
2
 
3
- Pull requests are greatly appreciated and are what makes opensource great. Here's a quick guide:
3
+ We'd love to accept your patches and contributions to this project. Pull requests are part of
4
+ what makes open source great. There are just a few small guidelines you need to follow.
4
5
 
5
- * Fork it
6
- * Create your feature branch (`git checkout -b my-new-feature`)
7
- * Commit your changes (`git commit -am 'Add some feature'`)
8
- * Push to the branch (`git push origin my-new-feature`)
9
- * Create new Pull Request
6
+ ## Code of Conduct
10
7
 
11
- Pester us if we don't get your Pull Requests merged in a timely fashion. :)
8
+ Participation in this project comes under the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md)
9
+
10
+ ## Submitting code via Pull Requests
11
+
12
+ - We follow the [Github Pull Request Model](https://help.github.com/articles/about-pull-requests/) for
13
+ all contributions.
14
+ - For large bodies of work, we recommend creating an issue outlining the feature that you wish to build,
15
+ and describing how it will be implemented. This gives a chance for review to happen early, and ensures
16
+ no wasted effort occurs.
17
+ - All submissions, will require review before being merged.
18
+ - Finally - *Thanks* for considering submitting code to the project!
19
+
20
+ ## Formatting
21
+
22
+ When submitting pull requests, make sure to do the following:
23
+
24
+ - Maintain the same code style as the rest of the project.
25
+ - Remove trailing whitespace. Many editors will do this automatically.
26
+ - Ensure any new files have [a trailing newline](https://stackoverflow.com/questions/5813311/no-newline-at-end-of-file)
12
27
 
13
28
  ## How to speed the merging of pull requests
14
29
 
15
- * Describe your changes in the CHANGELOG.
16
- * Give yourself some credit in the appropriate place (usually the CHANGELOG).
30
+ * Describe your changes in the CHANGELOG.md (if present).
31
+ * Give yourself some credit in the appropriate place (usually the CHANGELOG.md).
17
32
  * Make commits of logical units.
18
33
  * Ensure your commit messages help others understand what you are doing and why.
19
34
  * Check for unnecessary whitespace with `git diff --check` before committing.
@@ -23,4 +38,6 @@ Pester us if we don't get your Pull Requests merged in a timely fashion. :)
23
38
  ## Additional Resources
24
39
 
25
40
  * [General GitHub documentation](http://help.github.com/)
26
- * [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
41
+ * [How to write a good Git Commit message](https://chris.beams.io/posts/git-commit/) -
42
+ Great way to make sure your Pull Requests get accepted.
43
+ * [An Open Source Etiquette Guidebook](https://css-tricks.com/open-source-etiquette-guidebook/#article-header-id-1)
data/Rakefile CHANGED
@@ -4,3 +4,12 @@ require 'rake/clean'
4
4
  task :default => :build
5
5
 
6
6
  CLEAN.include 'pkg'
7
+
8
+ task :test => :install
9
+ task :test do
10
+ sh <<SCRIPT
11
+ cd fixture
12
+ knife cookbook doc . -o README-generated.md -c knife.rb
13
+ diff -u README-expected.md README-generated.md && rm README-generated.md
14
+ SCRIPT
15
+ end
@@ -6,6 +6,11 @@
6
6
 
7
7
  # Requirements
8
8
 
9
+
10
+ ## Chef Client:
11
+
12
+ *No Chef versions defined*
13
+
9
14
  ## Platform:
10
15
 
11
16
  * cookbook-authors
@@ -45,6 +50,11 @@ This resource is awesome.
45
50
  - my_attribute: This is an attribute. Defaults to <code>"a default value"</code>.
46
51
  - my_property: This is a property. Defaults to <code>"another default value"</code>.
47
52
 
53
+ # Libraries
54
+
55
+ ## stooges()
56
+ Returns `['Moe', 'Larry', 'Curly']`
57
+
48
58
  # Credits
49
59
 
50
60
  * Mathias Lafeldt
@@ -0,0 +1,7 @@
1
+ # <
2
+ # ## stooges()
3
+ # Returns `['Moe', 'Larry', 'Curly']`
4
+ # >
5
+ def stooges
6
+ %w(Moe Larry Curly)
7
+ end
@@ -12,6 +12,17 @@
12
12
  <%= fragments['requirements'] -%>
13
13
 
14
14
  <% end -%>
15
+
16
+ ## Chef Client:
17
+
18
+ <% unless chef_versions.empty? %>
19
+ <% chef_versions.each do |chef_version| %>
20
+ * <%= chef_version %>
21
+ <% end %>
22
+ <% else %>
23
+ *No Chef versions defined*
24
+ <% end %>
25
+
15
26
  ## Platform:
16
27
 
17
28
  <% unless platforms.empty? %>
@@ -136,7 +147,7 @@
136
147
  ### Attribute Parameters
137
148
 
138
149
  <% resource.attributes.each do |attribute| -%>
139
- - <%= attribute %>: <%= resource.attribute_description(attribute) %><% if resource.attribute_has_default_value?(attribute) %> Defaults to <code><%= resource.attribute_default_value(attribute).inspect %></code>.<% end %>
150
+ - <%= attribute %>: <%= resource.attribute_description(attribute) %><% if resource.attribute_has_default_value?(attribute) %> Defaults to <code><%= resource.attribute_default_value(attribute) %></code>.<% end %>
140
151
  <% end -%>
141
152
  <% end -%>
142
153
  <% resource.top_level_descriptions.keys.select{|k| k != 'main'}.each do |key| -%>
@@ -146,6 +157,13 @@
146
157
  <%= resource.top_level_description(key) -%>
147
158
  <% end -%>
148
159
 
160
+ <% end -%>
161
+ <% end -%>
162
+ <% unless libraries.empty? -%>
163
+ # Libraries
164
+ <% libraries.each do |lib| -%>
165
+
166
+ <%= lib.descriptions %>
149
167
  <% end -%>
150
168
  <% end -%>
151
169
  <% fragments.keys.select {|k|k != 'overview' && k != 'credit' && k != 'requirements'}.each do |key| -%>
@@ -9,6 +9,7 @@ module KnifeCookbookDoc
9
9
  require 'knife_cookbook_doc/base_model'
10
10
  require 'knife_cookbook_doc/documenting_lwrp_base'
11
11
  require 'knife_cookbook_doc/definitions_model'
12
+ require 'knife_cookbook_doc/libraries_model'
12
13
  require 'knife_cookbook_doc/readme_model'
13
14
  require 'knife_cookbook_doc/recipe_model'
14
15
  require 'knife_cookbook_doc/resource_model'
@@ -0,0 +1,13 @@
1
+ module KnifeCookbookDoc
2
+ class LibrariesModel
3
+ include KnifeCookbookDoc::BaseModel
4
+
5
+ attr_reader :descriptions
6
+
7
+ def initialize(name, filename)
8
+ @name = name
9
+ @filename = filename
10
+ @descriptions = extract_description
11
+ end
12
+ end
13
+ end
@@ -6,6 +6,7 @@ require 'rake/tasklib'
6
6
  require 'knife_cookbook_doc/base_model'
7
7
  require 'knife_cookbook_doc/documenting_lwrp_base'
8
8
  require 'knife_cookbook_doc/definitions_model'
9
+ require 'knife_cookbook_doc/libraries_model'
9
10
  require 'knife_cookbook_doc/readme_model'
10
11
  require 'knife_cookbook_doc/recipe_model'
11
12
  require 'knife_cookbook_doc/resource_model'
@@ -1,13 +1,21 @@
1
+ begin
2
+ require 'berkshelf'
3
+ rescue LoadError
4
+ # won't be able to get :source_url for dependent cookbooks
5
+ end
6
+
1
7
  module KnifeCookbookDoc
2
8
  class ReadmeModel
3
9
  DEFAULT_CONSTRAINT = ">= 0.0.0".freeze
4
10
 
11
+ attr_reader :libraries
12
+
5
13
  def initialize(cookbook_dir, config)
6
14
 
7
15
  @metadata = Chef::Cookbook::Metadata.new
8
16
  @metadata.from_file("#{cookbook_dir}/metadata.rb")
9
17
 
10
- if !@metadata.attributes.empty?
18
+ if (!@metadata.attributes.empty? rescue false)
11
19
  @attributes = @metadata.attributes.map do |attr, options|
12
20
  name = "node['#{attr.gsub("/", "']['")}']"
13
21
  [name, options['description'], options['default'], options['choice']]
@@ -22,6 +30,10 @@ module KnifeCookbookDoc
22
30
  end
23
31
  end
24
32
 
33
+ @libraries = Dir["#{cookbook_dir}/libraries/*.rb"].sort.map do |path|
34
+ LibrariesModel.new(@metadata.name, path)
35
+ end
36
+
25
37
  @resources = []
26
38
  Dir["#{cookbook_dir}/resources/*.rb"].sort.each do |resource_filename|
27
39
  @resources << ResourceModel.new(@metadata.name, resource_filename)
@@ -96,6 +108,16 @@ module KnifeCookbookDoc
96
108
  end
97
109
  end
98
110
 
111
+ def chef_versions
112
+ if @metadata.methods.include?(:chef_version)
113
+ @metadata.chef_versions.map do |chef_version, version|
114
+ format_constraint(chef_version, version)
115
+ end
116
+ else
117
+ []
118
+ end
119
+ end
120
+
99
121
  def dependencies
100
122
  @metadata.dependencies.map do |cookbook, version|
101
123
  format_constraint(cookbook, version)
@@ -162,7 +184,28 @@ module KnifeCookbookDoc
162
184
 
163
185
  private
164
186
 
187
+ def source_url_from_berkshelf(name)
188
+ @source_url ||= begin
189
+ if File.exist?('Berksfile') && defined?(::Berkshelf)
190
+ ::Berkshelf::Berksfile
191
+ .from_file('Berksfile')
192
+ .install
193
+ .map { |cb| [cb.cookbook_name, cb.metadata.source_url] }
194
+ .to_h
195
+ else
196
+ {}
197
+ end
198
+ end
199
+ @source_url[name]
200
+ end
201
+
165
202
  def format_constraint(name, version)
203
+ url = source_url_from_berkshelf(name)
204
+ if !url.nil? && url.start_with?('http')
205
+ # git:// and ssh:// URLs are not browsable
206
+ name = "[#{name}](#{url})"
207
+ end
208
+
166
209
  if @constraints && version != DEFAULT_CONSTRAINT
167
210
  "#{name} (#{version})"
168
211
  else
@@ -52,14 +52,18 @@ module KnifeCookbookDoc
52
52
 
53
53
  def attribute_has_default_value?(attribute)
54
54
  specification = @native_resource.attribute_specifications[attribute]
55
- specification && specification.has_key?(:default)
55
+ specification && specification.key?(:default)
56
56
  end
57
57
 
58
58
  def attribute_default_value(attribute)
59
- if attribute_has_default_value?(attribute)
60
- return @native_resource.attribute_specifications[attribute][:default]
59
+ default = if attribute_has_default_value?(attribute)
60
+ @native_resource.attribute_specifications[attribute][:default]
61
+ end
62
+
63
+ if default.is_a?(Chef::DelayedEvaluator)
64
+ 'lazy { ... }'
61
65
  else
62
- return nil
66
+ default.inspect
63
67
  end
64
68
  end
65
69
 
@@ -1,3 +1,3 @@
1
1
  module KnifeCookbookDoc
2
- VERSION = '0.25.0'
2
+ VERSION = '0.29.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-cookbook-doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Lafeldt
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-03-07 00:00:00.000000000 Z
12
+ date: 2020-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -76,6 +76,7 @@ extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
78
  - ".gitattributes"
79
+ - ".github/ISSUE_TEMPLATE.md"
79
80
  - ".gitignore"
80
81
  - ".travis.yml"
81
82
  - CHANGELOG.md
@@ -93,6 +94,7 @@ files:
93
94
  - fixture/doc/overview.md
94
95
  - fixture/gemfile
95
96
  - fixture/knife.rb
97
+ - fixture/libraries/default.rb
96
98
  - fixture/metadata.rb
97
99
  - fixture/recipes/default.rb
98
100
  - fixture/resources/default.rb
@@ -103,6 +105,7 @@ files:
103
105
  - lib/knife_cookbook_doc/base_model.rb
104
106
  - lib/knife_cookbook_doc/definitions_model.rb
105
107
  - lib/knife_cookbook_doc/documenting_lwrp_base.rb
108
+ - lib/knife_cookbook_doc/libraries_model.rb
106
109
  - lib/knife_cookbook_doc/rake_task.rb
107
110
  - lib/knife_cookbook_doc/readme_model.rb
108
111
  - lib/knife_cookbook_doc/recipe_model.rb