diffy 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of diffy might be problematic. Click here for more details.
- data/README.md +9 -8
- data/VERSION +1 -1
- data/{dirb.gemspec → diffy.gemspec} +2 -2
- data/lib/diffy/html_formatter.rb +17 -9
- data/spec/{dirb_spec.rb → diffy_spec.rb} +30 -12
- metadata +7 -7
data/README.md
CHANGED
@@ -2,9 +2,9 @@ Diffy - Easy Diffing With Ruby
|
|
2
2
|
============================
|
3
3
|
|
4
4
|
Need diffs in your ruby app? Diffy has you covered. It provides a convenient
|
5
|
-
way to generate a diff from two strings. Instead of reimplementing
|
6
|
-
algorithm Diffy uses battle tested Unix diff to generate diffs,
|
7
|
-
providing a convenient interface, and getting out of your way.
|
5
|
+
way to generate a diff from two strings or files. Instead of reimplementing
|
6
|
+
the LCS diff algorithm Diffy uses battle tested Unix diff to generate diffs,
|
7
|
+
and focuses on providing a convenient interface, and getting out of your way.
|
8
8
|
|
9
9
|
Supported Formats
|
10
10
|
-----------------
|
@@ -66,13 +66,14 @@ Then try adding this css to your stylesheets:
|
|
66
66
|
.diff{overflow:auto;}
|
67
67
|
.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
|
68
68
|
.diff del, .diff ins{display:block;text-decoration:none;}
|
69
|
-
.diff li{padding:0; display:table-row;margin: 0;}
|
69
|
+
.diff li{padding:0; display:table-row;margin: 0;height:1em;}
|
70
|
+
.diff li.ins{background:#dfd; color:#080}
|
71
|
+
.diff li.del{background:#fee; color:#b00}
|
72
|
+
.diff li:hover{background:#ffc}
|
70
73
|
/* try 'whitespace:pre;' if you don't want lines to wrap */
|
71
74
|
.diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;}
|
72
|
-
.diff
|
73
|
-
.diff
|
74
|
-
.diff li.ins strong{font-weight:normal; background: #6f6 }
|
75
|
-
.diff li.del strong{font-weight:normal; background: #f99 }
|
75
|
+
.diff del strong{font-weight:normal;background:#fcc;}
|
76
|
+
.diff ins strong{font-weight:normal;background:#9f9;}
|
76
77
|
|
77
78
|
You can also diff files instead of strings
|
78
79
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.1
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{diffy}
|
8
|
-
s.version = "2.0.
|
8
|
+
s.version = "2.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sam Goldstein"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-12-07}
|
13
13
|
s.description = %q{Convenient diffing in ruby}
|
14
14
|
s.email = %q{sgrock@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/diffy/html_formatter.rb
CHANGED
@@ -39,9 +39,8 @@ module Diffy
|
|
39
39
|
chunk1 = chunk1
|
40
40
|
chunk2 = chunks[index + 1]
|
41
41
|
if not chunk2
|
42
|
-
next chunk1
|
42
|
+
next ERB::Util.h(chunk1)
|
43
43
|
end
|
44
|
-
|
45
44
|
chunk1 = ERB::Util.h(chunk1)
|
46
45
|
chunk2 = ERB::Util.h(chunk2)
|
47
46
|
|
@@ -68,23 +67,32 @@ module Diffy
|
|
68
67
|
def split_characters(chunk)
|
69
68
|
chunk.gsub(/^./, '').each_line.map do |line|
|
70
69
|
line.chomp.split('') + ['\n']
|
71
|
-
end.flatten.join("\n")
|
70
|
+
end.flatten.join("\n") + "\n"
|
72
71
|
end
|
73
72
|
|
74
73
|
def reconstruct_characters(line_diff, type)
|
75
|
-
line_diff.each_chunk
|
74
|
+
enum = line_diff.each_chunk
|
75
|
+
enum.each_with_index.map do |l, i|
|
76
76
|
re = /(^|\\n)#{Regexp.escape(type)}/
|
77
77
|
case l
|
78
78
|
when re
|
79
|
-
|
80
|
-
gsub('\n', "</strong>\n<strong>") + "</strong>"
|
79
|
+
highlight(l)
|
81
80
|
when /^ /
|
82
|
-
|
83
|
-
|
81
|
+
if i > 1 and enum.to_a[i+1] and l.each_line.to_a.size < 4
|
82
|
+
highlight(l)
|
83
|
+
else
|
84
|
+
l.gsub(/^./, '').gsub("\n", '').
|
85
|
+
gsub('\r', "\r").gsub('\n', "\n")
|
86
|
+
end
|
84
87
|
end
|
85
88
|
end.join('').split("\n").map do |l|
|
86
|
-
type + l
|
89
|
+
type + l.gsub('</strong><strong>' , '')
|
87
90
|
end
|
88
91
|
end
|
92
|
+
|
93
|
+
def highlight(lines)
|
94
|
+
"<strong>" + lines.gsub(/(^|\\n)./, '').gsub("\n", '').
|
95
|
+
gsub('\n', "</strong>\n<strong>") + "</strong>"
|
96
|
+
end
|
89
97
|
end
|
90
98
|
end
|
@@ -174,6 +174,24 @@ baz
|
|
174
174
|
end
|
175
175
|
|
176
176
|
describe "html" do
|
177
|
+
it "should not allow html injection on the last line" do
|
178
|
+
@string1 = "hahaha\ntime flies like an arrow\nfoo bar\nbang baz\n<script>\n"
|
179
|
+
@string2 = "hahaha\nfruit flies like a banana\nbang baz\n<script>\n"
|
180
|
+
@diff = Diffy::Diff.new(@string1, @string2)
|
181
|
+
html = <<-HTML
|
182
|
+
<div class="diff">
|
183
|
+
<ul>
|
184
|
+
<li class="unchanged"><span>hahaha</span></li>
|
185
|
+
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
|
186
|
+
<li class="del"><del><strong>foo bar</strong></del></li>
|
187
|
+
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
|
188
|
+
<li class="unchanged"><span>bang baz</span></li>
|
189
|
+
<li class="unchanged"><span><script></span></li>
|
190
|
+
</ul>
|
191
|
+
</div>
|
192
|
+
HTML
|
193
|
+
@diff.to_s(:html).should == html
|
194
|
+
end
|
177
195
|
|
178
196
|
it "should highlight the changes within the line" do
|
179
197
|
@string1 = "hahaha\ntime flies like an arrow\nfoo bar\nbang baz\n"
|
@@ -183,9 +201,9 @@ baz
|
|
183
201
|
<div class="diff">
|
184
202
|
<ul>
|
185
203
|
<li class="unchanged"><span>hahaha</span></li>
|
186
|
-
<li class="del"><del><strong>
|
187
|
-
<li class="del"><del><strong>foo
|
188
|
-
<li class="ins"><ins><strong>
|
204
|
+
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
|
205
|
+
<li class="del"><del><strong>foo bar</strong></del></li>
|
206
|
+
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
|
189
207
|
<li class="unchanged"><span>bang baz</span></li>
|
190
208
|
</ul>
|
191
209
|
</div>
|
@@ -201,9 +219,9 @@ baz
|
|
201
219
|
<div class="diff">
|
202
220
|
<ul>
|
203
221
|
<li class="unchanged"><span>hahaha</span></li>
|
204
|
-
<li class="del"><del><strong>
|
205
|
-
<li class="ins"><ins><strong>
|
206
|
-
<li class="ins"><ins><strong>bang
|
222
|
+
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
|
223
|
+
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
|
224
|
+
<li class="ins"><ins><strong>bang baz</strong></ins></li>
|
207
225
|
</ul>
|
208
226
|
</div>
|
209
227
|
HTML
|
@@ -218,9 +236,9 @@ baz
|
|
218
236
|
<div class="diff">
|
219
237
|
<ul>
|
220
238
|
<li class="unchanged"><span>ha<br>haha</span></li>
|
221
|
-
<li class="del"><del><strong>
|
222
|
-
<li class="ins"><ins><strong>
|
223
|
-
<li class="ins"><ins><strong>bang
|
239
|
+
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
|
240
|
+
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
|
241
|
+
<li class="ins"><ins><strong>bang baz</strong></ins></li>
|
224
242
|
</ul>
|
225
243
|
</div>
|
226
244
|
HTML
|
@@ -235,9 +253,9 @@ baz
|
|
235
253
|
<div class="diff">
|
236
254
|
<ul>
|
237
255
|
<li class="unchanged"><span>hahaha</span></li>
|
238
|
-
<li class="del"><del><strong>
|
239
|
-
<li class="del"><del><strong>foo
|
240
|
-
<li class="ins"><ins><strong>
|
256
|
+
<li class="del"><del><strong>time</strong> flies like a<strong>n arrow</strong></del></li>
|
257
|
+
<li class="del"><del><strong>foo bar</strong></del></li>
|
258
|
+
<li class="ins"><ins><strong>fruit</strong> flies like a<strong> banana</strong></ins></li>
|
241
259
|
<li class="unchanged"><span>bang baz</span></li>
|
242
260
|
</ul>
|
243
261
|
</div>
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diffy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 1
|
10
|
+
version: 2.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Goldstein
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-07 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -35,12 +35,12 @@ files:
|
|
35
35
|
- README.md
|
36
36
|
- Rakefile
|
37
37
|
- VERSION
|
38
|
-
-
|
38
|
+
- diffy.gemspec
|
39
39
|
- lib/diffy.rb
|
40
40
|
- lib/diffy/diff.rb
|
41
41
|
- lib/diffy/format.rb
|
42
42
|
- lib/diffy/html_formatter.rb
|
43
|
-
- spec/
|
43
|
+
- spec/diffy_spec.rb
|
44
44
|
has_rdoc: true
|
45
45
|
homepage: http://github.com/samg/diffy/tree/master
|
46
46
|
licenses: []
|
@@ -77,4 +77,4 @@ signing_key:
|
|
77
77
|
specification_version: 3
|
78
78
|
summary: A convenient way to diff string in ruby
|
79
79
|
test_files:
|
80
|
-
- spec/
|
80
|
+
- spec/diffy_spec.rb
|