document_generator 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/assets/_layouts/default.html +1 -1
- data/document_generator.gemspec +1 -0
- data/lib/document_generator/diff_file.rb +71 -46
- data/lib/document_generator/output.rb +4 -0
- data/lib/document_generator/version.rb +1 -1
- data/spec/lib/document_generator/diff_file_spec.rb +146 -7
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6871a1067a242543d48a66cd7475e79ece9521d2
|
4
|
+
data.tar.gz: 23a5d3e5ab9d5f8f57e3bac358082529f77b4dcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d958dede20b91df5423a6ffe35243a30b52a498e02254737230ecb833ec2898322aa75165b0d5f41945f6fad4f7ebd17c97508e047c98110368fec0b18519f08
|
7
|
+
data.tar.gz: 720106b2000cb8707243a9bbfae1291e9fba2919171989130d15fdc4f8a903418d90552c7d49cc345138ad5a7fc2857c0e373152b370dc15285da265fd84d45d
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.0.0-
|
1
|
+
ruby-2.0.0-p353
|
data/document_generator.gemspec
CHANGED
@@ -12,40 +12,44 @@ module DocumentGenerator
|
|
12
12
|
@git_diff_file = git_diff_file
|
13
13
|
end
|
14
14
|
|
15
|
-
def git_diff_file_lines
|
16
|
-
git_diff_file.patch.split("\n")
|
17
|
-
end
|
18
|
-
|
19
15
|
def patch_heading
|
20
16
|
"#{action_type} `#{git_diff_file.path}`"
|
21
17
|
end
|
22
18
|
|
19
|
+
def git_diff_file_hunks
|
20
|
+
hunks = git_diff_file.patch.split(/@@.*@@.*\n/)
|
21
|
+
hunks.shift # Shift to pop first element off array which is just git diff header info
|
22
|
+
hunks
|
23
|
+
end
|
24
|
+
|
25
|
+
def git_diff_lines_for(hunk)
|
26
|
+
hunk.split("\n")
|
27
|
+
end
|
28
|
+
|
23
29
|
def content
|
24
30
|
if type == 'deleted'
|
25
|
-
return patch_heading
|
31
|
+
return "####{patch_heading}\n\n"
|
26
32
|
end
|
27
33
|
|
28
34
|
temp = []
|
29
|
-
temp << patch_heading
|
35
|
+
temp << "####{patch_heading}"
|
30
36
|
|
31
|
-
|
32
|
-
|
37
|
+
outputs = markdown_outputs
|
38
|
+
if outputs.any?
|
39
|
+
outputs.each do |output|
|
33
40
|
if output.escaped_content.length > 0
|
34
41
|
temp << "\n\n"
|
35
42
|
temp << output.description
|
36
43
|
temp << "\n<pre><code>"
|
37
|
-
|
44
|
+
if output.description == "Becomes"
|
45
|
+
temp << output.content.join("\n") + "\n"
|
46
|
+
else
|
47
|
+
temp << output.escaped_content
|
48
|
+
end
|
38
49
|
temp << "</code></pre>\n"
|
39
50
|
end
|
40
51
|
end
|
41
|
-
end
|
42
52
|
|
43
|
-
if git_diff_file.type == "modified"
|
44
|
-
temp << "\n\n"
|
45
|
-
temp << "Becomes"
|
46
|
-
temp << "\n<pre><code>"
|
47
|
-
temp << ending_code
|
48
|
-
temp << "\n</code></pre>\n"
|
49
53
|
end
|
50
54
|
|
51
55
|
temp << "\n\n"
|
@@ -53,10 +57,18 @@ module DocumentGenerator
|
|
53
57
|
temp.join
|
54
58
|
end
|
55
59
|
|
56
|
-
def ending_code
|
60
|
+
def ending_code # The escaped end result code for the whole diff file returned as a string
|
61
|
+
clean_hunks = []
|
62
|
+
git_diff_file_hunks.each do |hunk|
|
63
|
+
clean_hunks << ending_code_for(hunk).join("\n")
|
64
|
+
end
|
65
|
+
Output.no_really_escape(CGI.escapeHTML(clean_hunks.join("\n")))
|
66
|
+
end
|
67
|
+
|
68
|
+
def ending_code_for(hunk) # The unescaped end result code for a particular hunk returned as array
|
57
69
|
clean_lines = []
|
58
|
-
git_diff_file_lines[code_line_start..-1].each_with_index do |line, index|
|
59
70
|
|
71
|
+
git_diff_lines_for(hunk).each_with_index do |line, index|
|
60
72
|
if (line[0]) == "-" || ignore_line?(line)
|
61
73
|
next
|
62
74
|
end
|
@@ -64,9 +76,10 @@ module DocumentGenerator
|
|
64
76
|
if (line[0]) == "+"
|
65
77
|
line = remove_first_character(line)
|
66
78
|
end
|
79
|
+
line = CGI.unescapeHTML(line) # Shouldn't be necessary?
|
67
80
|
clean_lines << line
|
68
81
|
end
|
69
|
-
|
82
|
+
clean_lines
|
70
83
|
end
|
71
84
|
|
72
85
|
def action_type
|
@@ -75,63 +88,81 @@ module DocumentGenerator
|
|
75
88
|
deleted: 'Remove file' }.fetch(type.to_sym, type)
|
76
89
|
end
|
77
90
|
|
78
|
-
def markdown_outputs
|
91
|
+
def markdown_outputs
|
92
|
+
outputs = []
|
93
|
+
git_diff_file_hunks.each do |hunk|
|
94
|
+
outputs << markdown_outputs_for(hunk)
|
95
|
+
end
|
96
|
+
outputs.flatten
|
97
|
+
end
|
98
|
+
|
99
|
+
def markdown_outputs_for(hunk) # returns an array of outputs for a particular hunk
|
79
100
|
outputs = []
|
80
|
-
last_line =
|
81
|
-
|
82
|
-
next if index < code_line_start
|
101
|
+
last_line = -1
|
102
|
+
git_diff_lines_for(hunk).each_with_index do |line, index|
|
83
103
|
next if index <= last_line
|
84
104
|
case line.strip[0]
|
85
105
|
|
86
106
|
when "+"
|
87
|
-
last_line = last_same_line(index)
|
107
|
+
last_line = last_same_line(index, hunk)
|
88
108
|
output = Output.new
|
89
109
|
output.description = "Add"
|
90
|
-
output.content = line_block(index, last_line)
|
110
|
+
output.content = line_block(index, last_line, hunk)
|
91
111
|
outputs << output
|
92
112
|
when "-"
|
93
|
-
if line_sign(index + 1) == "+"
|
113
|
+
if line_sign(index + 1, hunk) == "+"
|
94
114
|
output = Output.new
|
95
115
|
output.description = "Change"
|
96
|
-
output.content = line_block(index, last_same_line(index))
|
116
|
+
output.content = line_block(index, last_same_line(index, hunk), hunk)
|
97
117
|
outputs << output
|
98
|
-
last_line = last_same_line(last_same_line(index) + 1)
|
118
|
+
last_line = last_same_line(last_same_line(index, hunk) + 1, hunk)
|
119
|
+
|
99
120
|
output = Output.new
|
100
121
|
output.description = "To"
|
101
|
-
output.content = line_block(last_same_line(index) + 1, last_line)
|
122
|
+
output.content = line_block(last_same_line(index, hunk) + 1, last_line, hunk)
|
102
123
|
outputs << output
|
124
|
+
last_line = last_same_line(last_same_line(index, hunk) + 1, hunk)
|
103
125
|
else
|
104
126
|
output = Output.new
|
105
127
|
output.description = "Remove"
|
106
|
-
last_line = last_same_line(index)
|
107
|
-
output.content = line_block(index, last_line)
|
128
|
+
last_line = last_same_line(index, hunk)
|
129
|
+
output.content = line_block(index, last_line, hunk)
|
108
130
|
outputs << output
|
109
131
|
end
|
110
132
|
end
|
133
|
+
end
|
111
134
|
|
135
|
+
if git_diff_file.type == 'modified'
|
136
|
+
output = Output.new
|
137
|
+
output.description = "Becomes"
|
138
|
+
output.content = ending_code_for(hunk)
|
139
|
+
outputs << output
|
112
140
|
end
|
141
|
+
|
113
142
|
outputs
|
114
143
|
end
|
115
144
|
|
116
|
-
|
145
|
+
|
146
|
+
|
147
|
+
private
|
117
148
|
|
118
149
|
def ignore_line?(line)
|
119
150
|
line.strip == 'No newline at end of file'
|
120
151
|
end
|
121
152
|
|
122
|
-
def last_same_line(line_index)
|
123
|
-
starting_sign = line_sign(line_index)
|
153
|
+
def last_same_line(line_index, hunk)
|
154
|
+
starting_sign = line_sign(line_index, hunk)
|
124
155
|
|
125
|
-
|
126
|
-
if line_sign(index + 1 + line_index) != starting_sign
|
156
|
+
git_diff_lines_for(hunk)[line_index..-1].each_with_index do |line, index|
|
157
|
+
if line_sign(index + 1 + line_index, hunk) != starting_sign
|
127
158
|
return (index + line_index)
|
128
159
|
end
|
129
160
|
end
|
130
161
|
end
|
131
162
|
|
132
|
-
def line_block(beginning, ending)
|
163
|
+
def line_block(beginning, ending, hunk)
|
133
164
|
lines = []
|
134
|
-
|
165
|
+
git_diff_lines_for(hunk)[beginning..ending].each do |line|
|
135
166
|
if ["+", "-"].include?(line[0..0])
|
136
167
|
line = remove_first_character(line)
|
137
168
|
end
|
@@ -142,18 +173,12 @@ module DocumentGenerator
|
|
142
173
|
lines
|
143
174
|
end
|
144
175
|
|
145
|
-
def line_sign(line_number)
|
146
|
-
(
|
176
|
+
def line_sign(line_number, hunk)
|
177
|
+
(git_diff_lines_for(hunk)[line_number] || '').strip[0]
|
147
178
|
end
|
148
179
|
|
149
180
|
def remove_first_character(line)
|
150
181
|
" " + line[1..-1]
|
151
182
|
end
|
152
|
-
|
153
|
-
def code_line_start
|
154
|
-
git_diff_file_lines.each_with_index do |line, index|
|
155
|
-
return (index + 1) if line[0..1] == "@@"
|
156
|
-
end
|
157
|
-
end
|
158
183
|
end
|
159
184
|
end
|
@@ -29,7 +29,7 @@ EXPECTED
|
|
29
29
|
|
30
30
|
let(:expected_content) do
|
31
31
|
<<-EXPECTED_CONTENT
|
32
|
-
Create file `/spec/support/capybara.rb`
|
32
|
+
###Create file `/spec/support/capybara.rb`
|
33
33
|
|
34
34
|
Add
|
35
35
|
<pre><code> Capybara.javascript_driver = :webkit</code></pre>
|
@@ -168,8 +168,11 @@ EXPECTED_CONTENT
|
|
168
168
|
expect(diff_file.markdown_outputs.first.description).to eq "Change"
|
169
169
|
expect(diff_file.markdown_outputs.first.escaped_content).to eq CGI.escapeHTML(" <%= form_for :post do |f| %>")
|
170
170
|
|
171
|
-
expect(diff_file.markdown_outputs.
|
172
|
-
expect(diff_file.markdown_outputs.
|
171
|
+
expect(diff_file.markdown_outputs[1].description).to eq "To"
|
172
|
+
expect(diff_file.markdown_outputs[1].escaped_content).to eq CGI.escapeHTML(" <%= form_for :post, url: posts_path do |f| %>")
|
173
|
+
|
174
|
+
expect(diff_file.markdown_outputs[2].description).to eq "Becomes"
|
175
|
+
expect(diff_file.markdown_outputs[2].escaped_content).to eq diff_file.ending_code
|
173
176
|
end
|
174
177
|
end
|
175
178
|
|
@@ -181,6 +184,139 @@ EXPECTED_CONTENT
|
|
181
184
|
end
|
182
185
|
end
|
183
186
|
|
187
|
+
context 'when the git diff file has two changes in different hunks' do
|
188
|
+
let(:type) { 'modified' }
|
189
|
+
let(:file_name) { '/spec/controllers/posts_controller_spec.rb' }
|
190
|
+
|
191
|
+
let(:patch) do
|
192
|
+
<<-PATCH
|
193
|
+
stuffasdfasdfadasdfasd
|
194
|
+
asdadsfasdfasdf
|
195
|
+
asdfasdfasdfasdf
|
196
|
+
@@ -5,7 +5,7 @@
|
197
|
+
describe 'GET #new' do
|
198
|
+
it "returns http success" do
|
199
|
+
get :new
|
200
|
+
- response.should be_success
|
201
|
+
+ expect(response).to be_success
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
@@ -19,7 +19,7 @@
|
206
|
+
describe 'GET #index' do
|
207
|
+
it "returns http success" do
|
208
|
+
get :index
|
209
|
+
- response.should be_success
|
210
|
+
+ expect(response).to be_success
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
PATCH
|
215
|
+
end
|
216
|
+
|
217
|
+
let(:ending) do
|
218
|
+
<<-ENDING
|
219
|
+
describe 'GET #new' do
|
220
|
+
it "returns http success" do
|
221
|
+
get :new
|
222
|
+
expect(response).to be_success
|
223
|
+
end
|
224
|
+
end
|
225
|
+
describe 'GET #index' do
|
226
|
+
it "returns http success" do
|
227
|
+
get :index
|
228
|
+
expect(response).to be_success
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
ENDING
|
233
|
+
end
|
234
|
+
|
235
|
+
let(:expected_content) do
|
236
|
+
<<-EXPECTED_CONTENT
|
237
|
+
###Update file `/spec/controllers/posts_controller_spec.rb`
|
238
|
+
|
239
|
+
Change
|
240
|
+
<pre><code> response.should be_success</code></pre>
|
241
|
+
|
242
|
+
|
243
|
+
To
|
244
|
+
<pre><code> expect(response).to be_success</code></pre>
|
245
|
+
|
246
|
+
|
247
|
+
Becomes
|
248
|
+
<pre><code> describe 'GET #new' do
|
249
|
+
it "returns http success" do
|
250
|
+
get :new
|
251
|
+
expect(response).to be_success
|
252
|
+
end
|
253
|
+
end
|
254
|
+
</code></pre>
|
255
|
+
|
256
|
+
|
257
|
+
Change
|
258
|
+
<pre><code> response.should be_success</code></pre>
|
259
|
+
|
260
|
+
|
261
|
+
To
|
262
|
+
<pre><code> expect(response).to be_success</code></pre>
|
263
|
+
|
264
|
+
|
265
|
+
Becomes
|
266
|
+
<pre><code> describe 'GET #index' do
|
267
|
+
it "returns http success" do
|
268
|
+
get :index
|
269
|
+
expect(response).to be_success
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
</code></pre>
|
274
|
+
|
275
|
+
|
276
|
+
EXPECTED_CONTENT
|
277
|
+
end
|
278
|
+
|
279
|
+
describe '#content' do
|
280
|
+
it 'includes the Becomes section' do
|
281
|
+
expect(diff_file.content).to eq expected_content
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe '#ending_code' do
|
286
|
+
it 'contains the ending_code' do
|
287
|
+
expect(diff_file.ending_code).to eq DocumentGenerator::Output.no_really_escape(CGI.escapeHTML(ending.rstrip))
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe '#action_type' do
|
292
|
+
it 'outputs correct phrase for action_type' do
|
293
|
+
expect(diff_file.action_type).to eq "Update file"
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe '#markdown_outputs' do
|
298
|
+
it 'has correct markdown outputs' do
|
299
|
+
expect(diff_file.markdown_outputs.first.description).to eq "Change"
|
300
|
+
expect(diff_file.markdown_outputs.first.content).to eq [" response.should be_success"]
|
301
|
+
|
302
|
+
expect(diff_file.markdown_outputs[1].description).to eq "To"
|
303
|
+
expect(diff_file.markdown_outputs[1].content).to eq [" expect(response).to be_success"]
|
304
|
+
|
305
|
+
expect(diff_file.markdown_outputs[2].description).to eq "Becomes"
|
306
|
+
expect(diff_file.markdown_outputs[2].content).to eq [" describe 'GET #new' do", " it \"returns http success\" do", " get :new", " expect(response).to be_success", " end", " end"]
|
307
|
+
|
308
|
+
expect(diff_file.markdown_outputs[3].description).to eq "Change"
|
309
|
+
expect(diff_file.markdown_outputs[3].content).to eq [" response.should be_success"]
|
310
|
+
|
311
|
+
expect(diff_file.markdown_outputs[4].description).to eq "To"
|
312
|
+
expect(diff_file.markdown_outputs[4].content).to eq [" expect(response).to be_success"]
|
313
|
+
|
314
|
+
expect(diff_file.markdown_outputs[5].description).to eq "Becomes"
|
315
|
+
expect(diff_file.markdown_outputs[5].content).to eq [" describe 'GET #index' do", " it \"returns http success\" do", " get :index", " expect(response).to be_success", " end", " end", " end"]
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
184
320
|
context 'when the git diff file has two changes' do
|
185
321
|
let(:type) { 'modified' }
|
186
322
|
let(:file_name) { '/spec/controllers/posts_controller_spec.rb' }
|
@@ -220,7 +356,7 @@ ENDING
|
|
220
356
|
|
221
357
|
let(:expected_content) do
|
222
358
|
<<-EXPECTED_CONTENT
|
223
|
-
Update file `/spec/controllers/posts_controller_spec.rb`
|
359
|
+
###Update file `/spec/controllers/posts_controller_spec.rb`
|
224
360
|
|
225
361
|
Change
|
226
362
|
<pre><code> describe GET new do</code></pre>
|
@@ -240,7 +376,7 @@ To
|
|
240
376
|
|
241
377
|
Becomes
|
242
378
|
<pre><code>describe PostsController do
|
243
|
-
|
379
|
+
|
244
380
|
describe GET new do
|
245
381
|
it returns http success do
|
246
382
|
get new
|
@@ -284,6 +420,9 @@ EXPECTED_CONTENT
|
|
284
420
|
|
285
421
|
expect(diff_file.markdown_outputs[3].description).to eq "To"
|
286
422
|
expect(diff_file.markdown_outputs[3].content).to eq [" get new"]
|
423
|
+
|
424
|
+
expect(diff_file.markdown_outputs[4].description).to eq "Becomes"
|
425
|
+
expect(diff_file.markdown_outputs[4].content).to eq ["describe PostsController do", "", " describe GET new do", " it returns http success do", " get new", " response.should be_success", " end", " end"]
|
287
426
|
end
|
288
427
|
end
|
289
428
|
end
|
@@ -352,7 +491,7 @@ PATCH
|
|
352
491
|
|
353
492
|
let(:expected_content) do
|
354
493
|
<<-EXPECTED_CONTENT
|
355
|
-
Create file `/spec/support/capybara.rb`
|
494
|
+
###Create file `/spec/support/capybara.rb`
|
356
495
|
|
357
496
|
Add
|
358
497
|
<pre><code> Capybara.javascript_driver = :webkit</code></pre>
|
@@ -424,7 +563,7 @@ PATCH
|
|
424
563
|
|
425
564
|
let(:expected_content) do
|
426
565
|
<<-EXPECTED_CONTENT
|
427
|
-
Remove file `/app/helpers/welcome_helper.rb`
|
566
|
+
###Remove file `/app/helpers/welcome_helper.rb`
|
428
567
|
|
429
568
|
EXPECTED_CONTENT
|
430
569
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: document_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wiscoDude
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: addressable
|
@@ -110,6 +110,20 @@ dependencies:
|
|
110
110
|
- - ~>
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0.7'
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: pry
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
type: :development
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
113
127
|
description: |
|
114
128
|
Generate documentation from a git repository.
|
115
129
|
email:
|
@@ -163,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
177
|
version: '0'
|
164
178
|
requirements: []
|
165
179
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.1.
|
180
|
+
rubygems_version: 2.1.11
|
167
181
|
signing_key:
|
168
182
|
specification_version: 4
|
169
183
|
summary: Generate documentation from a git repository.
|