diffy 3.0.7 → 3.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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cd5d2b187c4063456f8a018845cfa199d09b345
4
- data.tar.gz: 9e83a4e588db04b655db5c64c30e8fda39201b4b
3
+ metadata.gz: 926beeabce14fc2e5d5faa98b5ce2254d41fc9c4
4
+ data.tar.gz: 3d6f3d718606ab9d2a264b6e2d32285f164fd047
5
5
  SHA512:
6
- metadata.gz: b031cbc1697f4334aa62df5eff024c51e89546225f386a38345feac5e73590bb7992862032c7fd99741a0c1e4fb47e7819c06348b72a7efbc70d88ce46172ec5
7
- data.tar.gz: e524bece45facd115127d8f1a8814f0b8acc94b77e54caa87931312db00693d8ab55ebff76c00321733d13f04c8635d3d242c11389881f1ff83ad3a3748fe64a
6
+ metadata.gz: e2b63ca155a9eaa8360a2f17cb259aaf208ac1c7e84c36b1c7451a9bd0ebdbca4b110e12d286f7584018e011a6eed36eee520a2f5a44419300d0ba336acd8cb0
7
+ data.tar.gz: 6692ef85960a14e3e21e336760eb085991aa1bd480544146ec18241b3e2919807160f0e0e74cb60bda6c7f8bbab3de4b571379de79b80b8cff0759a5d8d84400
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ == 3.1.0 ==
2
+ Side by side diffs. Thanks Runar Skaare Tveiten!
3
+
1
4
  == 3.0.5 ==
2
5
  Improve performance when generating html output (with inline highlighting) on
3
6
  long lines. Thanks Jason Barnabe!
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Diffy - Easy Diffing With Ruby [![Build Status](https://secure.travis-ci.org/samg/diffy.png)](http://travis-ci.org/samg/diffy)
1
+ Diffy - Easy Diffing With Ruby [![Build Status](https://travis-ci.org/samg/diffy.svg?branch=master)](https://travis-ci.org/samg/diffy)
2
2
  ============================
3
3
 
4
4
  Need diffs in your ruby app? Diffy has you covered. It provides a convenient
@@ -126,6 +126,81 @@ There's some pretty nice css provided in `Diffy::CSS`.
126
126
  .diff li.diff-comment { display: none; }
127
127
  .diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
128
128
 
129
+
130
+ There's also a colorblind-safe version of the pallete provided in `Diffy::CSS_COLORBLIND_1`.
131
+
132
+
133
+ Side-by-side comparisons
134
+ ------------------------
135
+
136
+ Side-by-side comparisons, or split views as called by some, are supported by
137
+ using the `Diffy::SplitDiff` class. This class takes a diff returned from
138
+ `Diffy::Diff` and splits it in two parts (or two sides): left and right. The
139
+ left side represents deletions while the right side represents insertions.
140
+
141
+ The class is used as follows:
142
+
143
+ ```
144
+ Diffy::SplitDiff.new(string1, string2, options = {})
145
+ ```
146
+
147
+ The optional options hash is passed along to the main `Diff::Diff` class, so
148
+ all default options such as full diff output are supported. The output format
149
+ may be changed by passing the format with the options hash (see below), and all
150
+ default formats are supported.
151
+
152
+ Unlinke `Diffy::Diff`, `Diffy::SplitDiff` does not use `#to_s` to output
153
+ the resulting diff. Instead, two self-explanatory methods are used to output
154
+ the diff; `#left` and `#right`. Using the earlier example, this is what they
155
+ look like in action:
156
+
157
+ ```
158
+ >> puts Diffy::SplitDiff.new(string1, string2).left
159
+ -Hello how are you
160
+ I'm fine
161
+ -That's great
162
+ ```
163
+
164
+ ```
165
+ >> puts Diffy::SplitDiff.new(string1, string2).right
166
+ +Hello how are you?
167
+ I'm fine
168
+ +That's swell
169
+ ```
170
+
171
+ ### Changing the split view output format
172
+
173
+ The output format may be changed by passing the format with the options hash:
174
+
175
+ ```
176
+ Diffy::SplitDiff.new(string1, string2, :format => :html)
177
+ ```
178
+
179
+ This will result in the following:
180
+
181
+ ```
182
+ >> puts Diffy::SplitDiff.new(string1, string2, :format => :html).left
183
+ <div class="diff">
184
+ <ul>
185
+ <li class="del"><del>Hello how are you</del></li>
186
+ <li class="unchanged"><span>I&#39;m fine</span></li>
187
+ <li class="del"><del>That&#39;s <strong>great</strong></del></li>
188
+ </ul>
189
+ </div>
190
+ ```
191
+
192
+ ```
193
+ >> puts Diffy::SplitDiff.new(string1, string2, :format => :html).right
194
+ <div class="diff">
195
+ <ul>
196
+ <li class="ins"><ins>Hello how are you<strong>?</strong></ins></li>
197
+ <li class="unchanged"><span>I&#39;m fine</span></li>
198
+ <li class="ins"><ins>That&#39;s <strong>swell</strong></ins></li>
199
+ </ul>
200
+ </div>
201
+ ```
202
+
203
+
129
204
  Other Diff Options
130
205
  ------------------
131
206
 
@@ -9,4 +9,5 @@ require 'open3' unless Diffy::WINDOWS
9
9
  require File.join(File.dirname(__FILE__), 'diffy', 'format')
10
10
  require File.join(File.dirname(__FILE__), 'diffy', 'html_formatter')
11
11
  require File.join(File.dirname(__FILE__), 'diffy', 'diff')
12
+ require File.join(File.dirname(__FILE__), 'diffy', 'split_diff')
12
13
  require File.join(File.dirname(__FILE__), 'diffy', 'css')
@@ -14,4 +14,21 @@ module Diffy
14
14
  .diff li.diff-comment { display: none; }
15
15
  .diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
16
16
  STYLE
17
+
18
+ CSS_COLORBLIND_1 = <<-STYLE
19
+ .diff{overflow:auto;}
20
+ .diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
21
+ .diff del, .diff ins{display:block;text-decoration:none;}
22
+ .diff li{padding:0; display:table-row;margin: 0;height:1em;}
23
+ .diff li.ins{background:#ddf; color:#008}
24
+ .diff li.del{background:#fee; color:#b00}
25
+ .diff li:hover{background:#ffc}
26
+ /* try 'whitespace:pre;' if you don't want lines to wrap */
27
+ .diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;}
28
+ .diff del strong{font-weight:normal;background:#fcc;}
29
+ .diff ins strong{font-weight:normal;background:#99f;}
30
+ .diff li.diff-comment { display: none; }
31
+ .diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
32
+ STYLE
33
+
17
34
  end
@@ -0,0 +1,49 @@
1
+ module Diffy
2
+ class SplitDiff
3
+ def initialize(left, right, options = {})
4
+ @format = options[:format] || Diffy::Diff.default_format
5
+
6
+ formats = Format.instance_methods(false).map { |x| x.to_s }
7
+ unless formats.include?(@format.to_s)
8
+ fail ArgumentError, "Format #{format.inspect} is not a valid format"
9
+ end
10
+
11
+ @diff = Diffy::Diff.new(left, right, options).to_s(@format)
12
+ @left_diff, @right_diff = split
13
+ end
14
+
15
+ %w(left right).each do |direction|
16
+ define_method direction do
17
+ instance_variable_get("@#{direction}_diff")
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def split
24
+ [split_left, split_right]
25
+ end
26
+
27
+ def split_left
28
+ case @format
29
+ when :color
30
+ @diff.gsub(/\033\[32m\+(.*)\033\[0m\n/, '')
31
+ when :html, :html_simple
32
+ @diff.gsub(%r{\s+<li class="ins"><ins>(.*)</ins></li>}, '')
33
+ when :text
34
+ @diff.gsub(/^\+(.*)\n/, '')
35
+ end
36
+ end
37
+
38
+ def split_right
39
+ case @format
40
+ when :color
41
+ @diff.gsub(/\033\[31m\-(.*)\033\[0m\n/, '')
42
+ when :html, :html_simple
43
+ @diff.gsub(%r{\s+<li class="del"><del>(.*)</del></li>}, '')
44
+ when :text
45
+ @diff.gsub(/^-(.*)\n/, '')
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module Diffy
2
- VERSION = '3.0.7'
2
+ VERSION = '3.1.0'
3
3
  end
@@ -588,6 +588,73 @@ baz
588
588
  end
589
589
  end
590
590
 
591
+ describe Diffy::SplitDiff do
592
+ before do
593
+ ::Diffy::Diff.default_options.merge!(:diff => '-U 10000')
594
+ end
595
+
596
+ it "should fail with invalid format" do
597
+ expected_fail = expect do
598
+ Diffy::SplitDiff.new("lorem\n", "ipsum\n", :format => :fail)
599
+ end
600
+ expected_fail.to raise_error(ArgumentError)
601
+ end
602
+
603
+ describe "#left" do
604
+ it "should only highlight deletions" do
605
+ string1 = "lorem\nipsum\ndolor\nsit amet\n"
606
+ string2 = "lorem\nipsumdolor\nsit amet\n"
607
+ expect(Diffy::SplitDiff.new(string1, string2).left).to eq <<-TEXT
608
+ lorem
609
+ -ipsum
610
+ -dolor
611
+ sit amet
612
+ TEXT
613
+ end
614
+
615
+ it "should also format left diff as html" do
616
+ string1 = "lorem\nipsum\ndolor\nsit amet\n"
617
+ string2 = "lorem\nipsumdolor\nsit amet\n"
618
+ expect(Diffy::SplitDiff.new(string1, string2, :format => :html).left).to eq <<-HTML
619
+ <div class="diff">
620
+ <ul>
621
+ <li class="unchanged"><span>lorem</span></li>
622
+ <li class="del"><del>ipsum<strong></strong></del></li>
623
+ <li class="del"><del><strong></strong>dolor</del></li>
624
+ <li class="unchanged"><span>sit amet</span></li>
625
+ </ul>
626
+ </div>
627
+ HTML
628
+ end
629
+ end
630
+
631
+ describe "#right" do
632
+ it "should only highlight insertions" do
633
+ string1 = "lorem\nipsum\ndolor\nsit amet\n"
634
+ string2 = "lorem\nipsumdolor\nsit amet\n"
635
+ expect(Diffy::SplitDiff.new(string1, string2).right).to eq <<-TEXT
636
+ lorem
637
+ +ipsumdolor
638
+ sit amet
639
+ TEXT
640
+ end
641
+
642
+ it "should also format right diff as html" do
643
+ string1 = "lorem\nipsum\ndolor\nsit amet\n"
644
+ string2 = "lorem\nipsumdolor\nsit amet\n"
645
+ expect(Diffy::SplitDiff.new(string1, string2, :format => :html).right).to eq <<-HTML
646
+ <div class="diff">
647
+ <ul>
648
+ <li class="unchanged"><span>lorem</span></li>
649
+ <li class="ins"><ins>ipsumdolor</ins></li>
650
+ <li class="unchanged"><span>sit amet</span></li>
651
+ </ul>
652
+ </div>
653
+ HTML
654
+ end
655
+ end
656
+ end
657
+
591
658
  describe 'Diffy::CSS' do
592
659
  it "should be some css" do
593
660
  expect(Diffy::CSS).to include 'diff{overflow:auto;}'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.7
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Goldstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-12 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -60,6 +60,7 @@ files:
60
60
  - lib/diffy/diff.rb
61
61
  - lib/diffy/format.rb
62
62
  - lib/diffy/html_formatter.rb
63
+ - lib/diffy/split_diff.rb
63
64
  - lib/diffy/version.rb
64
65
  - spec/demo_app.rb
65
66
  - spec/diffy_spec.rb
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  version: '0'
84
85
  requirements: []
85
86
  rubyforge_project:
86
- rubygems_version: 2.2.2
87
+ rubygems_version: 2.4.5.1
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: A convenient way to diff string in ruby