chef_attrdoc 1.0.1 → 1.0.2

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.
data/bin/chef_attrdoc CHANGED
@@ -19,6 +19,7 @@
19
19
  require 'optparse'
20
20
 
21
21
  require 'chef_attrdoc'
22
+ require 'chef_attrdoc/version'
22
23
 
23
24
  options = {}
24
25
 
@@ -26,6 +27,8 @@ opt_parser = OptionParser.new do |opts|
26
27
  opts.banner = "Usage: chef_attrdoc [DIR] [options]\n"
27
28
  opts.banner << "DIR - cookbook directory - defaults to the current directory\n"
28
29
 
30
+ opts.version = ChefAttrdoc::VERSION
31
+
29
32
  options[:readme] = "README.md"
30
33
  opts.on("-r", "--readme README",
31
34
  "Readme file name; defaults to ./README.md; must be Markdown") do |readme|
@@ -1,3 +1,3 @@
1
1
  module ChefAttrdoc
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/lib/chef_attrdoc.rb CHANGED
@@ -139,21 +139,16 @@ module ChefAttrdoc
139
139
  # TODO find a cleaner way and do this in one step
140
140
  content = f.read
141
141
  if content =~ /\nAttributes\s*=+\s*\n/
142
- updated = content.gsub(/(?<before>.*\nAttributes\s*=+\s*\n)(?m:.+?)(?<after>\n.+\s*\n=+.*)/,
142
+ updated = content.gsub(/(?<before>.*\nAttributes\s*=+\s*?\n)\n*(?m:.+?)(?<after>\n.+\s*\n=+.*)/,
143
143
  '\k<before>CHEF_ATTRDOC_UPDATING_TEMPLATE\k<after>')
144
-
145
- # XXX hack because I couldn't figure out how to get another
146
- # newline in between the <before> and the content
147
- updated.sub!('CHEF_ATTRDOC_UPDATING_TEMPLATE',
148
- "\nCHEF_ATTRDOC_UPDATING_TEMPLATE")
149
144
  elsif content =~ /\n\#+\s*Attributes\s*\n/
150
- updated = content.gsub(/(?<before>.*\n\#+\s*Attributes\s*\n)(.+?)(?<after>\n\#+.*)/m,
145
+ updated = content.gsub(/(?<before>.*\n\#+\s*Attributes\s*?\n)\n*(.+?)(?<after>\n\#+.*)/m,
151
146
  '\k<before>CHEF_ATTRDOC_UPDATING_TEMPLATE\k<after>')
152
147
  else
153
148
  raise StandardError, "Could not find Attributes heading in #{readme}. Please make sure your README file has proper markdown formatting and includes an Attributes heading."
154
149
  end
155
150
 
156
- updated.sub! 'CHEF_ATTRDOC_UPDATING_TEMPLATE', parsed
151
+ updated.sub! 'CHEF_ATTRDOC_UPDATING_TEMPLATE', "\n" + parsed
157
152
  f.rewind
158
153
  f.write(updated)
159
154
  f.flush
@@ -27,6 +27,42 @@ describe ChefAttrdoc do
27
27
 
28
28
  Attributes
29
29
  ==========
30
+ my attributes
31
+
32
+ are nice
33
+
34
+ Another header
35
+ ==============
36
+
37
+ doc we won't touch
38
+
39
+ README
40
+ allow(::File).to receive(:open).and_yield(readme)
41
+ expect(readme).to receive(:write).with(<<-README)
42
+
43
+ Attributes
44
+ ==========
45
+
46
+ foo
47
+
48
+ Another header
49
+ ==============
50
+
51
+ doc we won't touch
52
+
53
+ README
54
+ ChefAttrdoc.write_readme('filename', "foo\n")
55
+ end
56
+
57
+ it 'normalizes space after an Attributes section' do
58
+ readme = double('file').as_null_object
59
+ allow(readme).to receive(:read).and_return(<<-README)
60
+
61
+ Attributes
62
+ ==========
63
+
64
+
65
+
30
66
  my attributes
31
67
 
32
68
  are nice
@@ -60,6 +96,35 @@ README
60
96
  allow(readme).to receive(:read).and_return(<<-README)
61
97
 
62
98
  ## Attributes
99
+ my attributes
100
+
101
+ are nice
102
+
103
+ ## Another header
104
+
105
+ doc we won't touch
106
+ README
107
+ allow(::File).to receive(:open).and_yield(readme)
108
+ expect(readme).to receive(:write).with(<<-README)
109
+
110
+ ## Attributes
111
+
112
+ foo
113
+
114
+ ## Another header
115
+
116
+ doc we won't touch
117
+ README
118
+ ChefAttrdoc.write_readme('filename', "foo\n")
119
+ end
120
+
121
+ it 'normalizes space after an Attributes section' do
122
+ readme = double('file').as_null_object
123
+ allow(readme).to receive(:read).and_return(<<-README)
124
+
125
+ ## Attributes
126
+
127
+
63
128
 
64
129
  my attributes
65
130
 
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Copyright 2014, Ionuț Arțăriși <ionut@artarisi.eu>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ describe 'chef_attrdoc' do
19
+ it 'shows version' do
20
+ output = `ruby -Ilib bin/chef_attrdoc --version`
21
+ expect(output).to match(/chef_attrdoc \d+\.\d+\.\d+/)
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef_attrdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-04 00:00:00.000000000 Z
12
+ date: 2014-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -64,6 +64,7 @@ files:
64
64
  - lib/chef_attrdoc/version.rb
65
65
  - spec/attributes_file_spec.rb
66
66
  - spec/chef_attrdoc_spec.rb
67
+ - spec/cli_spec.rb
67
68
  - spec/fixtures/cookbook-example/README.md
68
69
  - spec/fixtures/cookbook-example/attributes/default.rb
69
70
  - spec/fixtures/file1.rb
@@ -99,6 +100,7 @@ summary: Generate README.md docs from Chef cookbook attributes files
99
100
  test_files:
100
101
  - spec/attributes_file_spec.rb
101
102
  - spec/chef_attrdoc_spec.rb
103
+ - spec/cli_spec.rb
102
104
  - spec/fixtures/cookbook-example/README.md
103
105
  - spec/fixtures/cookbook-example/attributes/default.rb
104
106
  - spec/fixtures/file1.rb