diffy 2.0.5 → 2.0.6
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/Gemfile +1 -1
- data/README.md +83 -19
- data/VERSION +1 -1
- data/diffy.gemspec +14 -11
- data/lib/diffy.rb +1 -0
- data/lib/diffy/css.rb +17 -0
- data/lib/diffy/diff.rb +16 -1
- data/lib/diffy/format.rb +2 -2
- data/lib/diffy/html_formatter.rb +25 -4
- data/spec/demo_app.rb +46 -0
- data/spec/diffy_spec.rb +101 -5
- metadata +38 -64
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -48,7 +48,11 @@ Here's an example of using Diffy to diff two strings
|
|
48
48
|
-That's great
|
49
49
|
+That's swell
|
50
50
|
|
51
|
-
|
51
|
+
HTML Output
|
52
|
+
---------------
|
53
|
+
|
54
|
+
Outputing the diff as html is easy too. Here's an example using the
|
55
|
+
`:html_simple` formatter.
|
52
56
|
|
53
57
|
>> puts Diffy::Diff.new(string1, string2).to_s(:html_simple)
|
54
58
|
<div class="diff">
|
@@ -61,8 +65,19 @@ Outputing the diff as html is easy too.
|
|
61
65
|
</ul>
|
62
66
|
</div>
|
63
67
|
|
64
|
-
|
68
|
+
The `:html` formatter will give you inline highlighting a la github.
|
69
|
+
|
70
|
+
>> puts Diffy::Diff.new("foo\n", "Foo\n").to_s(:html)
|
71
|
+
<div class="diff">
|
72
|
+
<ul>
|
73
|
+
<li class="del"><del><strong>f</strong>oo</del></li>
|
74
|
+
<li class="ins"><ins><strong>F</strong>oo</ins></li>
|
75
|
+
</ul>
|
76
|
+
</div>
|
65
77
|
|
78
|
+
There's some pretty nice css provided in `Diffy::CSS`.
|
79
|
+
|
80
|
+
>> puts Diffy::CSS
|
66
81
|
.diff{overflow:auto;}
|
67
82
|
.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
|
68
83
|
.diff del, .diff ins{display:block;text-decoration:none;}
|
@@ -77,10 +92,75 @@ Then try adding this css to your stylesheets:
|
|
77
92
|
.diff li.diff-comment { display: none; }
|
78
93
|
.diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
|
79
94
|
|
80
|
-
|
95
|
+
Other Diff Options
|
96
|
+
------------------
|
97
|
+
|
98
|
+
### Diffing files instead of strings
|
99
|
+
|
100
|
+
You can diff files instead of strings by using the `:source` option.
|
81
101
|
|
82
102
|
>> puts Diffy::Diff.new('/tmp/foo', '/tmp/bar', :source => 'files')
|
83
103
|
|
104
|
+
### Full Diff Output
|
105
|
+
|
106
|
+
By default diffy removes the superfluous diff output. This is because its
|
107
|
+
default is to show the complete diff'ed file (`diff -U 10000` is the default).
|
108
|
+
|
109
|
+
Diffy does support full output, just use the `:include_diff_info => true`
|
110
|
+
option when initializing:
|
111
|
+
|
112
|
+
>> Diffy::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n", :include_diff_info => true).to_s(:text)
|
113
|
+
=>--- /Users/chaffeqa/Projects/stiwiki/tmp/diffy20111116-82153-ie27ex 2011-11-16 20:16:41.000000000 -0500
|
114
|
+
+++ /Users/chaffeqa/Projects/stiwiki/tmp/diffy20111116-82153-wzrhw5 2011-11-16 20:16:41.000000000 -0500
|
115
|
+
@@ -1,2 +1,3 @@
|
116
|
+
foo
|
117
|
+
bar
|
118
|
+
+baz
|
119
|
+
|
120
|
+
And even deals a bit with the formatting!
|
121
|
+
|
122
|
+
### Plus and Minus symbols in HTML output
|
123
|
+
|
124
|
+
By default Diffy doesn't include the `+`, `-`, and ` ` at the beginning of line for
|
125
|
+
HTML output.
|
126
|
+
|
127
|
+
You can use the `:include_plus_and_minus_in_html` option to include those
|
128
|
+
symbols in the output.
|
129
|
+
|
130
|
+
>> puts Diffy::Diff.new(string1, string2, :include_plus_and_minus_in_html => true).to_s(:html_simple)
|
131
|
+
<div class="diff">
|
132
|
+
<ul>
|
133
|
+
<li class="del"><del><span class="symbol">-</span>Hello how are you</del></li>
|
134
|
+
<li class="ins"><ins><span class="symbol">+</span>Hello how are you?</ins></li>
|
135
|
+
<li class="unchanged"><span class="symbol"> </span><span>I'm fine</span></li>
|
136
|
+
<li class="del"><del><span class="symbol">-</span>That's great</del></li>
|
137
|
+
<li class="ins"><ins><span class="symbol">+</span>That's swell</ins></li>
|
138
|
+
</ul>
|
139
|
+
</div>
|
140
|
+
|
141
|
+
|
142
|
+
### Overriding the command line options passed to diff.
|
143
|
+
|
144
|
+
You can use the `:diff` option to override the command line options that are
|
145
|
+
passed to unix diff. They default to `-U 10000`.
|
146
|
+
|
147
|
+
>> puts Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :diff => "-w")
|
148
|
+
foo
|
149
|
+
bar
|
150
|
+
|
151
|
+
Default Diff Options
|
152
|
+
--------------------
|
153
|
+
|
154
|
+
You can set the default options for new `Diffy::Diff`s using the
|
155
|
+
`Diffy::Diff.default_options` and `Diffy::Diff.default_options=` methods.
|
156
|
+
Options passed to Diffy::Diff.new will be merged into the default options.
|
157
|
+
|
158
|
+
>> Diffy::Diff.default_options
|
159
|
+
=> {:diff=>"-U 10000", :source=>"strings", :include_diff_info=>false, :include_plus_and_minus_in_html=>false}
|
160
|
+
>> Diffy::Diff.default_options.merge!(:source => 'files')
|
161
|
+
=> {:diff=>"-U 10000", :source=>"files", :include_diff_info=>false, :include_plus_and_minus_in_html=>false}
|
162
|
+
|
163
|
+
|
84
164
|
Custom Formats
|
85
165
|
--------------
|
86
166
|
|
@@ -105,22 +185,6 @@ deletions, and unchanged in a diff.
|
|
105
185
|
|
106
186
|
Use `#map`, `#inject`, or any of Enumerable's methods. Go crazy.
|
107
187
|
|
108
|
-
Full Diff Output
|
109
|
-
----------------
|
110
|
-
|
111
|
-
By default diffy removes the superfluous diff output. This is because its default is to show the complete diff'ed file (`diff -U 1000` is the default).
|
112
|
-
|
113
|
-
Diffy does support full output, just use the `:include_diff_info => true` option when initializing:
|
114
|
-
|
115
|
-
>> Diffy::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n", :include_diff_info => true).to_s(:text)
|
116
|
-
=>--- /Users/chaffeqa/Projects/stiwiki/tmp/diffy20111116-82153-ie27ex 2011-11-16 20:16:41.000000000 -0500
|
117
|
-
+++ /Users/chaffeqa/Projects/stiwiki/tmp/diffy20111116-82153-wzrhw5 2011-11-16 20:16:41.000000000 -0500
|
118
|
-
@@ -1,2 +1,3 @@
|
119
|
-
foo
|
120
|
-
bar
|
121
|
-
+baz
|
122
|
-
|
123
|
-
And even deals a bit with the formatting!
|
124
188
|
|
125
189
|
Ruby Version Compatibility
|
126
190
|
-------------------------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.6
|
data/diffy.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "2.0.
|
7
|
+
s.name = "diffy"
|
8
|
+
s.version = "2.0.6"
|
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 =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2012-03-04"
|
13
|
+
s.description = "Convenient diffing in ruby"
|
14
|
+
s.email = "sgrock@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.md"
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".rspec",
|
21
21
|
"CHANGELOG",
|
22
|
+
"CONTRIBUTORS",
|
22
23
|
"Gemfile",
|
23
24
|
"LICENSE",
|
24
25
|
"README.md",
|
@@ -26,30 +27,32 @@ Gem::Specification.new do |s|
|
|
26
27
|
"VERSION",
|
27
28
|
"diffy.gemspec",
|
28
29
|
"lib/diffy.rb",
|
30
|
+
"lib/diffy/css.rb",
|
29
31
|
"lib/diffy/diff.rb",
|
30
32
|
"lib/diffy/format.rb",
|
31
33
|
"lib/diffy/html_formatter.rb",
|
34
|
+
"spec/demo_app.rb",
|
32
35
|
"spec/diffy_spec.rb"
|
33
36
|
]
|
34
|
-
s.homepage =
|
37
|
+
s.homepage = "http://github.com/samg/diffy/tree/master"
|
35
38
|
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
36
39
|
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version =
|
38
|
-
s.summary =
|
40
|
+
s.rubygems_version = "1.8.10"
|
41
|
+
s.summary = "A convenient way to diff string in ruby"
|
39
42
|
|
40
43
|
if s.respond_to? :specification_version then
|
41
44
|
s.specification_version = 3
|
42
45
|
|
43
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
47
|
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
45
|
-
s.add_development_dependency(%q<rake>, ["
|
48
|
+
s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
|
46
49
|
else
|
47
50
|
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
48
|
-
s.add_dependency(%q<rake>, ["
|
51
|
+
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
49
52
|
end
|
50
53
|
else
|
51
54
|
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
52
|
-
s.add_dependency(%q<rake>, ["
|
55
|
+
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
data/lib/diffy.rb
CHANGED
@@ -10,3 +10,4 @@ module Diffy; end
|
|
10
10
|
require File.join(File.dirname(__FILE__), 'diffy', 'format')
|
11
11
|
require File.join(File.dirname(__FILE__), 'diffy', 'html_formatter')
|
12
12
|
require File.join(File.dirname(__FILE__), 'diffy', 'diff')
|
13
|
+
require File.join(File.dirname(__FILE__), 'diffy', 'css')
|
data/lib/diffy/css.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Diffy
|
2
|
+
CSS = <<-STYLE
|
3
|
+
.diff{overflow:auto;}
|
4
|
+
.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
|
5
|
+
.diff del, .diff ins{display:block;text-decoration:none;}
|
6
|
+
.diff li{padding:0; display:table-row;margin: 0;height:1em;}
|
7
|
+
.diff li.ins{background:#dfd; color:#080}
|
8
|
+
.diff li.del{background:#fee; color:#b00}
|
9
|
+
.diff li:hover{background:#ffc}
|
10
|
+
/* try 'whitespace:pre;' if you don't want lines to wrap */
|
11
|
+
.diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;}
|
12
|
+
.diff del strong{font-weight:normal;background:#fcc;}
|
13
|
+
.diff ins strong{font-weight:normal;background:#9f9;}
|
14
|
+
.diff li.diff-comment { display: none; }
|
15
|
+
.diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
|
16
|
+
STYLE
|
17
|
+
end
|
data/lib/diffy/diff.rb
CHANGED
@@ -5,6 +5,18 @@ module Diffy
|
|
5
5
|
def default_format
|
6
6
|
@default_format || :text
|
7
7
|
end
|
8
|
+
|
9
|
+
attr_writer :default_options
|
10
|
+
# default options passed to new Diff objects
|
11
|
+
def default_options
|
12
|
+
@default_options ||= {
|
13
|
+
:diff => '-U 10000',
|
14
|
+
:source => 'strings',
|
15
|
+
:include_diff_info => false,
|
16
|
+
:include_plus_and_minus_in_html => false
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
8
20
|
end
|
9
21
|
include Enumerable
|
10
22
|
attr_reader :string1, :string2, :options, :diff
|
@@ -13,8 +25,11 @@ module Diffy
|
|
13
25
|
# +:diff+:: A cli options string passed to diff
|
14
26
|
# +:source+:: Either _strings_ or _files_. Determines whether string1
|
15
27
|
# and string2 should be interpreted as strings or file paths.
|
28
|
+
# +:include_diff_info+:: Include diff header info
|
29
|
+
# +:include_plus_and_minus_in_html+:: Show the +, -, ' ' at the
|
30
|
+
# beginning of lines in html output.
|
16
31
|
def initialize(string1, string2, options = {})
|
17
|
-
@options =
|
32
|
+
@options = self.class.default_options.merge(options)
|
18
33
|
if ! ['strings', 'files'].include?(@options[:source])
|
19
34
|
raise ArgumentError, "Invalid :source option #{@options[:source].inspect}. Supported options are 'strings' and 'files'."
|
20
35
|
end
|
data/lib/diffy/format.rb
CHANGED
@@ -26,12 +26,12 @@ module Diffy
|
|
26
26
|
# Basic html output which does not attempt to highlight the changes
|
27
27
|
# between lines, and is more performant.
|
28
28
|
def html_simple
|
29
|
-
HtmlFormatter.new(self).to_s
|
29
|
+
HtmlFormatter.new(self, options).to_s
|
30
30
|
end
|
31
31
|
|
32
32
|
# Html output which does inline highlighting of changes between two lines.
|
33
33
|
def html
|
34
|
-
HtmlFormatter.new(self, :highlight_words => true).to_s
|
34
|
+
HtmlFormatter.new(self, options.merge(:highlight_words => true)).to_s
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/diffy/html_formatter.rb
CHANGED
@@ -15,7 +15,7 @@ module Diffy
|
|
15
15
|
|
16
16
|
private
|
17
17
|
def wrap_line(line)
|
18
|
-
cleaned = line
|
18
|
+
cleaned = clean_line(line)
|
19
19
|
case line
|
20
20
|
when /^(---|\+\+\+|\\\\)/
|
21
21
|
' <li class="diff-comment"><span>' + line.chomp + '</span></li>'
|
@@ -30,12 +30,23 @@ module Diffy
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
# remove +/- or wrap in html
|
34
|
+
def clean_line(line)
|
35
|
+
if @options[:include_plus_and_minus_in_html]
|
36
|
+
line.gsub(/^(.)/, '<span class="symbol">\1</span>')
|
37
|
+
else
|
38
|
+
line.gsub(/^./, '')
|
39
|
+
end.chomp
|
40
|
+
end
|
41
|
+
|
33
42
|
def wrap_lines(lines)
|
34
43
|
%'<div class="diff">\n <ul>\n#{lines.join("\n")}\n </ul>\n</div>\n'
|
35
44
|
end
|
36
45
|
|
37
46
|
def highlighted_words
|
38
|
-
chunks = @diff.each_chunk.
|
47
|
+
chunks = @diff.each_chunk.
|
48
|
+
reject{|c| c == ''"\n"}
|
49
|
+
|
39
50
|
processed = []
|
40
51
|
lines = chunks.each_with_index.map do |chunk1, index|
|
41
52
|
next if processed.include? index
|
@@ -93,8 +104,18 @@ module Diffy
|
|
93
104
|
end
|
94
105
|
|
95
106
|
def highlight(lines)
|
96
|
-
"<strong>" +
|
97
|
-
|
107
|
+
"<strong>" +
|
108
|
+
lines.
|
109
|
+
# strip diff tokens (e.g. +,-,etc.)
|
110
|
+
gsub(/(^|\\n)./, '').
|
111
|
+
# mark line boundaries from higher level line diff
|
112
|
+
# html is all escaped so using brackets should make this safe.
|
113
|
+
gsub('\n', '<LINE_BOUNDARY>').
|
114
|
+
# join characters back by stripping out newlines
|
115
|
+
gsub("\n", '').
|
116
|
+
# close and reopen strong tags. we don't want inline elements
|
117
|
+
# spanning block elements which get added later.
|
118
|
+
gsub('<LINE_BOUNDARY>',"</strong>\n<strong>") + "</strong>"
|
98
119
|
end
|
99
120
|
end
|
100
121
|
end
|
data/spec/demo_app.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'json'
|
4
|
+
require File.dirname(__FILE__) + '/../lib/diffy'
|
5
|
+
|
6
|
+
blk = proc do
|
7
|
+
Diffy::Diff.default_options.merge! JSON.parse(params[:options]) rescue {}
|
8
|
+
haml "- d = Diffy::Diff.new(params[:one].to_s, params[:two].to_s)\n%div= d.to_s(:html)\n%pre= d.to_s"
|
9
|
+
end
|
10
|
+
post '/', &blk
|
11
|
+
get '/', &blk
|
12
|
+
__END__
|
13
|
+
|
14
|
+
@@ layout
|
15
|
+
%html
|
16
|
+
%head
|
17
|
+
:css
|
18
|
+
.diff{overflow:auto;}
|
19
|
+
.diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
|
20
|
+
.diff del, .diff ins{display:block;text-decoration:none;}
|
21
|
+
.diff li{padding:0; display:table-row;margin: 0;height:1em;}
|
22
|
+
.diff li.ins{background:#dfd; color:#080}
|
23
|
+
.diff li.del{background:#fee; color:#b00}
|
24
|
+
.diff li:hover{background:#ffc}
|
25
|
+
.diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;}
|
26
|
+
.diff del strong{font-weight:normal;background:#fcc;}
|
27
|
+
.diff ins strong{font-weight:normal;background:#9f9;}
|
28
|
+
.diff li.diff-comment { display: none; }
|
29
|
+
.diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
|
30
|
+
%body
|
31
|
+
= yield
|
32
|
+
%form{:action => '', :method => 'post'}
|
33
|
+
%label JSON diff options
|
34
|
+
%textarea{:name => 'options', :style => 'width:100%;height:250px;'}= params[:options]
|
35
|
+
%label One
|
36
|
+
%textarea{:name => 'one', :style => 'width:100%;height:250px;'}= params[:one]
|
37
|
+
%br/
|
38
|
+
%label Two
|
39
|
+
%textarea{:name => 'two', :style => 'width:100%;height:250px;'}= params[:two]
|
40
|
+
%br/
|
41
|
+
%input{:type => 'submit'}
|
42
|
+
%br/
|
43
|
+
|
44
|
+
@@ index
|
45
|
+
%div.title Hello world!!!!!
|
46
|
+
|
data/spec/diffy_spec.rb
CHANGED
@@ -54,26 +54,72 @@ describe Diffy::Diff do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
|
57
58
|
end
|
58
|
-
|
59
|
+
|
60
|
+
describe "options[:include_plus_and_minus_in_html]" do
|
61
|
+
it "defaults to false" do
|
62
|
+
@diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n")
|
63
|
+
@diffy.options[:include_plus_and_minus_in_html].should == false
|
64
|
+
end
|
65
|
+
|
66
|
+
it "can be set to true" do
|
67
|
+
@diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :include_plus_and_minus_in_html=> true )
|
68
|
+
@diffy.options[:include_plus_and_minus_in_html].should == true
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "formats" do
|
72
|
+
it "includes symbols in html_simple" do
|
73
|
+
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_plus_and_minus_in_html => true ).
|
74
|
+
to_s(:html_simple)
|
75
|
+
output.should == <<-HTML
|
76
|
+
<div class="diff">
|
77
|
+
<ul>
|
78
|
+
<li class="unchanged"><span><span class="symbol"> </span>foo</span></li>
|
79
|
+
<li class="del"><del><span class="symbol">-</span>bar</del></li>
|
80
|
+
<li class="unchanged"><span><span class="symbol"> </span>bang</span></li>
|
81
|
+
</ul>
|
82
|
+
</div>
|
83
|
+
HTML
|
84
|
+
end
|
85
|
+
|
86
|
+
it "includes symbols in html" do
|
87
|
+
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\naba\nbang\n", :include_plus_and_minus_in_html => true ).
|
88
|
+
to_s(:html)
|
89
|
+
output.should == <<-HTML
|
90
|
+
<div class="diff">
|
91
|
+
<ul>
|
92
|
+
<li class="unchanged"><span><span class="symbol"> </span>foo</span></li>
|
93
|
+
<li class="del"><del><span class="symbol">-</span>ba<strong>r</strong></del></li>
|
94
|
+
<li class="ins"><ins><span class="symbol">+</span><strong>a</strong>ba</ins></li>
|
95
|
+
<li class="unchanged"><span><span class="symbol"> </span>bang</span></li>
|
96
|
+
</ul>
|
97
|
+
</div>
|
98
|
+
HTML
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
59
105
|
describe "options[:include_diff_info]" do
|
60
106
|
it "defaults to false" do
|
61
107
|
@diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n")
|
62
108
|
@diffy.options[:include_diff_info].should == false
|
63
109
|
end
|
64
|
-
|
110
|
+
|
65
111
|
it "can be set to true" do
|
66
112
|
@diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :include_diff_info => true )
|
67
113
|
@diffy.options[:include_diff_info].should == true
|
68
114
|
end
|
69
|
-
|
115
|
+
|
70
116
|
it "includes all diff output" do
|
71
117
|
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_diff_info => true ).to_s
|
72
118
|
output.to_s.should match( /@@/)
|
73
119
|
output.should match( /---/)
|
74
120
|
output.should match( /\+\+\+/)
|
75
121
|
end
|
76
|
-
|
122
|
+
|
77
123
|
describe "formats" do
|
78
124
|
it "works for :color" do
|
79
125
|
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_diff_info => true ).to_s(:color)
|
@@ -81,7 +127,7 @@ describe Diffy::Diff do
|
|
81
127
|
output.to_s.should match( /\e\[90m---/)
|
82
128
|
output.to_s.should match( /\e\[0m\n\e\[90m\+\+\+/)
|
83
129
|
end
|
84
|
-
|
130
|
+
|
85
131
|
it "works for :html_simple" do
|
86
132
|
output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_diff_info => true ).to_s(:html_simple)
|
87
133
|
output.split("\n").should include( " <li class=\"diff-block-info\"><span>@@ -1,3 +1,2 @@</span></li>" )
|
@@ -152,6 +198,14 @@ describe Diffy::Diff do
|
|
152
198
|
Diffy::Diff.default_format = old_format
|
153
199
|
end
|
154
200
|
|
201
|
+
it "should accept a default options" do
|
202
|
+
old_options = Diffy::Diff.default_options
|
203
|
+
Diffy::Diff.default_options = old_options.merge(:include_diff_info => true)
|
204
|
+
Diffy::Diff.new(@string1, @string2).to_s.
|
205
|
+
should include('@@ -1,3 +1,2 @@')
|
206
|
+
Diffy::Diff.default_options = old_options
|
207
|
+
end
|
208
|
+
|
155
209
|
it "should show one line added" do
|
156
210
|
Diffy::Diff.new(@string2, @string1).to_s.
|
157
211
|
should == <<-DIFF
|
@@ -349,6 +403,41 @@ baz
|
|
349
403
|
HTML
|
350
404
|
@diff.to_s(:html).should == html
|
351
405
|
end
|
406
|
+
|
407
|
+
describe 'with lines that include \n' do
|
408
|
+
before do
|
409
|
+
string1 = 'a\nb'"\n"
|
410
|
+
|
411
|
+
string2 = 'acb'"\n"
|
412
|
+
@string1, @string2 = string1, string2
|
413
|
+
end
|
414
|
+
|
415
|
+
it "should not leave lines out" do
|
416
|
+
Diffy::Diff.new(@string1, @string2 ).to_s(:html).should == <<-DIFF
|
417
|
+
<div class="diff">
|
418
|
+
<ul>
|
419
|
+
<li class="del"><del>a<strong>\\n</strong>b</del></li>
|
420
|
+
<li class="ins"><ins>a<strong>c</strong>b</ins></li>
|
421
|
+
</ul>
|
422
|
+
</div>
|
423
|
+
DIFF
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
it "should do highlighting on the last line when there's no trailing newlines" do
|
428
|
+
s1 = "foo\nbar\nbang"
|
429
|
+
s2 = "foo\nbar\nbangleize"
|
430
|
+
Diffy::Diff.new(s1,s2).to_s(:html).should == <<-DIFF
|
431
|
+
<div class="diff">
|
432
|
+
<ul>
|
433
|
+
<li class="unchanged"><span>foo</span></li>
|
434
|
+
<li class="unchanged"><span>bar</span></li>
|
435
|
+
<li class="del"><del>bang</del></li>
|
436
|
+
<li class="ins"><ins>bang<strong>leize</strong></ins></li>
|
437
|
+
</ul>
|
438
|
+
</div>
|
439
|
+
DIFF
|
440
|
+
end
|
352
441
|
end
|
353
442
|
|
354
443
|
it "should escape diffed html in html output" do
|
@@ -377,6 +466,13 @@ baz
|
|
377
466
|
line
|
378
467
|
end.should == [" foo\n", " bar\n", "+baz\n"]
|
379
468
|
end
|
469
|
+
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
describe 'Diffy::CSS' do
|
474
|
+
it "should be some css" do
|
475
|
+
Diffy::CSS.should include 'diff{overflow:auto;}'
|
380
476
|
end
|
381
477
|
end
|
382
478
|
|
metadata
CHANGED
@@ -1,64 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: diffy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.6
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
- 5
|
10
|
-
version: 2.0.5
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Sam Goldstein
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-03-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rspec
|
23
|
-
|
16
|
+
requirement: &70147571059540 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
18
|
+
requirements:
|
26
19
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 2
|
31
|
-
- 0
|
32
|
-
version: "2.0"
|
33
|
-
prerelease: false
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.0'
|
34
22
|
type: :development
|
35
|
-
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70147571059540
|
25
|
+
- !ruby/object:Gem::Dependency
|
37
26
|
name: rake
|
38
|
-
|
27
|
+
requirement: &70147571058940 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
- 8
|
47
|
-
- 7
|
48
|
-
version: 0.8.7
|
49
|
-
prerelease: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.2
|
50
33
|
type: :development
|
51
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70147571058940
|
52
36
|
description: Convenient diffing in ruby
|
53
37
|
email: sgrock@gmail.com
|
54
38
|
executables: []
|
55
|
-
|
56
39
|
extensions: []
|
57
|
-
|
58
|
-
extra_rdoc_files:
|
40
|
+
extra_rdoc_files:
|
59
41
|
- LICENSE
|
60
42
|
- README.md
|
61
|
-
files:
|
43
|
+
files:
|
62
44
|
- .rspec
|
63
45
|
- CHANGELOG
|
64
46
|
- CONTRIBUTORS
|
@@ -69,44 +51,36 @@ files:
|
|
69
51
|
- VERSION
|
70
52
|
- diffy.gemspec
|
71
53
|
- lib/diffy.rb
|
54
|
+
- lib/diffy/css.rb
|
72
55
|
- lib/diffy/diff.rb
|
73
56
|
- lib/diffy/format.rb
|
74
57
|
- lib/diffy/html_formatter.rb
|
58
|
+
- spec/demo_app.rb
|
75
59
|
- spec/diffy_spec.rb
|
76
|
-
has_rdoc: true
|
77
60
|
homepage: http://github.com/samg/diffy/tree/master
|
78
61
|
licenses: []
|
79
|
-
|
80
62
|
post_install_message:
|
81
|
-
rdoc_options:
|
63
|
+
rdoc_options:
|
82
64
|
- --inline-source
|
83
65
|
- --charset=UTF-8
|
84
|
-
require_paths:
|
66
|
+
require_paths:
|
85
67
|
- lib
|
86
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
69
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
|
93
|
-
- 0
|
94
|
-
version: "0"
|
95
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
75
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
version: "0"
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
104
80
|
requirements: []
|
105
|
-
|
106
81
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.8.10
|
108
83
|
signing_key:
|
109
84
|
specification_version: 3
|
110
85
|
summary: A convenient way to diff string in ruby
|
111
86
|
test_files: []
|
112
|
-
|