diffy 1.1.0
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/.gitignore +2 -0
- data/CHANGELOG +5 -0
- data/LICENSE +19 -0
- data/README.md +92 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/dirb.gemspec +49 -0
- data/spec/diffy_spec.rb +155 -0
- metadata +76 -0
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 Sam Goldstein
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
Diffy - Easy Diffing With Ruby
|
2
|
+
============================
|
3
|
+
|
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 the LCS diff
|
6
|
+
algorithm Diffy uses battle tested Unix diff to generate diffs, and focuses on
|
7
|
+
providing a convenient interface, and getting out of your way.
|
8
|
+
|
9
|
+
It provides several built in format options. Pass `:text`, `:color`, or
|
10
|
+
`:html` to `Diffy::Diff#to_s` to force that format, or set
|
11
|
+
`Diffy::Diff.default_format`
|
12
|
+
|
13
|
+
Getting Started
|
14
|
+
---------------
|
15
|
+
|
16
|
+
sudo gem install diffy
|
17
|
+
|
18
|
+
Here's an example of using Diffy to diff two strings
|
19
|
+
|
20
|
+
$ irb
|
21
|
+
>> string1 = <<-TXT
|
22
|
+
>" Hello how are you
|
23
|
+
>" I'm fine
|
24
|
+
>" That's great
|
25
|
+
>" TXT
|
26
|
+
=> "Hello how are you\nI'm fine\nThat's great\n"
|
27
|
+
>> string2 = <<-TXT
|
28
|
+
>" Hello how are you?
|
29
|
+
>" I'm fine
|
30
|
+
>" That's swell
|
31
|
+
>" TXT
|
32
|
+
=> "Hello how are you?\nI'm fine\nThat's swell\n"
|
33
|
+
>> puts Diffy::Diff.new(string1, string2)
|
34
|
+
-Hello how are you
|
35
|
+
+Hello how are you?
|
36
|
+
I'm fine
|
37
|
+
-That's great
|
38
|
+
+That's swell
|
39
|
+
|
40
|
+
Outputing the diff as html is easy too.
|
41
|
+
|
42
|
+
>> puts Diffy::Diff.new(string1, string2).to_s(:html)
|
43
|
+
<div class="diff">
|
44
|
+
<ul>
|
45
|
+
<li class="del"><del>Hello how are you</del></li>
|
46
|
+
<li class="ins"><ins>Hello how are you?</ins></li>
|
47
|
+
<li class="unchanged"><span>I'm fine</span></li>
|
48
|
+
<li class="del"><del>That's great</del></li>
|
49
|
+
<li class="ins"><ins>That's swell</ins></li>
|
50
|
+
</ul>
|
51
|
+
</div>
|
52
|
+
|
53
|
+
Then try adding this css to your stylesheets:
|
54
|
+
|
55
|
+
.diff{overflow:auto;}
|
56
|
+
.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
|
57
|
+
.diff del, .diff ins{display:block;text-decoration:none;}
|
58
|
+
.diff li{padding:0; display:table-row;margin: 0;}
|
59
|
+
.diff li.ins{background:#9f9;}
|
60
|
+
.diff li.del{background:#ccf;}
|
61
|
+
.diff li:hover{background:#ffc}
|
62
|
+
.diff del, .diff ins, .diff span{white-space:pre;font-family:courier;}
|
63
|
+
|
64
|
+
`Diffy::Diff` also alows you to set a default format. Here we set the default to
|
65
|
+
use ANSI termnial color escape sequences.
|
66
|
+
|
67
|
+
>> Diffy::Diff.default_format = :color
|
68
|
+
=> :color
|
69
|
+
>> puts Diffy::Diff.new(string1, string2) # prints color in the terminal
|
70
|
+
-Hello how are you
|
71
|
+
+Hello how are you?
|
72
|
+
I'm fine
|
73
|
+
-That's great
|
74
|
+
+That's swell
|
75
|
+
|
76
|
+
|
77
|
+
Creating custom formatted output is easy too. `Diffy::Diff` provides an
|
78
|
+
enumberable interface which lets you iterate over lines in the diff.
|
79
|
+
|
80
|
+
>> Diffy::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").each do |line|
|
81
|
+
>* case line
|
82
|
+
>> when /^\+/ then puts "line #{line.chomp} added"
|
83
|
+
>> when /^-/ then puts "line #{line.chomp} removed"
|
84
|
+
>> end
|
85
|
+
>> end
|
86
|
+
line +baz added
|
87
|
+
=> [" foo\n", " bar\n", "+baz\n"]
|
88
|
+
|
89
|
+
Use `#map`, `#inject`, or any of Enumerable's methods. Go crazy.
|
90
|
+
|
91
|
+
Report bugs or request features at http://github.com/samg/Diffy/issues
|
92
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec/rake/spectask'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc "Run all specs in spec directory"
|
8
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
9
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
10
|
+
t.spec_opts = %w{--color --format profile}
|
11
|
+
end
|
12
|
+
|
13
|
+
Rake::RDocTask.new do |rd|
|
14
|
+
rd.main = "README"
|
15
|
+
rd.rdoc_dir = 'doc'
|
16
|
+
rd.rdoc_files.include("README", "**/*.rb")
|
17
|
+
end
|
18
|
+
|
19
|
+
begin
|
20
|
+
require 'jeweler'
|
21
|
+
Jeweler::Tasks.new do |s|
|
22
|
+
s.name = %q{diffy}
|
23
|
+
|
24
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
25
|
+
s.authors = ["Sam Goldstein"]
|
26
|
+
s.date = %q{2010-06-28}
|
27
|
+
s.description = %q{Convenient diffing in ruby}
|
28
|
+
s.email = %q{sgrock@gmail.com}
|
29
|
+
s.has_rdoc = true
|
30
|
+
s.homepage = "http://github.com/samg/diffy/tree/master"
|
31
|
+
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.summary = %q{A convenient way to diff string in ruby}
|
34
|
+
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
38
|
+
end
|
39
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.0
|
data/dirb.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{diffy}
|
8
|
+
s.version = "1.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Sam Goldstein"]
|
12
|
+
s.date = %q{2010-10-15}
|
13
|
+
s.description = %q{Convenient diffing in ruby}
|
14
|
+
s.email = %q{sgrock@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"CHANGELOG",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"diffy.gemspec",
|
27
|
+
"lib/diffy.rb",
|
28
|
+
"spec/diffy_spec.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/samg/diffy/tree/master}
|
31
|
+
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
|
+
s.summary = %q{A convenient way to diff string in ruby}
|
35
|
+
s.test_files = [
|
36
|
+
"spec/diffy_spec.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
else
|
45
|
+
end
|
46
|
+
else
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
data/spec/diffy_spec.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'diffy')
|
3
|
+
|
4
|
+
describe Diffy::Diff do
|
5
|
+
describe "#to_s" do
|
6
|
+
describe "with no line different" do
|
7
|
+
before do
|
8
|
+
@string1 = "foo\nbar\nbang\n"
|
9
|
+
@string2 = "foo\nbar\nbang\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should show everything" do
|
13
|
+
Diffy::Diff.new(@string1, @string2).to_s.should == <<-DIFF
|
14
|
+
foo
|
15
|
+
bar
|
16
|
+
bang
|
17
|
+
DIFF
|
18
|
+
end
|
19
|
+
end
|
20
|
+
describe "with one line different" do
|
21
|
+
before do
|
22
|
+
@string1 = "foo\nbar\nbang\n"
|
23
|
+
@string2 = "foo\nbang\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should show one line removed" do
|
27
|
+
Diffy::Diff.new(@string1, @string2).to_s.should == <<-DIFF
|
28
|
+
foo
|
29
|
+
-bar
|
30
|
+
bang
|
31
|
+
DIFF
|
32
|
+
end
|
33
|
+
|
34
|
+
it "to_s should accept a format key" do
|
35
|
+
Diffy::Diff.new(@string1, @string2).to_s(:color).
|
36
|
+
should == " foo\n\e[31m-bar\e[0m\n bang\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should accept a default format option" do
|
40
|
+
old_format = Diffy::Diff.default_format
|
41
|
+
Diffy::Diff.default_format = :color
|
42
|
+
Diffy::Diff.new(@string1, @string2).to_s.
|
43
|
+
should == " foo\n\e[31m-bar\e[0m\n bang\n"
|
44
|
+
Diffy::Diff.default_format = old_format
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should show one line added" do
|
48
|
+
Diffy::Diff.new(@string2, @string1).to_s.should == <<-DIFF
|
49
|
+
foo
|
50
|
+
+bar
|
51
|
+
bang
|
52
|
+
DIFF
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "with one line changed" do
|
57
|
+
before do
|
58
|
+
@string1 = "foo\nbar\nbang\n"
|
59
|
+
@string2 = "foo\nbong\nbang\n"
|
60
|
+
end
|
61
|
+
it "should show one line added and one removed" do
|
62
|
+
Diffy::Diff.new(@string1, @string2).to_s.should == <<-DIFF
|
63
|
+
foo
|
64
|
+
-bar
|
65
|
+
+bong
|
66
|
+
bang
|
67
|
+
DIFF
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "with totally different strings" do
|
72
|
+
before do
|
73
|
+
@string1 = "foo\nbar\nbang\n"
|
74
|
+
@string2 = "one\ntwo\nthree\n"
|
75
|
+
end
|
76
|
+
it "should show one line added and one removed" do
|
77
|
+
Diffy::Diff.new(@string1, @string2).to_s.should == <<-DIFF
|
78
|
+
-foo
|
79
|
+
-bar
|
80
|
+
-bang
|
81
|
+
+one
|
82
|
+
+two
|
83
|
+
+three
|
84
|
+
DIFF
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "with a somewhat complicated diff" do
|
89
|
+
before do
|
90
|
+
@string1 = "foo\nbar\nbang\nwoot\n"
|
91
|
+
@string2 = "one\ntwo\nthree\nbar\nbang\nbaz\n"
|
92
|
+
@diff = Diffy::Diff.new(@string1, @string2)
|
93
|
+
end
|
94
|
+
it "should show one line added and one removed" do
|
95
|
+
@diff.to_s.should == <<-DIFF
|
96
|
+
-foo
|
97
|
+
+one
|
98
|
+
+two
|
99
|
+
+three
|
100
|
+
bar
|
101
|
+
bang
|
102
|
+
-woot
|
103
|
+
+baz
|
104
|
+
DIFF
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should make an awesome html diff" do
|
108
|
+
@diff.to_s(:html).should == <<-HTML
|
109
|
+
<div class="diff">
|
110
|
+
<ul>
|
111
|
+
<li class="del"><del>foo</del></li>
|
112
|
+
<li class="ins"><ins>one</ins></li>
|
113
|
+
<li class="ins"><ins>two</ins></li>
|
114
|
+
<li class="ins"><ins>three</ins></li>
|
115
|
+
<li class="unchanged"><span>bar</span></li>
|
116
|
+
<li class="unchanged"><span>bang</span></li>
|
117
|
+
<li class="del"><del>woot</del></li>
|
118
|
+
<li class="ins"><ins>baz</ins></li>
|
119
|
+
</ul>
|
120
|
+
</div>
|
121
|
+
HTML
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should accept overrides to diff's options" do
|
125
|
+
@diff = Diffy::Diff.new(@string1, @string2, "--rcs")
|
126
|
+
@diff.to_s.should == <<-DIFF
|
127
|
+
d1 1
|
128
|
+
a1 3
|
129
|
+
one
|
130
|
+
two
|
131
|
+
three
|
132
|
+
d4 1
|
133
|
+
a4 1
|
134
|
+
baz
|
135
|
+
DIFF
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should escape diffed html in html output" do
|
140
|
+
diff = Diffy::Diff.new("<script>alert('bar')</script>", "<script>alert('foo')</script>").to_s(:html)
|
141
|
+
diff.should include('<script>')
|
142
|
+
diff.should_not include('<script>')
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should be easy to generate custom format" do
|
146
|
+
Diffy::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").map do |line|
|
147
|
+
case line
|
148
|
+
when /^\+/ then "line #{line.chomp} added"
|
149
|
+
when /^-/ then "line #{line.chomp} removed"
|
150
|
+
end
|
151
|
+
end.compact.join.should == "line +baz added"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: diffy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sam Goldstein
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-22 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Convenient diffing in ruby
|
23
|
+
email: sgrock@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.md
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- CHANGELOG
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- VERSION
|
38
|
+
- dirb.gemspec
|
39
|
+
- spec/diffy_spec.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/samg/diffy/tree/master
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --inline-source
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.7
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: A convenient way to diff string in ruby
|
75
|
+
test_files:
|
76
|
+
- spec/diffy_spec.rb
|