knife-cookbook-readme 0.1.3 → 0.2.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a22fbf6290e37c8c038ef2df5c4d02f71de5d862
4
- data.tar.gz: bc71a063b422222a8b1e54bedc82fef90dc44e4d
3
+ metadata.gz: 193805210062a991a89d12cd47566a7510fc3b07
4
+ data.tar.gz: 0bf71481d6c7d0d520dc6d3d6ab0d11a8b3ae695
5
5
  SHA512:
6
- metadata.gz: 23c18204dd65d728e9c972c05b1d7dee6fd46efbd8bd063bbb7e7472126f18fafaaea6df5c799913b3a4c62232c8a5a4f27df303afb6d496c20aea5e3b27989d
7
- data.tar.gz: 7c5ceab3877c69dc5b9d66b9a4b54c20881aa7e99a6db182800b4f942995bb76ca2df404a0e75c6994d53e62017720489c77dfb882b00d92621dd4c80552d457
6
+ metadata.gz: 985774423c5a13afd53b117896ed95569897ddec8cfa76f0fe47481cc781f91297732eed682ad489a04d21ce3a7910c21c23109edc33b8d434526e4065bc1680
7
+ data.tar.gz: 42a8cf5c5525e4d22a2a3e4b864282a49adffea4f3d37c4d64c41493f80b5f6e0cc8fb9cfb58266aad5b761bb2e57a67a8b3cdad72d478f41e61e2be0a87de65
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ v0.2.0 (Sep 22 2013)
2
+ --------------------
3
+
4
+ * Split up logic into `Metadata`, `Readme`, and `Template` classes. Add specs.
5
+ * Make `DEFAULT_CONSTRAINT` a module variable.
6
+
1
7
  v0.1.3 (Sep 15 2013)
2
8
  --------------------
3
9
 
@@ -4,9 +4,9 @@ require 'pathname'
4
4
  module KnifeCookbookReadme
5
5
  class CookbookReadmeFrom < Chef::Knife
6
6
  deps do
7
- require 'chef/cookbook/metadata'
8
- require 'erubis'
9
- require 'knife_cookbook_readme/readme_model'
7
+ require 'knife_cookbook_readme/metadata'
8
+ require 'knife_cookbook_readme/readme'
9
+ require 'knife_cookbook_readme/template'
10
10
  end
11
11
 
12
12
  banner 'knife cookbook readme from FILE (options)'
@@ -26,18 +26,19 @@ module KnifeCookbookReadme
26
26
  :description => 'Set template file used to render README.md'
27
27
 
28
28
  def run
29
- unless (metadata_file = name_args.first)
29
+ metadata_file = name_args.first
30
+ template_file = config[:template_file]
31
+ constraints = config[:constraints]
32
+
33
+ unless metadata_file
30
34
  ui.fatal 'Please provide metadata.rb file as argument'
31
- exit(1)
35
+ exit 1
32
36
  end
33
37
 
34
- metadata = Chef::Cookbook::Metadata.new
35
- metadata.from_file(metadata_file)
36
-
37
- model = ReadmeModel.new(metadata, config[:constraints])
38
- template = File.read(config[:template_file])
39
- eruby = Erubis::Eruby.new(template)
40
- result = eruby.result(model.get_binding)
38
+ metadata = Metadata.from_file(metadata_file)
39
+ template = File.read(template_file)
40
+ readme = Readme.new(metadata, constraints)
41
+ result = readme.render(template)
41
42
 
42
43
  ui.output(result)
43
44
  end
@@ -0,0 +1,11 @@
1
+ require "chef/cookbook/metadata"
2
+
3
+ module KnifeCookbookReadme
4
+ class Metadata
5
+ def self.from_file(filename)
6
+ metadata = Chef::Cookbook::Metadata.new
7
+ metadata.from_file(filename)
8
+ metadata
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
1
  module KnifeCookbookReadme
2
- class ReadmeModel
3
- DEFAULT_CONSTRAINT = ">= 0.0.0".freeze
2
+ DEFAULT_CONSTRAINT = ">= 0.0.0".freeze
4
3
 
4
+ class Readme
5
5
  def initialize(metadata, constraints=false)
6
6
  @metadata = metadata
7
7
  @constraints = constraints
@@ -54,8 +54,8 @@ module KnifeCookbookReadme
54
54
  @metadata.license
55
55
  end
56
56
 
57
- def get_binding
58
- binding
57
+ def render(template)
58
+ Template.render(template, get_binding)
59
59
  end
60
60
 
61
61
  private
@@ -67,5 +67,9 @@ module KnifeCookbookReadme
67
67
  name
68
68
  end
69
69
  end
70
+
71
+ def get_binding
72
+ binding
73
+ end
70
74
  end
71
75
  end
@@ -0,0 +1,11 @@
1
+ require "erubis"
2
+
3
+ module KnifeCookbookReadme
4
+ class Template
5
+ def self.render(template, binding)
6
+ eruby = Erubis::Eruby.new(template)
7
+ output = eruby.result(binding)
8
+ output
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module KnifeCookbookReadme
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,11 @@
1
+ require File.expand_path("../../lib/knife_cookbook_readme/metadata", __FILE__)
2
+
3
+ module KnifeCookbookReadme
4
+ describe "Metadata.from_file" do
5
+ it "knows how to read metadata from metadata.rb" do
6
+ file = double
7
+ Chef::Cookbook::Metadata.any_instance.should_receive(:from_file).with(file)
8
+ Metadata.from_file(file)
9
+ end
10
+ end
11
+ end
@@ -1,27 +1,28 @@
1
- require File.expand_path("../../lib/knife_cookbook_readme/readme_model", __FILE__)
2
- require "erubis"
1
+ require File.expand_path("../../lib/knife_cookbook_readme/readme", __FILE__)
2
+
3
+ class Template; end
3
4
 
4
5
  module KnifeCookbookReadme
5
- describe ReadmeModel do
6
+ describe Readme do
6
7
  it "generates title from cookbook name" do
7
8
  cookbook_name = "cats"
8
9
  metadata = double(:metadata, :name => cookbook_name)
9
- model = ReadmeModel.new(metadata)
10
- model.title.should == "Cats Cookbook"
10
+ readme = Readme.new(metadata)
11
+ readme.title.should == "Cats Cookbook"
11
12
  end
12
13
 
13
14
  it "generates description" do
14
15
  description = double
15
16
  metadata = double(:metadata, :description => description)
16
- model = ReadmeModel.new(metadata)
17
- model.description.should == description
17
+ readme = Readme.new(metadata)
18
+ readme.description.should == description
18
19
  end
19
20
 
20
21
  it "generates recipes" do
21
22
  recipes = double
22
23
  metadata = double(:metadata, :recipes => recipes)
23
- model = ReadmeModel.new(metadata)
24
- model.recipes.should == recipes
24
+ readme = Readme.new(metadata)
25
+ readme.recipes.should == recipes
25
26
  end
26
27
 
27
28
  it "generates cookbook attributes" do
@@ -36,8 +37,8 @@ module KnifeCookbookReadme
36
37
  }
37
38
  }
38
39
  metadata = double(:metadata, :attributes => attributes)
39
- model = ReadmeModel.new(metadata)
40
- model.attributes.sort.should == [
40
+ readme = Readme.new(metadata)
41
+ readme.attributes.sort.should == [
41
42
  ["node['pets']['cat']['name']", "The name of your cat", "Kitty"],
42
43
  ["node['pets']['dog']['name']", "The name of your dog", "Barf"],
43
44
  ]
@@ -51,36 +52,33 @@ module KnifeCookbookReadme
51
52
 
52
53
  it "generates platforms with version constraints" do
53
54
  constraints = true
54
- model = ReadmeModel.new(metadata, constraints)
55
- model.platforms.sort.should == ["Debian (= 7)", "Ubuntu (>= 10.04)"]
55
+ readme = Readme.new(metadata, constraints)
56
+ readme.platforms.sort.should == ["Debian (= 7)", "Ubuntu (>= 10.04)"]
56
57
  end
57
58
 
58
59
  it "generates platforms without version constraints" do
59
60
  constraints = false
60
- model = ReadmeModel.new(metadata, constraints)
61
- model.platforms.sort.should == ["Debian", "Ubuntu"]
61
+ readme = Readme.new(metadata, constraints)
62
+ readme.platforms.sort.should == ["Debian", "Ubuntu"]
62
63
  end
63
64
  end
64
65
 
65
66
  context "cookbook dependencies" do
66
67
  let(:metadata) do
67
- dependencies = {
68
- "cats" => "< 1.0",
69
- "dogs" => ReadmeModel::DEFAULT_CONSTRAINT,
70
- }
68
+ dependencies = { "cats" => "< 1.0", "dogs" => DEFAULT_CONSTRAINT }
71
69
  double(:metadata, :dependencies => dependencies)
72
70
  end
73
71
 
74
72
  it "generates dependencies with version constraints" do
75
73
  constraints = true
76
- model = ReadmeModel.new(metadata, constraints)
77
- model.dependencies.sort.should == ["cats (< 1.0)", "dogs"]
74
+ readme = Readme.new(metadata, constraints)
75
+ readme.dependencies.sort.should == ["cats (< 1.0)", "dogs"]
78
76
  end
79
77
 
80
78
  it "generates dependencies without version constraints" do
81
79
  constraints = false
82
- model = ReadmeModel.new(metadata, constraints)
83
- model.dependencies.sort.should == ["cats", "dogs"]
80
+ readme = Readme.new(metadata, constraints)
81
+ readme.dependencies.sort.should == ["cats", "dogs"]
84
82
  end
85
83
  end
86
84
 
@@ -88,54 +86,40 @@ module KnifeCookbookReadme
88
86
  it "generates author from maintainer name" do
89
87
  maintainer = double
90
88
  metadata = double(:metadata, :maintainer => maintainer)
91
- model = ReadmeModel.new(metadata)
92
- model.author.should == maintainer
89
+ readme = Readme.new(metadata)
90
+ readme.author.should == maintainer
93
91
  end
94
92
 
95
93
  it "generates author email from maintainer email" do
96
94
  maintainer_email = double
97
95
  metadata = double(:metadata, :maintainer_email => maintainer_email)
98
- model = ReadmeModel.new(metadata)
99
- model.author_email.should == maintainer_email
96
+ readme = Readme.new(metadata)
97
+ readme.author_email.should == maintainer_email
100
98
  end
101
99
 
102
100
  it "generates copyright year from current year" do
103
101
  time_now = Time.mktime(2013, 1, 1)
104
102
  Time.stub(:now).and_return(time_now)
105
103
  metadata = double
106
- model = ReadmeModel.new(metadata)
107
- model.copyright_year.should == time_now.year
104
+ readme = Readme.new(metadata)
105
+ readme.copyright_year.should == time_now.year
108
106
  end
109
107
 
110
108
  it "generates license name" do
111
109
  license = double
112
110
  metadata = double(:metadata, :license => license)
113
- model = ReadmeModel.new(metadata)
114
- model.license.should == license
111
+ readme = Readme.new(metadata)
112
+ readme.license.should == license
115
113
  end
116
114
  end
117
115
 
118
- # TODO: implement ReadmeModel#render
119
- context "template rendering" do
120
- it "can be rendered with erubis" do
121
- metadata = double(:metadata,
122
- :name => "cats",
123
- :description => "Manages a herd of cats!")
124
- model = ReadmeModel.new(metadata)
125
- template = <<EOS
126
- <%= title %>
127
- <%= '=' * title.length %>
128
-
129
- <%= description %>
130
- EOS
131
- eruby = Erubis::Eruby.new(template)
132
- result = eruby.result(model.get_binding)
133
- result.should == <<EOS
134
- Cats Cookbook
135
- =============
136
-
137
- Manages a herd of cats!
138
- EOS
116
+ context "#render" do
117
+ it "knows how to render a README.md file" do
118
+ template = double
119
+ Template.should_receive(:render).with(template, kind_of(Binding))
120
+ metadata = double
121
+ readme = Readme.new(metadata)
122
+ readme.render(template)
139
123
  end
140
124
  end
141
125
  end
@@ -0,0 +1,12 @@
1
+ require File.expand_path("../../lib/knife_cookbook_readme/template", __FILE__)
2
+
3
+ module KnifeCookbookReadme
4
+ describe "Template.render" do
5
+ it "renders ERB template" do
6
+ template = "Hello, <%= title %>."
7
+ binding = { :title => "Mr. President" }
8
+ output = Template.render(template, binding)
9
+ output.should == "Hello, Mr. President."
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-cookbook-readme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Lafeldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-15 00:00:00.000000000 Z
11
+ date: 2013-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -82,9 +82,13 @@ files:
82
82
  - Rakefile
83
83
  - knife_cookbook_readme.gemspec
84
84
  - lib/chef/knife/cookbook_readme_from.rb
85
- - lib/knife_cookbook_readme/readme_model.rb
85
+ - lib/knife_cookbook_readme/metadata.rb
86
+ - lib/knife_cookbook_readme/readme.rb
87
+ - lib/knife_cookbook_readme/template.rb
86
88
  - lib/knife_cookbook_readme/version.rb
87
- - spec/readme_model_spec.rb
89
+ - spec/metadata_spec.rb
90
+ - spec/readme_spec.rb
91
+ - spec/template_spec.rb
88
92
  - template/README.md.erb
89
93
  homepage: http://mlafeldt.github.com/knife-cookbook-readme
90
94
  licenses:
@@ -111,4 +115,6 @@ signing_key:
111
115
  specification_version: 4
112
116
  summary: Knife plugin to generate README.md from metadata.rb
113
117
  test_files:
114
- - spec/readme_model_spec.rb
118
+ - spec/metadata_spec.rb
119
+ - spec/readme_spec.rb
120
+ - spec/template_spec.rb