knife-cookbook-doc 0.16.0 → 0.17.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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTdjZDI5OTM0Mjk5MTU4ZDVmMTI4NTMzOTM4MjJlMjNlYmM5ZDRiMg==
5
- data.tar.gz: !binary |-
6
- YWIyYmJiZGZlMWZlZTg3NDZkZjBkNjRkOWU4Yjg3MmE4YzUxODEyNQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NTM0YTIzODBhNmE0NGIxYjlhZDA3ZjViNzAyNDc2NGZjZWQwNjhkNTRlZThk
10
- ODg4N2EwODE3ZjRkOThkOGI1MGYzYjNjZTA0NmZlN2ZjMjFjMTIxNDA1NjE4
11
- YjQ4NTdmOGJjMGZiOTBmNjI4YmZmYmE3NDg1NDAxNTA0Y2QzNTg=
12
- data.tar.gz: !binary |-
13
- ZDA4YWVjYWEyMGU0ZmU4MjFkNGEzYTAwNGEzYTA0NDdjMmEyYWNhOWIxODdj
14
- ZjgwYmM0M2I3NjBlYmUxOGMxYmE5MDMwMWRjNmE0YTBjMzkwZjk1NWEwMTBm
15
- ZDZiMzFjOGI4MzgzZTYxNWI1N2QyM2NkMDdiOWNhN2E0NDg3ZmY=
2
+ SHA1:
3
+ metadata.gz: f864d13016b58e2852ac3ee106881e6ecc5108e6
4
+ data.tar.gz: 270a238f84aecae4ef5897b17d2aa22ab704c7ac
5
+ SHA512:
6
+ metadata.gz: 3f6838645213d246defcc7c5acb682241b5cac15a4a34ac7f01d57b72fd8cf9b179b1515009647a21b01633b401cf0e2749463939608224517a92b1a96e9f05b
7
+ data.tar.gz: 14c5eb78292fe9c27695e55ab6d96538d3ede2b3e7a44424317b0e10309d529ff5c402e42577ed09423d587c32fc9de2b8eda090d9eba25b9364943b0bc651be
@@ -10,6 +10,7 @@ rvm:
10
10
 
11
11
  env:
12
12
  - CHEF_VERSION=master
13
+ - CHEF_VERSION=12.5.1
13
14
  - CHEF_VERSION=12.4.1
14
15
  - CHEF_VERSION=12.3.0
15
16
  - CHEF_VERSION=12.2.1
@@ -1,3 +1,7 @@
1
+ # v0.17.0 (Dec 1 2015)
2
+ * Add support for Chef >= 12.5. Submitted by Ole Claussen.
3
+ * Add support for arrays of default_actions. Submitted by Ole Claussen.
4
+
1
5
  # v0.16.0 (Aug 6 2015)
2
6
 
3
7
  * Travis CI testing, and test matrix. Submitted by Mark Ayers.
data/README.md CHANGED
@@ -85,6 +85,10 @@ The other text will be added at the start of the LWRP documentation
85
85
  except if marked with `@section <heading>`, in which case it will be added
86
86
  to the end of the LWRP documentation.
87
87
 
88
+ Starting with Chef >12.5, properties will replace attributes in custom
89
+ resources. For compatibility, `@property` may be used interchangibly with
90
+ `@attribute`. Both will be handled completely identical by the plugin.
91
+
88
92
  #### Step 5
89
93
 
90
94
  In each definition add documentation like:
@@ -143,6 +147,21 @@ Afterwards, the new knife command `knife cookbook doc DIR` will be available.
143
147
  knife cookbook doc path/to/cookbook
144
148
  knife cookbook doc path/to/cookbook --template README.md.erb
145
149
 
150
+ Alternatively, you can execute cookbook doc directly from your Rakefile:
151
+
152
+ require 'knife_cookbook_doc/rake_task'
153
+
154
+ # With default options
155
+ KnifeCookbookDoc::RakeTask.new(:doc)
156
+
157
+ # Example with custom options
158
+ KnifeCookbookDoc::RakeTask.new(:doc) do |t|
159
+ t.options[:cookbook_dir] = './'
160
+ t.options[:constraints] = true
161
+ t.options[:output_file] = 'README.md'
162
+ t.options[:template_file] = "#{File.dirname(__FILE__)}/templates/README.md.erb"
163
+ end
164
+
146
165
  ## Further Details
147
166
 
148
167
  ### Documentation in comments
@@ -28,6 +28,23 @@ The recipe is awesome. It does thing 1, thing 2 and thing 3!
28
28
 
29
29
  MyApp Admin Group: The group allowed to manage MyApp.
30
30
 
31
+ # Resources
32
+
33
+ * [fixture](#fixture) - This resource is awesome.
34
+
35
+ ## fixture
36
+
37
+ This resource is awesome.
38
+
39
+ ### Actions
40
+
41
+ - stuff: Does awesome things. Default action.
42
+
43
+ ### Attribute Parameters
44
+
45
+ - my_attribute: This is an attribute. Defaults to <code>"a default value"</code>.
46
+ - my_property: This is a property. Defaults to <code>"another default value"</code>.
47
+
31
48
  # Credits
32
49
 
33
50
  * Mathias Lafeldt
@@ -0,0 +1,13 @@
1
+ #<
2
+ # This resource is awesome.
3
+ #
4
+ # @action stuff Does awesome things.
5
+ #>
6
+
7
+ default_action :stuff
8
+
9
+ #<> @attribute my_attribute This is an attribute.
10
+ attribute :my_attribute, default: 'a default value'
11
+
12
+ #<> @property my_property This is a property.
13
+ property :my_property, default: 'another default value'
@@ -120,8 +120,11 @@
120
120
  <% unless resource.actions.empty? -%>
121
121
  ### Actions
122
122
 
123
+ <% if resource.default_action.is_a?(Array) %>
124
+ - Default actions: [<%= resource.default_action.join ', ' %>]
125
+ <% end %>
123
126
  <% resource.actions.each do |action| -%>
124
- - <%= action %>: <%= resource.action_description(action) %><% if resource.default_action == action %> Default action.<% end %>
127
+ - <%= action %>: <%= resource.action_description(action) %><% if !resource.default_action.is_a?(Array) && resource.default_action == action %> Default action.<% end %>
125
128
  <% end -%>
126
129
  <% end -%>
127
130
  <% unless resource.attributes.empty? -%>
@@ -14,6 +14,12 @@ class DocumentingLWRPBase < ::Chef::Resource::LWRPBase
14
14
  def description
15
15
  @description || ""
16
16
  end
17
+
18
+ NOT_PASSED = defined?(::Chef::NOT_PASSED) ? ::Chef::NOT_PASSED : "NOT_PASSED"
19
+ def property(name, type = NOT_PASSED, **options)
20
+ attribute_specifications[name] = options
21
+ super(name, type, **options) if defined?(super)
22
+ end
17
23
  end
18
24
 
19
25
  def self.attribute(attr_name, validation_opts={})
@@ -0,0 +1,54 @@
1
+ require 'chef/cookbook/metadata'
2
+ require 'erubis'
3
+ require 'rake'
4
+ require 'rake/tasklib'
5
+
6
+ require 'knife_cookbook_doc/base_model'
7
+ require 'knife_cookbook_doc/documenting_lwrp_base'
8
+ require 'knife_cookbook_doc/definitions_model'
9
+ require 'knife_cookbook_doc/readme_model'
10
+ require 'knife_cookbook_doc/recipe_model'
11
+ require 'knife_cookbook_doc/resource_model'
12
+ require 'knife_cookbook_doc/attributes_model'
13
+
14
+ module KnifeCookbookDoc
15
+ class RakeTask < ::Rake::TaskLib
16
+ attr_accessor :name, :options
17
+
18
+ def initialize(name = :knife_cookbook_doc)
19
+ @name = name
20
+ @options = {}
21
+ yield self if block_given?
22
+ define
23
+ end
24
+
25
+ def define
26
+ desc 'Generate cookbook documentation' unless ::Rake.application.last_comment
27
+ task(name) do
28
+ merged_options = default_options.merge(options)
29
+ cookbook_dir = File.realpath(merged_options[:cookbook_dir])
30
+ model = ReadmeModel.new(cookbook_dir, merged_options[:constraints])
31
+ template = File.read(merged_options[:template_file])
32
+ eruby = Erubis::Eruby.new(template)
33
+ result = eruby.result(model.get_binding)
34
+
35
+ File.open("#{cookbook_dir}/#{merged_options[:output_file]}", 'wb') do |f|
36
+ result.each_line do |line|
37
+ f.write line.gsub(/[ \t\r\n]*$/,'')
38
+ f.write "\n"
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ private
45
+ def default_options
46
+ {
47
+ cookbook_dir: './',
48
+ constraints: true,
49
+ output_file: 'README.md',
50
+ template_file: Pathname.new("#{File.dirname(__FILE__)}/../chef/knife/README.md.erb").realpath
51
+ }
52
+ end
53
+ end
54
+ end
@@ -13,16 +13,25 @@ module KnifeCookbookDoc
13
13
  @native_resource.resource_name
14
14
  end
15
15
 
16
- # Return the unique set of actions, with the default one first, if there is a default
16
+ # Return the unique set of actions, with the default one first, if there is a single default
17
+ # The :nothing action will show up only if it is the only one, or it is explicitly documented
17
18
  def actions
18
- unless @actions
19
+ return @actions unless @actions.nil?
20
+
21
+ if default_action.is_a?(Array)
22
+ @actions = @native_resource.actions
23
+ else
19
24
  @actions = [default_action].compact + @native_resource.actions.sort.uniq.select { |a| a != default_action }
20
25
  end
26
+
27
+ @actions.delete(:nothing) if @actions != [:nothing] && action_descriptions[:nothing].nil?
21
28
  @actions
22
29
  end
23
30
 
24
31
  def default_action
25
- @native_resource.default_action
32
+ action = @native_resource.default_action
33
+ return action.first if action.is_a?(Array) && action.length == 1
34
+ action
26
35
  end
27
36
 
28
37
  def action_description(action)
@@ -65,7 +74,7 @@ module KnifeCookbookDoc
65
74
  @native_resource.description.each_line do |line|
66
75
  if /^ *\@action *([^ ]*) (.*)$/ =~ line
67
76
  action_descriptions[$1] = $2.strip
68
- elsif /^ *\@attribute *([^ ]*) (.*)$/ =~ line
77
+ elsif /^ *(?:\@attribute|\@property) *([^ ]*) (.*)$/ =~ line
69
78
  attribute_descriptions[$1] = $2.strip
70
79
  elsif /^ *\@section (.*)$/ =~ line
71
80
  current_section = $1.strip
@@ -1,3 +1,3 @@
1
1
  module KnifeCookbookDoc
2
- VERSION = '0.16.0'
2
+ VERSION = '0.17.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.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Lafeldt
@@ -9,62 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-06 00:00:00.000000000 Z
12
+ date: 2015-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: erubis
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ! '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ! '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ! '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ! '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ! '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ! '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  description: Knife plugin to generate README.md for a cookbook
@@ -75,8 +75,8 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - .gitignore
79
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
80
  - CHANGELOG.md
81
81
  - CONTRIBUTING.md
82
82
  - Gemfile
@@ -93,6 +93,7 @@ files:
93
93
  - fixture/knife.rb
94
94
  - fixture/metadata.rb
95
95
  - fixture/recipes/default.rb
96
+ - fixture/resources/default.rb
96
97
  - knife_cookbook_doc.gemspec
97
98
  - lib/chef/knife/README.md.erb
98
99
  - lib/chef/knife/cookbook_doc.rb
@@ -100,6 +101,7 @@ files:
100
101
  - lib/knife_cookbook_doc/base_model.rb
101
102
  - lib/knife_cookbook_doc/definitions_model.rb
102
103
  - lib/knife_cookbook_doc/documenting_lwrp_base.rb
104
+ - lib/knife_cookbook_doc/rake_task.rb
103
105
  - lib/knife_cookbook_doc/readme_model.rb
104
106
  - lib/knife_cookbook_doc/recipe_model.rb
105
107
  - lib/knife_cookbook_doc/resource_model.rb
@@ -116,21 +118,20 @@ require_paths:
116
118
  - lib
117
119
  required_ruby_version: !ruby/object:Gem::Requirement
118
120
  requirements:
119
- - - ! '>='
121
+ - - ">="
120
122
  - !ruby/object:Gem::Version
121
123
  version: '0'
122
124
  required_rubygems_version: !ruby/object:Gem::Requirement
123
125
  requirements:
124
- - - ! '>='
126
+ - - ">="
125
127
  - !ruby/object:Gem::Version
126
128
  version: '0'
127
129
  requirements: []
128
130
  rubyforge_project:
129
- rubygems_version: 2.0.3
131
+ rubygems_version: 2.2.2
130
132
  signing_key:
131
133
  specification_version: 4
132
134
  summary: Knife plugin to generate README.md for a cookbook
133
135
  test_files:
134
136
  - spec/knife_cookbook_doc/attribute_model_spec.rb
135
137
  - spec/spec_helper.rb
136
- has_rdoc: