ydiffy 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da837db923dccfb81fd25331f0e4794515df2923
4
+ data.tar.gz: 8a26000dde88219122ad677300c2de7fa8ea32cd
5
+ SHA512:
6
+ metadata.gz: 3e3b15cd46a23f88c9b07eafcd7ba5499ee98a017e8cc6fafd456969f490aa459c03efa9956a6680e27a81d79f1563c57ee55beba59c61eb03d975e8a0e564d0
7
+ data.tar.gz: e72a6a7a66f12e601fbf04db1dcd1330f3b5ee4f04eebac703081aa20f65fd31e19b64e14e3b0ddd24d75f2c32e61afe51833bba8270b1d80b21a41cd86c2a80
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ *.swp
3
+ Gemfile.lock
4
+ tags
5
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --profile
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ rvm:
5
+ - 2.4.0
@@ -0,0 +1,40 @@
1
+ == 3.1.0 ==
2
+ Side by side diffs. Thanks Runar Skaare Tveiten!
3
+
4
+ == 3.0.5 ==
5
+ Improve performance when generating html output (with inline highlighting) on
6
+ long lines. Thanks Jason Barnabe!
7
+
8
+ == 3.0.4 ==
9
+ handle windows vs. unix line breaks consistently in html output
10
+
11
+ == 3.0.3 ==
12
+ explicitly unlink tempfiles to avoid occasional file handle leaks
13
+
14
+ == 3.0.0 ==
15
+ allow_empty_diff is true by default
16
+
17
+ == 2.1.0 ==
18
+ Windows support
19
+
20
+ == 2.0.10 ==
21
+ Close tempfile after it's been written to to avoid too many open file handles
22
+
23
+ == 2.0.9 ==
24
+ Memoize calls to `which diff` which should result in a minor performance
25
+ improvement in high use environments.
26
+
27
+ == 2.0.8 ==
28
+ Handle non-UTF-8 byte sequences in Ruby 1.9.
29
+ Avoid non-deterministic deletion of temp files when GC runs
30
+
31
+ == 2.0.7 ==
32
+ Added :allow_empty_diff option
33
+
34
+ == Oops, need to backfill changelog ==
35
+
36
+ == 1.0.1 ==
37
+ * Compatibility with ruby 1.8.6 and 1.9
38
+
39
+ == 1.0.0 ==
40
+ * HTML output and better documentation
@@ -0,0 +1,13 @@
1
+ * Sam Goldstein
2
+ * joelash
3
+ * chaffeqa
4
+ * Lincoln Ritter
5
+ * Bernhard Weichel
6
+ * Yuichi Tateno
7
+ * Nigel Thorne
8
+ * Richard Stiller
9
+ * printercu
10
+ * Bryan Ricker
11
+ * JasonBarnabe
12
+ * Skye Shaw
13
+ * Abinoam P. Marques Jr.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ platforms :rbx do
4
+ gem 'rubysl', '~> 2.0'
5
+ end
6
+
7
+ gemspec
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.
@@ -0,0 +1,334 @@
1
+ Yidffy
2
+ ======
3
+
4
+ This a a forked version of the diffy gem, because we needed a patch to work around a deficiency in the odba gem, which tried to persist closed (temp) files.
5
+
6
+ Diffy - Easy Diffing With Ruby [![Build Status](https://travis-ci.org/samg/diffy.svg?branch=master)](https://travis-ci.org/samg/diffy)
7
+ ============================
8
+
9
+ Need diffs in your ruby app? Diffy has you covered. It provides a convenient
10
+ way to generate a diff from two strings or files. Instead of reimplementing
11
+ the LCS diff algorithm Diffy uses battle tested Unix diff to generate diffs,
12
+ and focuses on providing a convenient interface, and getting out of your way.
13
+
14
+ Supported Formats
15
+ -----------------
16
+
17
+ It provides several built in format options which can be passed to
18
+ `Diffy::Diff#to_s`.
19
+
20
+ * `:text` - Plain text output
21
+ * `:color` - ANSI colorized text suitable for use in a terminal
22
+ * `:html` - HTML output. Since version 2.0 this format does inline highlighting of the character changes between lines.
23
+ * `:html_simple` - HTML output without inline highlighting. This may be useful in situations where high performance is required or simpler output is desired.
24
+
25
+ A default format can be set like so:
26
+
27
+ Diffy::Diff.default_format = :html
28
+
29
+ Installation
30
+ ------------
31
+
32
+ ### on Unix
33
+
34
+ gem install diffy
35
+
36
+ ### on Windows:
37
+
38
+ 1. Ensure that you have a working `diff` on your machine and in your search path.
39
+
40
+ There are several options:
41
+
42
+ 1. Install [Diff::LCS](https://github.com/halostatue/diff-lcs), which includes `ldiff`. [RSpec](https://www.relishapp.com/rspec/docs/gettingstarted)
43
+ depends on Diff::LCS so you may already have it installed.
44
+
45
+ 1. If you're using [RubyInstaller](http://rubyinstaller.org), install the [devkit](http://rubyinstaller.org/add-ons/devkit).
46
+
47
+ 1. Install unxutils <http://sourceforge.net/projects/unxutils>
48
+
49
+ note that these tools contain diff 2.7 which has a different handling
50
+ of whitespace in the diff results. This makes Diffy spec tests
51
+ yielding one fail on Windows.
52
+
53
+ 1. Install these two individually from the gnuwin32 project
54
+ <http://gnuwin32.sourceforge.net/>
55
+
56
+ note that this delivers diff 2.8 which makes Diffy spec pass
57
+ even on Windows.
58
+
59
+
60
+ 2. Install the gem by
61
+
62
+ gem install diffy
63
+
64
+
65
+ Getting Started
66
+ ---------------
67
+
68
+ Here's an example of using Diffy to diff two strings
69
+
70
+ $ irb
71
+ >> string1 = <<-TXT
72
+ >" Hello how are you
73
+ >" I'm fine
74
+ >" That's great
75
+ >" TXT
76
+ => "Hello how are you\nI'm fine\nThat's great\n"
77
+ >> string2 = <<-TXT
78
+ >" Hello how are you?
79
+ >" I'm fine
80
+ >" That's swell
81
+ >" TXT
82
+ => "Hello how are you?\nI'm fine\nThat's swell\n"
83
+ >> puts Diffy::Diff.new(string1, string2)
84
+ -Hello how are you
85
+ +Hello how are you?
86
+ I'm fine
87
+ -That's great
88
+ +That's swell
89
+
90
+ HTML Output
91
+ ---------------
92
+
93
+ Outputing the diff as html is easy too. Here's an example using the
94
+ `:html_simple` formatter.
95
+
96
+ >> puts Diffy::Diff.new(string1, string2).to_s(:html_simple)
97
+ <div class="diff">
98
+ <ul>
99
+ <li class="del"><del>Hello how are you</del></li>
100
+ <li class="ins"><ins>Hello how are you?</ins></li>
101
+ <li class="unchanged"><span>I'm fine</span></li>
102
+ <li class="del"><del>That's great</del></li>
103
+ <li class="ins"><ins>That's swell</ins></li>
104
+ </ul>
105
+ </div>
106
+
107
+ The `:html` formatter will give you inline highlighting a la github.
108
+
109
+ >> puts Diffy::Diff.new("foo\n", "Foo\n").to_s(:html)
110
+ <div class="diff">
111
+ <ul>
112
+ <li class="del"><del><strong>f</strong>oo</del></li>
113
+ <li class="ins"><ins><strong>F</strong>oo</ins></li>
114
+ </ul>
115
+ </div>
116
+
117
+ There's some pretty nice css provided in `Diffy::CSS`.
118
+
119
+ >> puts Diffy::CSS
120
+ .diff{overflow:auto;}
121
+ .diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
122
+ .diff del, .diff ins{display:block;text-decoration:none;}
123
+ .diff li{padding:0; display:table-row;margin: 0;height:1em;}
124
+ .diff li.ins{background:#dfd; color:#080}
125
+ .diff li.del{background:#fee; color:#b00}
126
+ .diff li:hover{background:#ffc}
127
+ /* try 'whitespace:pre;' if you don't want lines to wrap */
128
+ .diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;}
129
+ .diff del strong{font-weight:normal;background:#fcc;}
130
+ .diff ins strong{font-weight:normal;background:#9f9;}
131
+ .diff li.diff-comment { display: none; }
132
+ .diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
133
+
134
+
135
+ There's also a colorblind-safe version of the pallete provided in `Diffy::CSS_COLORBLIND_1`.
136
+
137
+
138
+ Side-by-side comparisons
139
+ ------------------------
140
+
141
+ Side-by-side comparisons, or split views as called by some, are supported by
142
+ using the `Diffy::SplitDiff` class. This class takes a diff returned from
143
+ `Diffy::Diff` and splits it in two parts (or two sides): left and right. The
144
+ left side represents deletions while the right side represents insertions.
145
+
146
+ The class is used as follows:
147
+
148
+ ```
149
+ Diffy::SplitDiff.new(string1, string2, options = {})
150
+ ```
151
+
152
+ The optional options hash is passed along to the main `Diff::Diff` class, so
153
+ all default options such as full diff output are supported. The output format
154
+ may be changed by passing the format with the options hash (see below), and all
155
+ default formats are supported.
156
+
157
+ Unlike `Diffy::Diff`, `Diffy::SplitDiff` does not use `#to_s` to output
158
+ the resulting diff. Instead, two self-explanatory methods are used to output
159
+ the diff: `#left` and `#right`. Using the earlier example, this is what they
160
+ look like in action:
161
+
162
+ ```
163
+ >> puts Diffy::SplitDiff.new(string1, string2).left
164
+ -Hello how are you
165
+ I'm fine
166
+ -That's great
167
+ ```
168
+
169
+ ```
170
+ >> puts Diffy::SplitDiff.new(string1, string2).right
171
+ +Hello how are you?
172
+ I'm fine
173
+ +That's swell
174
+ ```
175
+
176
+ ### Changing the split view output format
177
+
178
+ The output format may be changed by passing the format with the options hash:
179
+
180
+ ```
181
+ Diffy::SplitDiff.new(string1, string2, :format => :html)
182
+ ```
183
+
184
+ This will result in the following:
185
+
186
+ ```
187
+ >> puts Diffy::SplitDiff.new(string1, string2, :format => :html).left
188
+ <div class="diff">
189
+ <ul>
190
+ <li class="del"><del>Hello how are you</del></li>
191
+ <li class="unchanged"><span>I&#39;m fine</span></li>
192
+ <li class="del"><del>That&#39;s <strong>great</strong></del></li>
193
+ </ul>
194
+ </div>
195
+ ```
196
+
197
+ ```
198
+ >> puts Diffy::SplitDiff.new(string1, string2, :format => :html).right
199
+ <div class="diff">
200
+ <ul>
201
+ <li class="ins"><ins>Hello how are you<strong>?</strong></ins></li>
202
+ <li class="unchanged"><span>I&#39;m fine</span></li>
203
+ <li class="ins"><ins>That&#39;s <strong>swell</strong></ins></li>
204
+ </ul>
205
+ </div>
206
+ ```
207
+
208
+
209
+ Other Diff Options
210
+ ------------------
211
+
212
+ ### Diffing files instead of strings
213
+
214
+ You can diff files instead of strings by using the `:source` option.
215
+
216
+ >> puts Diffy::Diff.new('/tmp/foo', '/tmp/bar', :source => 'files')
217
+
218
+ ### Full Diff Output
219
+
220
+ By default Diffy removes the superfluous diff output. This is because its
221
+ default is to show the complete diff'ed file (`diff -U 10000` is the default).
222
+
223
+ Diffy does support full output, just use the `:include_diff_info => true`
224
+ option when initializing:
225
+
226
+ >> Diffy::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n", :include_diff_info => true).to_s(:text)
227
+ =>--- /Users/chaffeqa/Projects/stiwiki/tmp/diffy20111116-82153-ie27ex 2011-11-16 20:16:41.000000000 -0500
228
+ +++ /Users/chaffeqa/Projects/stiwiki/tmp/diffy20111116-82153-wzrhw5 2011-11-16 20:16:41.000000000 -0500
229
+ @@ -1,2 +1,3 @@
230
+ foo
231
+ bar
232
+ +baz
233
+
234
+ And even deals a bit with the formatting!
235
+
236
+ ### Empty Diff Behavior
237
+
238
+ By default Diffy will return empty string if there are no
239
+ differences in inputs. In previous versions the full text of its first input
240
+ was returned in this case. To restore this behaviour simply use the
241
+ `:allow_empty_diff => false` option when initializing.
242
+
243
+ ### Plus and Minus symbols in HTML output
244
+
245
+ By default Diffy doesn't include the `+`, `-`, and ` ` at the beginning of line for
246
+ HTML output.
247
+
248
+ You can use the `:include_plus_and_minus_in_html` option to include those
249
+ symbols in the output.
250
+
251
+ >> puts Diffy::Diff.new(string1, string2, :include_plus_and_minus_in_html => true).to_s(:html_simple)
252
+ <div class="diff">
253
+ <ul>
254
+ <li class="del"><del><span class="symbol">-</span>Hello how are you</del></li>
255
+ <li class="ins"><ins><span class="symbol">+</span>Hello how are you?</ins></li>
256
+ <li class="unchanged"><span class="symbol"> </span><span>I'm fine</span></li>
257
+ <li class="del"><del><span class="symbol">-</span>That's great</del></li>
258
+ <li class="ins"><ins><span class="symbol">+</span>That's swell</ins></li>
259
+ </ul>
260
+ </div>
261
+
262
+ ### Number of lines of context around changes
263
+
264
+ You can use the `:context` option to override the number of lines of context
265
+ that are shown around each change (this defaults to 10000 to show the full
266
+ file).
267
+
268
+ >> puts Diffy::Diff.new("foo\nfoo\nBAR\nbang\nbaz", "foo\nfoo\nbar\nbang\nbaz", :context => 1)
269
+ foo
270
+ -BAR
271
+ +bar
272
+ bang
273
+
274
+
275
+ ### Overriding the command line options passed to diff.
276
+
277
+ You can use the `:diff` option to override the command line options that are
278
+ passed to unix diff. They default to `-U 10000`. This option will noop if
279
+ combined with the `:context` option.
280
+
281
+ >> puts Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :diff => "-w")
282
+ foo
283
+ bar
284
+
285
+ Default Diff Options
286
+ --------------------
287
+
288
+ You can set the default options for new `Diffy::Diff`s using the
289
+ `Diffy::Diff.default_options` and `Diffy::Diff.default_options=` methods.
290
+ Options passed to `Diffy::Diff.new` will be merged into the default options.
291
+
292
+ >> Diffy::Diff.default_options
293
+ => {:diff=>"-U 10000", :source=>"strings", :include_diff_info=>false, :include_plus_and_minus_in_html=>false}
294
+ >> Diffy::Diff.default_options.merge!(:source => 'files')
295
+ => {:diff=>"-U 10000", :source=>"files", :include_diff_info=>false, :include_plus_and_minus_in_html=>false}
296
+
297
+
298
+ Custom Formats
299
+ --------------
300
+
301
+ Diffy tries to make generating your own custom formatted output easy.
302
+ `Diffy::Diff` provides an enumerable interface which lets you iterate over
303
+ lines in the diff.
304
+
305
+ >> Diffy::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").each do |line|
306
+ >* case line
307
+ >> when /^\+/ then puts "line #{line.chomp} added"
308
+ >> when /^-/ then puts "line #{line.chomp} removed"
309
+ >> end
310
+ >> end
311
+ line +baz added
312
+ => [" foo\n", " bar\n", "+baz\n"]
313
+
314
+ You can also use `Diffy::Diff#each_chunk` to iterate each grouping of additions,
315
+ deletions, and unchanged in a diff.
316
+
317
+ >> Diffy::Diff.new("foo\nbar\nbang\nbaz\n", "foo\nbar\nbing\nbong\n").each_chunk.to_a
318
+ => [" foo\n bar\n", "-bang\n-baz\n", "+bing\n+bong\n"]
319
+
320
+ Use `#map`, `#inject`, or any of Enumerable's methods. Go crazy.
321
+
322
+
323
+ Testing
324
+ ------------
325
+
326
+ Diffy includes a full set of rspec tests. When contributing please include
327
+ tests for your changes.
328
+
329
+ [![Build Status](https://secure.travis-ci.org/samg/diffy.png)](http://travis-ci.org/samg/diffy)
330
+
331
+ ---------------------------------------------------------------------
332
+
333
+ Report bugs or request features at http://github.com/samg/diffy/issues
334
+
@@ -0,0 +1,11 @@
1
+ require 'rspec/core/rake_task'
2
+ require "bundler/gem_tasks"
3
+
4
+ task :default => :spec
5
+
6
+ desc "Run all specs in spec directory"
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
10
+ t.ruby_opts = "-w"
11
+ end