diff-lcs 1.6.1 → 2.0.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +48 -0
- data/CONTRIBUTING.md +85 -34
- data/CONTRIBUTORS.md +1 -0
- data/LICENCE.md +39 -11
- data/Manifest.txt +3 -13
- data/README.md +1 -1
- data/Rakefile +29 -55
- data/SECURITY.md +27 -23
- data/lib/diff/lcs/block.rb +29 -24
- data/lib/diff/lcs/callbacks.rb +240 -242
- data/lib/diff/lcs/change.rb +84 -91
- data/lib/diff/lcs/hunk.rb +92 -155
- data/lib/diff/lcs/internals.rb +92 -96
- data/lib/diff/lcs/ldiff.rb +21 -34
- data/lib/diff/lcs/version.rb +1 -1
- data/lib/diff/lcs.rb +439 -466
- data/licenses/dco.txt +34 -0
- data/spec/hunk_spec.rb +0 -11
- data/spec/lcs_spec.rb +6 -6
- data/spec/ldiff_spec.rb +1 -1
- data/spec/spec_helper.rb +14 -16
- metadata +91 -36
- data/.rspec +0 -1
- data/bin/htmldiff +0 -35
- data/lib/diff/lcs/backports.rb +0 -9
- data/lib/diff/lcs/htmldiff.rb +0 -160
- data/mise.toml +0 -5
- data/spec/fixtures/ldiff/output.diff-e +0 -3
- data/spec/fixtures/ldiff/output.diff-f +0 -3
- data/spec/fixtures/ldiff/output.diff.chef-e +0 -3
- data/spec/fixtures/ldiff/output.diff.chef-f +0 -3
- data/spec/fixtures/ldiff/output.diff.chef2-e +0 -7
- data/spec/fixtures/ldiff/output.diff.chef2-f +0 -7
- /data/{docs → licenses}/COPYING.txt +0 -0
- /data/{docs → licenses}/artistic.txt +0 -0
data/licenses/dco.txt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Developer Certificate of Origin
|
|
2
|
+
Version 1.1
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
|
|
5
|
+
|
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
|
7
|
+
license document, but changing it is not allowed.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Developer's Certificate of Origin 1.1
|
|
11
|
+
|
|
12
|
+
By making a contribution to this project, I certify that:
|
|
13
|
+
|
|
14
|
+
(a) The contribution was created in whole or in part by me and I
|
|
15
|
+
have the right to submit it under the open source license
|
|
16
|
+
indicated in the file; or
|
|
17
|
+
|
|
18
|
+
(b) The contribution is based upon previous work that, to the best
|
|
19
|
+
of my knowledge, is covered under an appropriate open source
|
|
20
|
+
license and I have the right under that license to submit that
|
|
21
|
+
work with modifications, whether created in whole or in part
|
|
22
|
+
by me, under the same open source license (unless I am
|
|
23
|
+
permitted to submit under a different license), as indicated
|
|
24
|
+
in the file; or
|
|
25
|
+
|
|
26
|
+
(c) The contribution was provided directly to me by some other
|
|
27
|
+
person who certified (a), (b) or (c) and I have not modified
|
|
28
|
+
it.
|
|
29
|
+
|
|
30
|
+
(d) I understand and agree that this project and the contribution
|
|
31
|
+
are public and that a record of the contribution (including all
|
|
32
|
+
personal information I submit with it, including my sign-off) is
|
|
33
|
+
maintained indefinitely and may be redistributed consistent with
|
|
34
|
+
this project or the open source license(s) involved.
|
data/spec/hunk_spec.rb
CHANGED
|
@@ -56,17 +56,6 @@ if String.method_defined?(:encoding)
|
|
|
56
56
|
expect(hunk.diff(:old)).to eq(expected)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
it "produces a reverse ed diff from the two pieces" do
|
|
60
|
-
expected = <<-EXPECTED.gsub(/^ +/, "").encode("UTF-16LE").chomp
|
|
61
|
-
c1
|
|
62
|
-
Tu a un carte avec {count} items
|
|
63
|
-
.
|
|
64
|
-
|
|
65
|
-
EXPECTED
|
|
66
|
-
|
|
67
|
-
expect(hunk.diff(:reverse_ed)).to eq(expected)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
59
|
context "with empty first data set" do
|
|
71
60
|
let(:old_data) { [] }
|
|
72
61
|
|
data/spec/lcs_spec.rb
CHANGED
|
@@ -31,26 +31,26 @@ describe Diff::LCS::Internals, ".lcs" do
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
describe Diff::LCS, ".
|
|
34
|
+
describe Diff::LCS, ".lcs" do
|
|
35
35
|
include Diff::LCS::SpecHelper::Matchers
|
|
36
36
|
|
|
37
|
-
it "returns the correct compacted values from Diff::LCS.
|
|
38
|
-
res = Diff::LCS.
|
|
37
|
+
it "returns the correct compacted values from Diff::LCS.lcs" do
|
|
38
|
+
res = Diff::LCS.lcs(seq1, seq2)
|
|
39
39
|
expect(res).to eq(correct_lcs)
|
|
40
40
|
expect(res.compact).to eq(res)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "is transitive" do
|
|
44
|
-
res = Diff::LCS.
|
|
44
|
+
res = Diff::LCS.lcs(seq2, seq1)
|
|
45
45
|
expect(res).to eq(correct_lcs)
|
|
46
46
|
expect(res.compact).to eq(res)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "returns %W(h e l l o) with (hello, hello)" do
|
|
50
|
-
expect(Diff::LCS.
|
|
50
|
+
expect(Diff::LCS.lcs(hello, hello)).to eq(hello.chars)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "returns hello_ary with (hello_ary, hello_ary)" do
|
|
54
|
-
expect(Diff::LCS.
|
|
54
|
+
expect(Diff::LCS.lcs(hello_ary, hello_ary)).to eq(hello_ary)
|
|
55
55
|
end
|
|
56
56
|
end
|
data/spec/ldiff_spec.rb
CHANGED
|
@@ -17,7 +17,7 @@ RSpec.describe "bin/ldiff" do
|
|
|
17
17
|
{:name => "diff.bin2", :left => "file1.bin", :right => "file2.bin", :diff => 1},
|
|
18
18
|
{:name => "diff.chef", :left => "old-chef", :right => "new-chef", :diff => 1},
|
|
19
19
|
{:name => "diff.chef2", :left => "old-chef2", :right => "new-chef2", :diff => 1}
|
|
20
|
-
].product([nil, "-
|
|
20
|
+
].product([nil, "-c", "-u"]).map { |(fixture, flag)|
|
|
21
21
|
fixture = fixture.dup
|
|
22
22
|
fixture[:flag] = flag
|
|
23
23
|
fixture
|
data/spec/spec_helper.rb
CHANGED
|
@@ -5,24 +5,22 @@ require "pathname"
|
|
|
5
5
|
|
|
6
6
|
require "psych" if RUBY_VERSION >= "1.9"
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
require "simplecov-lcov"
|
|
8
|
+
require "simplecov"
|
|
9
|
+
require "simplecov-lcov"
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
SimpleCov::Formatter::LcovFormatter.config do |config|
|
|
12
|
+
config.report_with_single_file = true
|
|
13
|
+
config.lcov_file_name = "lcov.info"
|
|
14
|
+
end
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
end
|
|
16
|
+
SimpleCov.start "test_frameworks" do
|
|
17
|
+
enable_coverage :branch
|
|
18
|
+
primary_coverage :branch
|
|
19
|
+
formatter SimpleCov::Formatter::MultiFormatter.new([
|
|
20
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
21
|
+
SimpleCov::Formatter::LcovFormatter,
|
|
22
|
+
SimpleCov::Formatter::SimpleFormatter
|
|
23
|
+
])
|
|
26
24
|
end
|
|
27
25
|
|
|
28
26
|
file = Pathname.new(__FILE__).expand_path
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: diff-lcs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0.beta.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Austin Ziegler
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: hoe
|
|
@@ -29,28 +29,20 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '2.
|
|
33
|
-
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - "~>"
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '2.0'
|
|
40
|
-
- !ruby/object:Gem::Dependency
|
|
41
|
-
name: hoe-rubygems
|
|
42
|
-
requirement: !ruby/object:Gem::Requirement
|
|
43
|
-
requirements:
|
|
44
|
-
- - "~>"
|
|
32
|
+
version: '2.1'
|
|
33
|
+
- - ">="
|
|
45
34
|
- !ruby/object:Gem::Version
|
|
46
|
-
version:
|
|
35
|
+
version: 2.1.1
|
|
47
36
|
type: :development
|
|
48
37
|
prerelease: false
|
|
49
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
39
|
requirements:
|
|
51
40
|
- - "~>"
|
|
52
41
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: '1
|
|
42
|
+
version: '2.1'
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 2.1.1
|
|
54
46
|
- !ruby/object:Gem::Dependency
|
|
55
47
|
name: rspec
|
|
56
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -111,12 +103,82 @@ dependencies:
|
|
|
111
103
|
- - "<"
|
|
112
104
|
- !ruby/object:Gem::Version
|
|
113
105
|
version: '7'
|
|
106
|
+
- !ruby/object:Gem::Dependency
|
|
107
|
+
name: simplecov
|
|
108
|
+
requirement: !ruby/object:Gem::Requirement
|
|
109
|
+
requirements:
|
|
110
|
+
- - "~>"
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '0.9'
|
|
113
|
+
type: :development
|
|
114
|
+
prerelease: false
|
|
115
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
116
|
+
requirements:
|
|
117
|
+
- - "~>"
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: '0.9'
|
|
120
|
+
- !ruby/object:Gem::Dependency
|
|
121
|
+
name: simplecov-lcov
|
|
122
|
+
requirement: !ruby/object:Gem::Requirement
|
|
123
|
+
requirements:
|
|
124
|
+
- - "~>"
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: '0.9'
|
|
127
|
+
type: :development
|
|
128
|
+
prerelease: false
|
|
129
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
130
|
+
requirements:
|
|
131
|
+
- - "~>"
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: '0.9'
|
|
134
|
+
- !ruby/object:Gem::Dependency
|
|
135
|
+
name: standard
|
|
136
|
+
requirement: !ruby/object:Gem::Requirement
|
|
137
|
+
requirements:
|
|
138
|
+
- - "~>"
|
|
139
|
+
- !ruby/object:Gem::Version
|
|
140
|
+
version: '1.50'
|
|
141
|
+
type: :development
|
|
142
|
+
prerelease: false
|
|
143
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
144
|
+
requirements:
|
|
145
|
+
- - "~>"
|
|
146
|
+
- !ruby/object:Gem::Version
|
|
147
|
+
version: '1.50'
|
|
148
|
+
- !ruby/object:Gem::Dependency
|
|
149
|
+
name: standard-thread_safety
|
|
150
|
+
requirement: !ruby/object:Gem::Requirement
|
|
151
|
+
requirements:
|
|
152
|
+
- - "~>"
|
|
153
|
+
- !ruby/object:Gem::Version
|
|
154
|
+
version: '1.0'
|
|
155
|
+
type: :development
|
|
156
|
+
prerelease: false
|
|
157
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
158
|
+
requirements:
|
|
159
|
+
- - "~>"
|
|
160
|
+
- !ruby/object:Gem::Version
|
|
161
|
+
version: '1.0'
|
|
162
|
+
- !ruby/object:Gem::Dependency
|
|
163
|
+
name: fasterer
|
|
164
|
+
requirement: !ruby/object:Gem::Requirement
|
|
165
|
+
requirements:
|
|
166
|
+
- - "~>"
|
|
167
|
+
- !ruby/object:Gem::Version
|
|
168
|
+
version: '0.11'
|
|
169
|
+
type: :development
|
|
170
|
+
prerelease: false
|
|
171
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
172
|
+
requirements:
|
|
173
|
+
- - "~>"
|
|
174
|
+
- !ruby/object:Gem::Version
|
|
175
|
+
version: '0.11'
|
|
114
176
|
description: |-
|
|
115
177
|
Diff::LCS computes the difference between two Enumerable sequences using the
|
|
116
178
|
McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities
|
|
117
179
|
to create a simple HTML diff output format and a standard diff-like tool.
|
|
118
180
|
|
|
119
|
-
This is release 1.
|
|
181
|
+
This is release 1.6.1, providing a simple extension that allows for
|
|
120
182
|
Diff::LCS::Change objects to be treated implicitly as arrays and fixes a number
|
|
121
183
|
of formatting issues.
|
|
122
184
|
|
|
@@ -128,7 +190,6 @@ description: |-
|
|
|
128
190
|
email:
|
|
129
191
|
- halostatue@gmail.com
|
|
130
192
|
executables:
|
|
131
|
-
- htmldiff
|
|
132
193
|
- ldiff
|
|
133
194
|
extensions: []
|
|
134
195
|
extra_rdoc_files:
|
|
@@ -140,10 +201,10 @@ extra_rdoc_files:
|
|
|
140
201
|
- Manifest.txt
|
|
141
202
|
- README.md
|
|
142
203
|
- SECURITY.md
|
|
143
|
-
-
|
|
144
|
-
-
|
|
204
|
+
- licenses/COPYING.txt
|
|
205
|
+
- licenses/artistic.txt
|
|
206
|
+
- licenses/dco.txt
|
|
145
207
|
files:
|
|
146
|
-
- ".rspec"
|
|
147
208
|
- CHANGELOG.md
|
|
148
209
|
- CODE_OF_CONDUCT.md
|
|
149
210
|
- CONTRIBUTING.md
|
|
@@ -153,24 +214,21 @@ files:
|
|
|
153
214
|
- README.md
|
|
154
215
|
- Rakefile
|
|
155
216
|
- SECURITY.md
|
|
156
|
-
- bin/htmldiff
|
|
157
217
|
- bin/ldiff
|
|
158
|
-
- docs/COPYING.txt
|
|
159
|
-
- docs/artistic.txt
|
|
160
218
|
- lib/diff-lcs.rb
|
|
161
219
|
- lib/diff/lcs.rb
|
|
162
220
|
- lib/diff/lcs/array.rb
|
|
163
|
-
- lib/diff/lcs/backports.rb
|
|
164
221
|
- lib/diff/lcs/block.rb
|
|
165
222
|
- lib/diff/lcs/callbacks.rb
|
|
166
223
|
- lib/diff/lcs/change.rb
|
|
167
|
-
- lib/diff/lcs/htmldiff.rb
|
|
168
224
|
- lib/diff/lcs/hunk.rb
|
|
169
225
|
- lib/diff/lcs/internals.rb
|
|
170
226
|
- lib/diff/lcs/ldiff.rb
|
|
171
227
|
- lib/diff/lcs/string.rb
|
|
172
228
|
- lib/diff/lcs/version.rb
|
|
173
|
-
-
|
|
229
|
+
- licenses/COPYING.txt
|
|
230
|
+
- licenses/artistic.txt
|
|
231
|
+
- licenses/dco.txt
|
|
174
232
|
- spec/change_spec.rb
|
|
175
233
|
- spec/diff_spec.rb
|
|
176
234
|
- spec/fixtures/123_x
|
|
@@ -196,8 +254,6 @@ files:
|
|
|
196
254
|
- spec/fixtures/ldiff/error.diff.missing_new_line2-f
|
|
197
255
|
- spec/fixtures/ldiff/output.diff
|
|
198
256
|
- spec/fixtures/ldiff/output.diff-c
|
|
199
|
-
- spec/fixtures/ldiff/output.diff-e
|
|
200
|
-
- spec/fixtures/ldiff/output.diff-f
|
|
201
257
|
- spec/fixtures/ldiff/output.diff-u
|
|
202
258
|
- spec/fixtures/ldiff/output.diff.bin1
|
|
203
259
|
- spec/fixtures/ldiff/output.diff.bin1-c
|
|
@@ -211,14 +267,10 @@ files:
|
|
|
211
267
|
- spec/fixtures/ldiff/output.diff.bin2-u
|
|
212
268
|
- spec/fixtures/ldiff/output.diff.chef
|
|
213
269
|
- spec/fixtures/ldiff/output.diff.chef-c
|
|
214
|
-
- spec/fixtures/ldiff/output.diff.chef-e
|
|
215
|
-
- spec/fixtures/ldiff/output.diff.chef-f
|
|
216
270
|
- spec/fixtures/ldiff/output.diff.chef-u
|
|
217
271
|
- spec/fixtures/ldiff/output.diff.chef2
|
|
218
272
|
- spec/fixtures/ldiff/output.diff.chef2-c
|
|
219
273
|
- spec/fixtures/ldiff/output.diff.chef2-d
|
|
220
|
-
- spec/fixtures/ldiff/output.diff.chef2-e
|
|
221
|
-
- spec/fixtures/ldiff/output.diff.chef2-f
|
|
222
274
|
- spec/fixtures/ldiff/output.diff.chef2-u
|
|
223
275
|
- spec/fixtures/ldiff/output.diff.empty.vs.four_lines
|
|
224
276
|
- spec/fixtures/ldiff/output.diff.empty.vs.four_lines-c
|
|
@@ -278,14 +330,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
278
330
|
requirements:
|
|
279
331
|
- - ">="
|
|
280
332
|
- !ruby/object:Gem::Version
|
|
281
|
-
version:
|
|
333
|
+
version: 3.2.0
|
|
334
|
+
- - "<"
|
|
335
|
+
- !ruby/object:Gem::Version
|
|
336
|
+
version: '5'
|
|
282
337
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
338
|
requirements:
|
|
284
339
|
- - ">="
|
|
285
340
|
- !ruby/object:Gem::Version
|
|
286
341
|
version: '0'
|
|
287
342
|
requirements: []
|
|
288
|
-
rubygems_version: 3.6.
|
|
343
|
+
rubygems_version: 3.6.9
|
|
289
344
|
specification_version: 4
|
|
290
345
|
summary: Diff::LCS computes the difference between two Enumerable sequences using
|
|
291
346
|
the McIlroy-Hunt longest common subsequence (LCS) algorithm
|
data/.rspec
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--colour
|
data/bin/htmldiff
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env ruby -w
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require "diff/lcs"
|
|
5
|
-
require "diff/lcs/htmldiff"
|
|
6
|
-
|
|
7
|
-
begin
|
|
8
|
-
require "text/format"
|
|
9
|
-
rescue LoadError
|
|
10
|
-
Diff::LCS::HTMLDiff.can_expand_tabs = false
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
if ARGV.size < 2 or ARGV.size > 3
|
|
14
|
-
warn "usage: #{File.basename($0)} old new [output.html]"
|
|
15
|
-
warn " #{File.basename($0)} old new > output.html"
|
|
16
|
-
exit 127
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
left = IO.read(ARGV[0]).split($/)
|
|
20
|
-
right = IO.read(ARGV[1]).split($/)
|
|
21
|
-
|
|
22
|
-
options = { :title => "diff #{ARGV[0]} #{ARGV[1]}" }
|
|
23
|
-
|
|
24
|
-
htmldiff = Diff::LCS::HTMLDiff.new(left, right, options)
|
|
25
|
-
|
|
26
|
-
if ARGV[2]
|
|
27
|
-
File.open(ARGV[2], "w") do |f|
|
|
28
|
-
htmldiff.options[:output] = f
|
|
29
|
-
htmldiff.run
|
|
30
|
-
end
|
|
31
|
-
else
|
|
32
|
-
htmldiff.run
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# vim: ft=ruby
|
data/lib/diff/lcs/backports.rb
DELETED
data/lib/diff/lcs/htmldiff.rb
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "cgi"
|
|
4
|
-
|
|
5
|
-
# Produce a simple HTML diff view.
|
|
6
|
-
class Diff::LCS::HTMLDiff
|
|
7
|
-
class << self
|
|
8
|
-
# standard:disable ThreadSafety/ClassAndModuleAttributes
|
|
9
|
-
attr_accessor :can_expand_tabs # :nodoc:
|
|
10
|
-
# standard:enable ThreadSafety/ClassAndModuleAttributes
|
|
11
|
-
end
|
|
12
|
-
self.can_expand_tabs = true
|
|
13
|
-
|
|
14
|
-
class Callbacks # :nodoc:
|
|
15
|
-
attr_accessor :output
|
|
16
|
-
attr_accessor :match_class
|
|
17
|
-
attr_accessor :only_a_class
|
|
18
|
-
attr_accessor :only_b_class
|
|
19
|
-
|
|
20
|
-
def initialize(output, options = {})
|
|
21
|
-
@output = output
|
|
22
|
-
options ||= {}
|
|
23
|
-
|
|
24
|
-
@match_class = options[:match_class] || "match"
|
|
25
|
-
@only_a_class = options[:only_a_class] || "only_a"
|
|
26
|
-
@only_b_class = options[:only_b_class] || "only_b"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def htmlize(element, css_class)
|
|
30
|
-
element = " " if element.empty?
|
|
31
|
-
%(<pre class="#{__send__(css_class)}">#{element}</pre>\n)
|
|
32
|
-
end
|
|
33
|
-
private :htmlize
|
|
34
|
-
|
|
35
|
-
# This will be called with both lines are the same
|
|
36
|
-
def match(event)
|
|
37
|
-
@output << htmlize(event.old_element, :match_class)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# This will be called when there is a line in A that isn't in B
|
|
41
|
-
def discard_a(event)
|
|
42
|
-
@output << htmlize(event.old_element, :only_a_class)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# This will be called when there is a line in B that isn't in A
|
|
46
|
-
def discard_b(event)
|
|
47
|
-
@output << htmlize(event.new_element, :only_b_class)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# standard:disable Style/HashSyntax
|
|
52
|
-
DEFAULT_OPTIONS = {
|
|
53
|
-
:expand_tabs => nil,
|
|
54
|
-
:output => nil,
|
|
55
|
-
:css => nil,
|
|
56
|
-
:title => nil
|
|
57
|
-
}.freeze
|
|
58
|
-
# standard:enable Style/HashSyntax
|
|
59
|
-
|
|
60
|
-
# standard:disable Layout/HeredocIndentation
|
|
61
|
-
DEFAULT_CSS = <<-CSS
|
|
62
|
-
body { margin: 0; }
|
|
63
|
-
.diff
|
|
64
|
-
{
|
|
65
|
-
border: 1px solid black;
|
|
66
|
-
margin: 1em 2em;
|
|
67
|
-
}
|
|
68
|
-
p
|
|
69
|
-
{
|
|
70
|
-
margin-left: 2em;
|
|
71
|
-
}
|
|
72
|
-
pre
|
|
73
|
-
{
|
|
74
|
-
padding-left: 1em;
|
|
75
|
-
margin: 0;
|
|
76
|
-
font-family: Inconsolata, Consolas, Lucida, Courier, monospaced;
|
|
77
|
-
white-space: pre;
|
|
78
|
-
}
|
|
79
|
-
.match { }
|
|
80
|
-
.only_a
|
|
81
|
-
{
|
|
82
|
-
background-color: #fdd;
|
|
83
|
-
color: red;
|
|
84
|
-
text-decoration: line-through;
|
|
85
|
-
}
|
|
86
|
-
.only_b
|
|
87
|
-
{
|
|
88
|
-
background-color: #ddf;
|
|
89
|
-
color: blue;
|
|
90
|
-
border-left: 3px solid blue
|
|
91
|
-
}
|
|
92
|
-
h1 { margin-left: 2em; }
|
|
93
|
-
CSS
|
|
94
|
-
# standard:enable Layout/HeredocIndentation
|
|
95
|
-
|
|
96
|
-
def initialize(left, right, options = nil)
|
|
97
|
-
@left = left
|
|
98
|
-
@right = right
|
|
99
|
-
@options = options
|
|
100
|
-
|
|
101
|
-
@options = DEFAULT_OPTIONS.dup if @options.nil?
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def verify_options
|
|
105
|
-
@options[:expand_tabs] ||= 4
|
|
106
|
-
@options[:expand_tabs] = 4 if @options[:expand_tabs].negative?
|
|
107
|
-
|
|
108
|
-
@options[:output] ||= $stdout
|
|
109
|
-
|
|
110
|
-
@options[:css] ||= DEFAULT_CSS.dup
|
|
111
|
-
|
|
112
|
-
@options[:title] ||= "diff"
|
|
113
|
-
end
|
|
114
|
-
private :verify_options
|
|
115
|
-
|
|
116
|
-
attr_reader :options
|
|
117
|
-
|
|
118
|
-
def run
|
|
119
|
-
verify_options
|
|
120
|
-
|
|
121
|
-
if @options[:expand_tabs].positive? && self.class.can_expand_tabs
|
|
122
|
-
formatter = Text::Format.new
|
|
123
|
-
formatter.tabstop = @options[:expand_tabs]
|
|
124
|
-
|
|
125
|
-
@left.map! { |line| formatter.expand(line.chomp) }
|
|
126
|
-
@right.map! { |line| formatter.expand(line.chomp) }
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
@left.map! { |line| CGI.escapeHTML(line.chomp) }
|
|
130
|
-
@right.map! { |line| CGI.escapeHTML(line.chomp) }
|
|
131
|
-
|
|
132
|
-
# standard:disable Layout/HeredocIndentation
|
|
133
|
-
@options[:output] << <<-OUTPUT
|
|
134
|
-
<html>
|
|
135
|
-
<head>
|
|
136
|
-
<title>#{@options[:title]}</title>
|
|
137
|
-
<style type="text/css">
|
|
138
|
-
#{@options[:css]}
|
|
139
|
-
</style>
|
|
140
|
-
</head>
|
|
141
|
-
<body>
|
|
142
|
-
<h1>#{@options[:title]}</h1>
|
|
143
|
-
<p>Legend: <span class="only_a">Only in Old</span>
|
|
144
|
-
<span class="only_b">Only in New</span></p>
|
|
145
|
-
<div class="diff">
|
|
146
|
-
OUTPUT
|
|
147
|
-
# standard:enable Layout/HeredocIndentation
|
|
148
|
-
|
|
149
|
-
callbacks = Callbacks.new(@options[:output])
|
|
150
|
-
Diff::LCS.traverse_sequences(@left, @right, callbacks)
|
|
151
|
-
|
|
152
|
-
# standard:disable Layout/HeredocIndentation
|
|
153
|
-
@options[:output] << <<-OUTPUT
|
|
154
|
-
</div>
|
|
155
|
-
</body>
|
|
156
|
-
</html>
|
|
157
|
-
OUTPUT
|
|
158
|
-
# standard:enable Layout/HeredocIndentation
|
|
159
|
-
end
|
|
160
|
-
end
|
data/mise.toml
DELETED
|
File without changes
|
|
File without changes
|