knife-cookbook-doc 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.md +22 -0
- data/lib/chef/knife/README.md.erb +29 -0
- data/lib/chef/knife/cookbook_doc.rb +18 -12
- data/lib/knife_cookbook_doc/base_model.rb +44 -0
- data/lib/knife_cookbook_doc/definitions_model.rb +51 -0
- data/lib/knife_cookbook_doc/readme_model.rb +9 -0
- data/lib/knife_cookbook_doc/recipe_model.rb +1 -30
- data/lib/knife_cookbook_doc/resource_model.rb +1 -24
- data/lib/knife_cookbook_doc/version.rb +1 -1
- metadata +15 -6
- checksums.yaml +0 -15
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -80,6 +80,28 @@ to the end of the LWRP documentation.
|
|
80
80
|
|
81
81
|
#### Step 4
|
82
82
|
|
83
|
+
In each definition add documentation like:
|
84
|
+
|
85
|
+
=begin
|
86
|
+
#<
|
87
|
+
This definition does something useful.
|
88
|
+
|
89
|
+
@param user User to run as.
|
90
|
+
@param group User group to run as.
|
91
|
+
|
92
|
+
@section Examples
|
93
|
+
|
94
|
+
# An example of my awesome service
|
95
|
+
mycookbook_awesome_definition "app resources" do
|
96
|
+
user 'appuser'
|
97
|
+
group 'appgroup'
|
98
|
+
end
|
99
|
+
#>
|
100
|
+
=end
|
101
|
+
|
102
|
+
|
103
|
+
#### Step 5
|
104
|
+
|
83
105
|
Finally the user should add some documentation fragments into the `doc/` dir.
|
84
106
|
Most importantly you should add `doc/overview.md` which will replace the first
|
85
107
|
`Description` section of the readme. You should also add a `doc/credit.md` which
|
@@ -73,6 +73,35 @@
|
|
73
73
|
<% else -%>
|
74
74
|
*No recipes defined*
|
75
75
|
|
76
|
+
<% end -%>
|
77
|
+
<% unless definitions.empty? -%>
|
78
|
+
# Definitions
|
79
|
+
|
80
|
+
<% definitions.each do |definition| -%>
|
81
|
+
* [<%= definition.name %>](#<%= definition.name %>)<% if definition.short_description %> - <%= definition.short_description %><% end %>
|
82
|
+
<% end -%>
|
83
|
+
|
84
|
+
<% definitions.each do |definition| -%>
|
85
|
+
## <%= definition.name %>
|
86
|
+
|
87
|
+
<% if definition.top_level_description('main') != '' -%>
|
88
|
+
<%= definition.top_level_description('main') -%>
|
89
|
+
<% end -%>
|
90
|
+
|
91
|
+
<% unless definition.params.empty? -%>
|
92
|
+
### Parameters
|
93
|
+
|
94
|
+
<% definition.params.each do |param, data| -%>
|
95
|
+
- <%= param %>: <%= data['descr'] %>.<% if data['default']%> Defaults to: <%=data['default']%><%end%>
|
96
|
+
<% end -%>
|
97
|
+
<% end -%>
|
98
|
+
<% definition.top_level_descriptions.keys.select{|k| k != 'main'}.each do |key| -%>
|
99
|
+
|
100
|
+
### <%= key -%>
|
101
|
+
|
102
|
+
<%= definition.top_level_description(key) -%>
|
103
|
+
<% end -%>
|
104
|
+
<% end -%>
|
76
105
|
<% end -%>
|
77
106
|
<% unless resources.empty? -%>
|
78
107
|
# Resources
|
@@ -6,6 +6,9 @@ module KnifeCookbookDoc
|
|
6
6
|
deps do
|
7
7
|
require 'chef/cookbook/metadata'
|
8
8
|
require 'erubis'
|
9
|
+
require 'knife_cookbook_doc/base_model'
|
10
|
+
require 'knife_cookbook_doc/documenting_lwrp_base'
|
11
|
+
require 'knife_cookbook_doc/definitions_model'
|
9
12
|
require 'knife_cookbook_doc/readme_model'
|
10
13
|
require 'knife_cookbook_doc/recipe_model'
|
11
14
|
require 'knife_cookbook_doc/resource_model'
|
@@ -15,22 +18,22 @@ module KnifeCookbookDoc
|
|
15
18
|
banner 'knife cookbook doc DIR (options)'
|
16
19
|
|
17
20
|
option :constraints,
|
18
|
-
:short
|
19
|
-
:long
|
20
|
-
:boolean
|
21
|
-
:default
|
21
|
+
:short => '-c',
|
22
|
+
:long => '--constraints',
|
23
|
+
:boolean => true,
|
24
|
+
:default => true,
|
22
25
|
:description => 'Include version constraints for platforms and dependencies'
|
23
26
|
|
24
27
|
option :output_file,
|
25
|
-
:short
|
26
|
-
:long
|
27
|
-
:default
|
28
|
+
:short => '-o',
|
29
|
+
:long => '--output-file FILE',
|
30
|
+
:default => 'README.md',
|
28
31
|
:description => 'Set the output file to render to relative to cookbook dir. Defaults to README.md'
|
29
32
|
|
30
33
|
option :template_file,
|
31
|
-
:short
|
32
|
-
:long
|
33
|
-
:default
|
34
|
+
:short => '-t',
|
35
|
+
:long => '--template FILE',
|
36
|
+
:default => Pathname.new("#{File.dirname(__FILE__)}/README.md.erb").realpath,
|
34
37
|
:description => 'Set template file used to render README.md'
|
35
38
|
|
36
39
|
def run
|
@@ -47,8 +50,11 @@ module KnifeCookbookDoc
|
|
47
50
|
eruby = Erubis::Eruby.new(template)
|
48
51
|
result = eruby.result(model.get_binding)
|
49
52
|
|
50
|
-
File.open("#{cookbook_dir}/#{config[:output_file]}",'wb') do |f|
|
51
|
-
|
53
|
+
File.open("#{cookbook_dir}/#{config[:output_file]}", 'wb') do |f|
|
54
|
+
result.each_line do |line|
|
55
|
+
f.write line.gsub(/[ \t\r\n]*$/,'')
|
56
|
+
f.write "\n"
|
57
|
+
end
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module KnifeCookbookDoc
|
2
|
+
module BaseModel
|
3
|
+
|
4
|
+
def top_level_description(section)
|
5
|
+
(top_level_descriptions[section.to_s] || []).join("\n").gsub(/\n+$/m,"\n")
|
6
|
+
end
|
7
|
+
|
8
|
+
def top_level_descriptions
|
9
|
+
@top_level_descriptions ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def short_description
|
13
|
+
unless @short_description
|
14
|
+
@short_description = first_sentence(top_level_description('main'))
|
15
|
+
end
|
16
|
+
@short_description
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def first_sentence(string)
|
22
|
+
string.gsub(/^(.*?\.(\z|\s))/m) do |match|
|
23
|
+
return $1.gsub("\n",' ').strip
|
24
|
+
end
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def extract_description
|
29
|
+
description = []
|
30
|
+
IO.read(@filename).gsub(/^=begin *\n *\#\<\n(.*?)^ *\#\>\n=end *\n/m) do
|
31
|
+
description << $1
|
32
|
+
""
|
33
|
+
end.gsub(/^ *\#\<\n(.*?)^ *\#\>\n/m) do
|
34
|
+
description << $1.gsub(/^ *\# ?/, '')
|
35
|
+
""
|
36
|
+
end.gsub(/^ *\#\<\> (.*?)$/) do
|
37
|
+
description << $1
|
38
|
+
""
|
39
|
+
end
|
40
|
+
description.join("\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module KnifeCookbookDoc
|
2
|
+
class DefinitionsModel
|
3
|
+
include KnifeCookbookDoc::BaseModel
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(name, filename)
|
7
|
+
@name = name
|
8
|
+
@filename = filename
|
9
|
+
load_descriptions
|
10
|
+
end
|
11
|
+
|
12
|
+
def params
|
13
|
+
@params ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def load_descriptions
|
19
|
+
description = extract_description
|
20
|
+
current_section = 'main'
|
21
|
+
description.each_line do |line|
|
22
|
+
if /^ *\@param *([^ ]*) (.*)$/ =~ line
|
23
|
+
params[$1] = {}
|
24
|
+
params[$1]['descr'] = $2.strip
|
25
|
+
elsif /^ *\@section (.*)$/ =~ line
|
26
|
+
current_section = $1.strip
|
27
|
+
else
|
28
|
+
lines = (top_level_descriptions[current_section] || [])
|
29
|
+
lines << line.gsub("\n", '')
|
30
|
+
top_level_descriptions[current_section] = lines
|
31
|
+
end
|
32
|
+
end
|
33
|
+
load_properties
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_properties
|
37
|
+
code = IO.read(@filename)
|
38
|
+
code.gsub(/^ *define (.*?) (?=do)/m) do
|
39
|
+
all = $1.split(' ', 2)
|
40
|
+
@name = all.shift.gsub(/:/, '')
|
41
|
+
next if all.empty?
|
42
|
+
all = eval("{#{all.last}}") rescue {}
|
43
|
+
all.each do |k, v|
|
44
|
+
p_name = k.to_s
|
45
|
+
params[p_name] ||= {}
|
46
|
+
params[p_name]['default'] = v ? v : 'nil'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -27,6 +27,11 @@ module KnifeCookbookDoc
|
|
27
27
|
@resources << ResourceModel.new(@metadata.name, resource_filename)
|
28
28
|
end
|
29
29
|
|
30
|
+
@definitions = []
|
31
|
+
Dir["#{cookbook_dir}/definitions/*.rb"].sort.each do |def_filename|
|
32
|
+
@definitions << DefinitionsModel.new(File.basename(def_filename, '.*'), def_filename)
|
33
|
+
end
|
34
|
+
|
30
35
|
@fragments = {}
|
31
36
|
Dir["#{cookbook_dir}/doc/*.md"].sort.each do |resource_filename|
|
32
37
|
@fragments[::File.basename(resource_filename,'.md')] = IO.read(resource_filename)
|
@@ -57,6 +62,10 @@ module KnifeCookbookDoc
|
|
57
62
|
@resources
|
58
63
|
end
|
59
64
|
|
65
|
+
def definitions
|
66
|
+
@definitions
|
67
|
+
end
|
68
|
+
|
60
69
|
def description
|
61
70
|
@metadata.description
|
62
71
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module KnifeCookbookDoc
|
2
2
|
class RecipeModel
|
3
|
+
include KnifeCookbookDoc::BaseModel
|
3
4
|
|
4
5
|
attr_reader :name
|
5
6
|
attr_reader :short_description
|
@@ -11,14 +12,6 @@ module KnifeCookbookDoc
|
|
11
12
|
load_descriptions
|
12
13
|
end
|
13
14
|
|
14
|
-
def top_level_description(section)
|
15
|
-
(top_level_descriptions[section.to_s] || []).join("\n").gsub(/\n+$/m,"\n")
|
16
|
-
end
|
17
|
-
|
18
|
-
def top_level_descriptions
|
19
|
-
@top_level_descriptions ||= {}
|
20
|
-
end
|
21
|
-
|
22
15
|
private
|
23
16
|
|
24
17
|
def load_descriptions
|
@@ -39,27 +32,5 @@ module KnifeCookbookDoc
|
|
39
32
|
end
|
40
33
|
|
41
34
|
include ::Chef::Mixin::ConvertToClassName
|
42
|
-
|
43
|
-
def extract_description
|
44
|
-
description = []
|
45
|
-
IO.read(@filename).gsub(/^=begin *\n *\#\<\n(.*?)^ *\#\>\n=end *\n/m) do
|
46
|
-
description << $1
|
47
|
-
""
|
48
|
-
end.gsub(/^ *\#\<\n(.*?)^ *\#\>\n/m) do
|
49
|
-
description << $1.gsub(/^ *\# ?/, '')
|
50
|
-
""
|
51
|
-
end.gsub(/^ *\#\<\> (.*?)$/) do
|
52
|
-
description << $1
|
53
|
-
""
|
54
|
-
end
|
55
|
-
description.join("\n")
|
56
|
-
end
|
57
|
-
|
58
|
-
def first_sentence(string)
|
59
|
-
string.gsub(/^(.*?\.(\z|\s))/m) do |match|
|
60
|
-
return $1.gsub("\n",' ').strip
|
61
|
-
end
|
62
|
-
return nil
|
63
|
-
end
|
64
35
|
end
|
65
36
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require 'knife_cookbook_doc/documenting_lwrp_base'
|
2
|
-
|
3
1
|
module KnifeCookbookDoc
|
4
2
|
class ResourceModel
|
3
|
+
include KnifeCookbookDoc::BaseModel
|
5
4
|
|
6
5
|
attr_reader :native_resource
|
7
6
|
|
@@ -59,28 +58,6 @@ module KnifeCookbookDoc
|
|
59
58
|
@attribute_descriptions ||= {}
|
60
59
|
end
|
61
60
|
|
62
|
-
def short_description
|
63
|
-
unless @short_description
|
64
|
-
@short_description = first_sentence(top_level_description('main'))
|
65
|
-
end
|
66
|
-
@short_description
|
67
|
-
end
|
68
|
-
|
69
|
-
def first_sentence(string)
|
70
|
-
string.gsub(/^(.*?\.(\z|\s))/m) do |match|
|
71
|
-
return $1.gsub("\n",' ').strip
|
72
|
-
end
|
73
|
-
return nil
|
74
|
-
end
|
75
|
-
|
76
|
-
def top_level_description(section)
|
77
|
-
(top_level_descriptions[section.to_s] || []).join("\n").gsub(/\n+$/m,"\n")
|
78
|
-
end
|
79
|
-
|
80
|
-
def top_level_descriptions
|
81
|
-
@top_level_descriptions ||= {}
|
82
|
-
end
|
83
|
-
|
84
61
|
private
|
85
62
|
|
86
63
|
def load_descriptions
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-cookbook-doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Mathias Lafeldt
|
@@ -9,11 +10,12 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-02
|
13
|
+
date: 2014-03-02 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: chef
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
20
|
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
@@ -21,6 +23,7 @@ dependencies:
|
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
28
|
- - ! '>='
|
26
29
|
- !ruby/object:Gem::Version
|
@@ -28,6 +31,7 @@ dependencies:
|
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: erubis
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
36
|
- - ! '>='
|
33
37
|
- !ruby/object:Gem::Version
|
@@ -35,6 +39,7 @@ dependencies:
|
|
35
39
|
type: :runtime
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
44
|
- - ! '>='
|
40
45
|
- !ruby/object:Gem::Version
|
@@ -42,6 +47,7 @@ dependencies:
|
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: rake
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
52
|
- - ! '>='
|
47
53
|
- !ruby/object:Gem::Version
|
@@ -49,6 +55,7 @@ dependencies:
|
|
49
55
|
type: :development
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
60
|
- - ! '>='
|
54
61
|
- !ruby/object:Gem::Version
|
@@ -72,6 +79,8 @@ files:
|
|
72
79
|
- lib/chef/knife/README.md.erb
|
73
80
|
- lib/chef/knife/cookbook_doc.rb
|
74
81
|
- lib/knife_cookbook_doc/attributes_model.rb
|
82
|
+
- lib/knife_cookbook_doc/base_model.rb
|
83
|
+
- lib/knife_cookbook_doc/definitions_model.rb
|
75
84
|
- lib/knife_cookbook_doc/documenting_lwrp_base.rb
|
76
85
|
- lib/knife_cookbook_doc/readme_model.rb
|
77
86
|
- lib/knife_cookbook_doc/recipe_model.rb
|
@@ -80,26 +89,26 @@ files:
|
|
80
89
|
homepage: http://realityforge.github.com/knife-cookbook-doc
|
81
90
|
licenses:
|
82
91
|
- Apache 2.0
|
83
|
-
metadata: {}
|
84
92
|
post_install_message:
|
85
93
|
rdoc_options: []
|
86
94
|
require_paths:
|
87
95
|
- lib
|
88
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
89
98
|
requirements:
|
90
99
|
- - ! '>='
|
91
100
|
- !ruby/object:Gem::Version
|
92
101
|
version: '0'
|
93
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
94
104
|
requirements:
|
95
105
|
- - ! '>='
|
96
106
|
- !ruby/object:Gem::Version
|
97
107
|
version: '0'
|
98
108
|
requirements: []
|
99
109
|
rubyforge_project:
|
100
|
-
rubygems_version:
|
110
|
+
rubygems_version: 1.8.23
|
101
111
|
signing_key:
|
102
|
-
specification_version:
|
112
|
+
specification_version: 3
|
103
113
|
summary: Knife plugin to generate README.md for a cookbook
|
104
114
|
test_files: []
|
105
|
-
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
ODE3YjMyNTVmN2UzYWY3ZDVkMjE4Y2U3ZTk2MjZiZjM1MjlmZmRmMg==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
N2NjZDhlZmVhM2M0M2Q2MzNlNDExNThjYTY0ZGQ5Nzk3M2E2OTI0Yw==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ODQwNWE3OTY5YmFmY2YyOWJhYzgyNjQ3ZmViMGZkZjAxN2E2ZDllMDEyMGQy
|
10
|
-
MmYzZDZkNmIzMzQ0Y2NmNGNhMTkyNzNiNWY4OGFlNGQ4ZTlhNmJjZGFiMmU2
|
11
|
-
NWIwN2VmZTRjZDkyNGVlZTNhNDhhMjJiMTdmNjUxMzFjMmZkZTE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MTc3MWFhOGM0NDM2NTQ3NjFjMDc4MjU2M2Q2ZTExZDllOTMyYzc5Y2FjY2Q5
|
14
|
-
NWNkNzAyOGRlNWVhN2ZmZTBhZmQ4YTJlYmM2YTVlODA3MWVhZTlmNjg1NGY2
|
15
|
-
NjkyOWZlZDZmMTI3MjFhYmNkYjNmMGE1MTc2NDdjYWU1N2ZlM2I=
|