knife-cookbook-doc 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +17 -0
- data/README.md +7 -4
- data/lib/chef/knife/README.md.erb +2 -2
- data/lib/chef/knife/cookbook_doc.rb +1 -0
- data/lib/knife_cookbook_doc/attributes_model.rb +64 -0
- data/lib/knife_cookbook_doc/readme_model.rb +27 -6
- data/lib/knife_cookbook_doc/recipe_model.rb +13 -2
- data/lib/knife_cookbook_doc/resource_model.rb +1 -1
- data/lib/knife_cookbook_doc/version.rb +1 -1
- metadata +3 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
v0.5.0 (Sep 16 2013)
|
2
|
+
--------------------
|
3
|
+
|
4
|
+
* Re-push gem with correct set of changes to rubygems.
|
5
|
+
|
6
|
+
v0.4.0 (Sep 16 2013)
|
7
|
+
--------------------
|
8
|
+
|
9
|
+
* Scan the recipes directory for recipes if no recipes are declared in the metadata.rb (Skipping recipes with a name starting with '_'). Submitted by Jarek Gawor.
|
10
|
+
* Scan the attributes files if no attributes are declared in the metadata.rb and collect descriptions from comments. Submitted by Jarek Gawor.
|
11
|
+
* Descriptions scanned from source files should expect the . separator to be followed by a space. Submitted by Jarek Gawor.
|
12
|
+
|
13
|
+
v0.3.0 (Apr 1 2013)
|
14
|
+
--------------------
|
15
|
+
|
16
|
+
* Replace the last section of the readme with the doc/credit.md fragment if it is present.
|
17
|
+
|
1
18
|
v0.2.0 (Apr 1 2013)
|
2
19
|
--------------------
|
3
20
|
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ compatibility and cookbook requirements (i.e. depends, recommends, suggests etc)
|
|
21
21
|
|
22
22
|
#### Step 2
|
23
23
|
|
24
|
-
At the top of each
|
24
|
+
At the top of each recipe, add a detailed documentation section such as;
|
25
25
|
|
26
26
|
=begin
|
27
27
|
#<
|
@@ -67,8 +67,10 @@ to the end of the LWRP documentation.
|
|
67
67
|
|
68
68
|
Finally the user should add some documentation fragments into the `doc/` dir.
|
69
69
|
Most importantly you should add `doc/overview.md` which will replace the first
|
70
|
-
`Description` section of the readme.
|
71
|
-
|
70
|
+
`Description` section of the readme. You should also add a `doc/credit.md` which
|
71
|
+
will replace the last 'License and Maintainer' section in the readme. The
|
72
|
+
remaining fragments will be included at the end of the readme in lexicographic
|
73
|
+
order of the filename.
|
72
74
|
|
73
75
|
## Installation
|
74
76
|
|
@@ -127,4 +129,5 @@ The documentation stored in comments comes in three forms;
|
|
127
129
|
The plugin was originally written by Mathias Lafeldt as a way to create
|
128
130
|
initial README.md from the metadata.rb. It was subsequently rewritten by
|
129
131
|
Peter Donald to gather information from the other files within the cookbook.
|
130
|
-
All credit to Mathias for his wonderful idea.
|
132
|
+
All credit to Mathias for his wonderful idea. Jarek Gawor has also submitted
|
133
|
+
several major changes.
|
@@ -40,8 +40,8 @@
|
|
40
40
|
# Attributes
|
41
41
|
|
42
42
|
<% unless attributes.empty? %>
|
43
|
-
<% attributes.each do |name, description, default| %>
|
44
|
-
* `<%= name %>` - <%= description %>. Defaults to `<%= default %>`.
|
43
|
+
<% attributes.each do |name, description, default, choice| %>
|
44
|
+
* `<%= name %>` - <%= description %><% if !description.nil? && !description.strip.end_with?(".") %>.<% end %> <% unless choice.empty? %>Available options: <%= "`#{choice.join('`, `')}`" %>. <% end %>Defaults to `<%= default %>`.
|
45
45
|
<% end %>
|
46
46
|
<% else %>
|
47
47
|
*No attributes defined*
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module KnifeCookbookDoc
|
2
|
+
class AttributesModel
|
3
|
+
|
4
|
+
ATTRIBUTE_REGEX = "(^\s*default.*?)=(.*?)$".freeze
|
5
|
+
|
6
|
+
def initialize(filename)
|
7
|
+
@filename = filename
|
8
|
+
@attributes = {}
|
9
|
+
load_descriptions
|
10
|
+
end
|
11
|
+
|
12
|
+
def attributes
|
13
|
+
@attributes.map do |name, options|
|
14
|
+
[name, options[:description], options[:default], []]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def load_descriptions
|
21
|
+
resource_data = IO.read(@filename)
|
22
|
+
|
23
|
+
# find all attributes
|
24
|
+
resource_data.gsub(/#{ATTRIBUTE_REGEX}/) do
|
25
|
+
name = get_attribute_name($1)
|
26
|
+
value = $2.strip
|
27
|
+
|
28
|
+
if value.starts_with?("{")
|
29
|
+
value = "{ ... }"
|
30
|
+
elsif value.starts_with?("[")
|
31
|
+
value = "[ ... ]"
|
32
|
+
else
|
33
|
+
value = value.gsub(/\A\"|\A'|\"\Z|'\Z/, '')
|
34
|
+
end
|
35
|
+
|
36
|
+
options = {}
|
37
|
+
options[:default] = value
|
38
|
+
@attributes[name] = options
|
39
|
+
end
|
40
|
+
|
41
|
+
# get/parse comments
|
42
|
+
resource_data = resource_data.gsub(/^=begin\s*\n\s*\#\<\s*\n(.*?)^\s*\#\>\n=end\s*\n#{ATTRIBUTE_REGEX}/m) do
|
43
|
+
update_attribute($2, $1)
|
44
|
+
end
|
45
|
+
resource_data = resource_data.gsub(/^\s*\#\<\n(.*?)^\s*\#\>\n#{ATTRIBUTE_REGEX}/m) do
|
46
|
+
update_attribute($2, $1.gsub(/^\s*\# ?/, ''))
|
47
|
+
end
|
48
|
+
resource_data = resource_data.gsub(/^\s*\#\<\>\s(.*?$)\n#{ATTRIBUTE_REGEX}/m) do
|
49
|
+
update_attribute($2, $1)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_attribute(name, description)
|
54
|
+
name = get_attribute_name(name)
|
55
|
+
options = @attributes[name]
|
56
|
+
options[:description] = description.strip
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_attribute_name(name)
|
60
|
+
name.strip.gsub(/^default/, "node")
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -7,6 +7,21 @@ module KnifeCookbookDoc
|
|
7
7
|
@metadata = Chef::Cookbook::Metadata.new
|
8
8
|
@metadata.from_file("#{cookbook_dir}/metadata.rb")
|
9
9
|
|
10
|
+
if !@metadata.attributes.empty?
|
11
|
+
@attributes = @metadata.attributes.map do |attr, options|
|
12
|
+
name = "node['#{attr.gsub("/", "']['")}']"
|
13
|
+
[name, options['description'], options['default'], options['choice']]
|
14
|
+
end
|
15
|
+
else
|
16
|
+
@attributes = []
|
17
|
+
Dir["#{cookbook_dir}/attributes/*.rb"].sort.each do |attribute_filename|
|
18
|
+
model = AttributesModel.new(attribute_filename)
|
19
|
+
if !model.attributes.empty?
|
20
|
+
@attributes += model.attributes
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
10
25
|
@resources = []
|
11
26
|
Dir["#{cookbook_dir}/resources/*.rb"].sort.each do |resource_filename|
|
12
27
|
@resources << ResourceModel.new(@metadata.name, resource_filename)
|
@@ -18,8 +33,17 @@ module KnifeCookbookDoc
|
|
18
33
|
end
|
19
34
|
|
20
35
|
@recipes = []
|
21
|
-
|
22
|
-
@recipes
|
36
|
+
if !@metadata.recipes.empty?
|
37
|
+
@metadata.recipes.each do |name, description|
|
38
|
+
@recipes << RecipeModel.new(name, description, "#{cookbook_dir}/recipes/#{name.gsub(/^.*\:(.*)$/,'\1')}.rb")
|
39
|
+
end
|
40
|
+
else
|
41
|
+
Dir["#{cookbook_dir}/recipes/*.rb"].sort.each do |recipe_filename|
|
42
|
+
base_name = File.basename(recipe_filename, ".rb")
|
43
|
+
if !base_name.start_with?("_")
|
44
|
+
@recipes << RecipeModel.new("#{@metadata.name}::#{base_name}", recipe_filename)
|
45
|
+
end
|
46
|
+
end
|
23
47
|
end
|
24
48
|
@metadata = @metadata
|
25
49
|
@constraints = constraints
|
@@ -68,10 +92,7 @@ module KnifeCookbookDoc
|
|
68
92
|
end
|
69
93
|
|
70
94
|
def attributes
|
71
|
-
@
|
72
|
-
name = "node['#{attr.gsub("/", "']['")}']"
|
73
|
-
[name, options['description'], options['default']]
|
74
|
-
end
|
95
|
+
@attributes
|
75
96
|
end
|
76
97
|
|
77
98
|
def recipes
|
@@ -4,7 +4,7 @@ module KnifeCookbookDoc
|
|
4
4
|
attr_reader :name
|
5
5
|
attr_reader :short_description
|
6
6
|
|
7
|
-
def initialize(name, short_description, filename)
|
7
|
+
def initialize(name, short_description = nil, filename)
|
8
8
|
@name = name
|
9
9
|
@short_description = short_description
|
10
10
|
@filename = filename
|
@@ -23,7 +23,8 @@ module KnifeCookbookDoc
|
|
23
23
|
|
24
24
|
def load_descriptions
|
25
25
|
current_section = 'main'
|
26
|
-
|
26
|
+
description = extract_description
|
27
|
+
description.each_line do |line|
|
27
28
|
if /^ *\@section (.*)$/ =~ line
|
28
29
|
current_section = $1.strip
|
29
30
|
else
|
@@ -32,6 +33,9 @@ module KnifeCookbookDoc
|
|
32
33
|
top_level_descriptions[current_section] = lines
|
33
34
|
end
|
34
35
|
end
|
36
|
+
if @short_description.nil?
|
37
|
+
@short_description = first_sentence(description) || ""
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
include ::Chef::Mixin::ConvertToClassName
|
@@ -50,6 +54,13 @@ module KnifeCookbookDoc
|
|
50
54
|
end
|
51
55
|
description.join("\n")
|
52
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
|
53
64
|
end
|
54
65
|
|
55
66
|
class DocumentingLWRPBase < ::Chef::Resource::LWRPBase
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-09-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: chef
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- knife_cookbook_doc.gemspec
|
79
79
|
- lib/chef/knife/README.md.erb
|
80
80
|
- lib/chef/knife/cookbook_doc.rb
|
81
|
+
- lib/knife_cookbook_doc/attributes_model.rb
|
81
82
|
- lib/knife_cookbook_doc/readme_model.rb
|
82
83
|
- lib/knife_cookbook_doc/recipe_model.rb
|
83
84
|
- lib/knife_cookbook_doc/resource_model.rb
|