wdiff 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/wdiff.rb +37 -10
- data/spec/wdiff_spec.rb +42 -4
- data/wdiff.gemspec +60 -0
- metadata +46 -74
data/README.rdoc
CHANGED
@@ -17,6 +17,9 @@ Simple wrapper around GNU wdiff (http://www.gnu.org/software/wdiff/)
|
|
17
17
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
18
18
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
19
19
|
|
20
|
+
== Contributors
|
21
|
+
- Richard Livsey
|
22
|
+
|
20
23
|
== Copyright
|
21
24
|
|
22
25
|
Copyright (c) 2010 Jerome Riga. See LICENSE.txt for
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ require 'jeweler'
|
|
13
13
|
Jeweler::Tasks.new do |gem|
|
14
14
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
15
|
gem.name = "wdiff"
|
16
|
-
gem.homepage = "http://github.com/
|
16
|
+
gem.homepage = "http://github.com/zemis/wdiff"
|
17
17
|
gem.license = "MIT"
|
18
18
|
gem.summary = %Q{adds the wdiff method to String instance}
|
19
19
|
gem.description = %Q{string word diff with other string; Wdiff::Helper.to_html transforms diff string in html snippet}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/wdiff.rb
CHANGED
@@ -4,27 +4,54 @@ module Wdiff
|
|
4
4
|
def included(target)
|
5
5
|
verify_wdiff_in_path
|
6
6
|
end
|
7
|
+
|
7
8
|
def verify_wdiff_in_path
|
8
9
|
path = %x{which #{bin_path}}
|
9
10
|
raise "GNU wdiff (http://www.gnu.org/software/wdiff/) not found in $PATH" if path.empty?
|
10
11
|
end
|
12
|
+
|
11
13
|
def bin_path
|
12
14
|
'wdiff'
|
13
15
|
end
|
16
|
+
|
17
|
+
# TODO - this will fail if option strings include quotes, need to escape quotes automagically
|
18
|
+
def options_string_from_hash(options={})
|
19
|
+
parts = []
|
20
|
+
|
21
|
+
options[:inserts].each_with_index do |token, index|
|
22
|
+
token.gsub!(/^\"$/,'\"') if token == '"'
|
23
|
+
parts << ( index.even? ? %Q(--start-insert="#{token}") : %Q(--end-insert="#{token}") )
|
24
|
+
break if index >= 1
|
25
|
+
end if options[:inserts]
|
26
|
+
|
27
|
+
|
28
|
+
options[:deletes].each_with_index do |token, index|
|
29
|
+
token.gsub!(/^\"$/,'\"') if token == '"'
|
30
|
+
parts << ( index.even? ? %Q(--start-delete="#{token}") : %Q(--end-delete="#{token}") )
|
31
|
+
break if index >= 1
|
32
|
+
end if options[:deletes]
|
33
|
+
|
34
|
+
parts.join(" ")
|
35
|
+
end
|
36
|
+
|
37
|
+
def diff(old_str, new_str, options={})
|
38
|
+
f1, f2 = Tempfile.new('f1'), Tempfile.new('f2')
|
39
|
+
f1.write(old_str); f1.flush
|
40
|
+
f2.write(new_str); f2.flush
|
41
|
+
opt_str = options_string_from_hash(options)
|
42
|
+
raw = %x{#{bin_path} #{opt_str} #{f1.path} #{f2.path}}
|
43
|
+
f1.close; f2.close
|
44
|
+
raw
|
45
|
+
end
|
14
46
|
end
|
15
47
|
|
16
|
-
def wdiff(str_new)
|
17
|
-
|
18
|
-
f1.write(self); f1.flush
|
19
|
-
f2.write(str_new); f2.flush
|
20
|
-
raw = %x{#{Wdiff::bin_path} #{f1.path} #{f2.path}}
|
21
|
-
f1.close; f2.close
|
22
|
-
raw
|
48
|
+
def wdiff(str_new, options={})
|
49
|
+
Wdiff::diff(self, str_new, options)
|
23
50
|
end
|
24
|
-
|
51
|
+
|
25
52
|
module Helper
|
26
|
-
def self.to_html(
|
27
|
-
|
53
|
+
def self.to_html(old_str,new_str)
|
54
|
+
Wdiff::diff(old_str, new_str, :inserts => ["<ins>", "</ins>"], :deletes => ["<del>", "</del>"])
|
28
55
|
end
|
29
56
|
end
|
30
57
|
end
|
data/spec/wdiff_spec.rb
CHANGED
@@ -1,12 +1,50 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Wdiff" do
|
4
|
-
|
5
|
-
|
4
|
+
context "On String Instance" do
|
5
|
+
it "should return the diff with another string" do
|
6
|
+
'this is a test'.wdiff('this is another test').should == 'this is [-a-] {+another+} test'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should allow overriding the delete regions" do
|
10
|
+
'this is a test'.wdiff('this is another test', :deletes => ["<del>", "</del>"]).should == 'this is <del>a</del> {+another+} test'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should allow overriding the insert regions" do
|
14
|
+
'this is a test'.wdiff('this is another test', :inserts => ["<ins>", "</ins>"]).should == 'this is [-a-] <ins>another</ins> test'
|
15
|
+
end
|
16
|
+
|
6
17
|
end
|
7
18
|
|
8
|
-
|
9
|
-
|
19
|
+
context "Library" do
|
20
|
+
it "should cope with nil strings" do
|
21
|
+
Wdiff.diff(nil, nil).should == ""
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not fail when double quote are entered for inserts" do
|
25
|
+
'this is a test'.wdiff('this is another test', :inserts => ["\"", "\""]).should == 'this is [-a-] "another" test'
|
26
|
+
'this is a test'.wdiff('this is another test', :inserts => ['"', '"']).should == 'this is [-a-] "another" test'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should ignore unnecessary tokens for inserts" do
|
30
|
+
'this is a test'.wdiff('this is another test', :inserts => ['"', "'", 'dddd']).should == "this is [-a-] \"another' test"
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
it "should not fail when double quote are entered for deletes" do
|
35
|
+
'this is a test'.wdiff('this is another test', :deletes => ["\"", "\""]).should == 'this is "a" {+another+} test'
|
36
|
+
'this is a test'.wdiff('this is another test', :deletes => ['"', '"']).should == 'this is "a" {+another+} test'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should ignore unnecessary tokens for deletes" do
|
40
|
+
'this is a test'.wdiff('this is another test', :deletes => ['"', "'", 'dddd']).should == "this is \"a' {+another+} test"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "Helper" do
|
45
|
+
it "should return the HTML diff of two strings" do
|
46
|
+
Wdiff::Helper.to_html('this is a test','this is another test').should == 'this is <del>a</del> <ins>another</ins> test'
|
47
|
+
end
|
10
48
|
end
|
11
49
|
|
12
50
|
it "should raise error if xdiff is not in $PATH" do
|
data/wdiff.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{wdiff}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Jerome Riga}]
|
12
|
+
s.date = %q{2011-09-28}
|
13
|
+
s.description = %q{string word diff with other string; Wdiff::Helper.to_html transforms diff string in html snippet}
|
14
|
+
s.email = %q{jriga@zemis.co.uk}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/wdiff.rb",
|
28
|
+
"spec/spec_helper.rb",
|
29
|
+
"spec/wdiff_spec.rb",
|
30
|
+
"wdiff.gemspec"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/zemis/wdiff}
|
33
|
+
s.licenses = [%q{MIT}]
|
34
|
+
s.require_paths = [%q{lib}]
|
35
|
+
s.rubygems_version = %q{1.8.6}
|
36
|
+
s.summary = %q{adds the wdiff method to String instance}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/spec_helper.rb",
|
39
|
+
"spec/wdiff_spec.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
|
47
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
51
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, ["~> 2.1.0"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
metadata
CHANGED
@@ -1,81 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: wdiff
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 2
|
10
|
-
version: 0.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jerome Riga
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
12
|
+
date: 2011-09-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
24
15
|
name: rspec
|
25
|
-
|
16
|
+
requirement: &2154020660 !ruby/object:Gem::Requirement
|
26
17
|
none: false
|
27
|
-
requirements:
|
18
|
+
requirements:
|
28
19
|
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 11
|
31
|
-
segments:
|
32
|
-
- 2
|
33
|
-
- 1
|
34
|
-
- 0
|
20
|
+
- !ruby/object:Gem::Version
|
35
21
|
version: 2.1.0
|
36
|
-
requirement: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
22
|
type: :development
|
39
23
|
prerelease: false
|
24
|
+
version_requirements: *2154020660
|
25
|
+
- !ruby/object:Gem::Dependency
|
40
26
|
name: bundler
|
41
|
-
|
27
|
+
requirement: &2154020180 !ruby/object:Gem::Requirement
|
42
28
|
none: false
|
43
|
-
requirements:
|
29
|
+
requirements:
|
44
30
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
hash: 23
|
47
|
-
segments:
|
48
|
-
- 1
|
49
|
-
- 0
|
50
|
-
- 0
|
31
|
+
- !ruby/object:Gem::Version
|
51
32
|
version: 1.0.0
|
52
|
-
requirement: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
33
|
type: :development
|
55
34
|
prerelease: false
|
35
|
+
version_requirements: *2154020180
|
36
|
+
- !ruby/object:Gem::Dependency
|
56
37
|
name: jeweler
|
57
|
-
|
38
|
+
requirement: &2154019700 !ruby/object:Gem::Requirement
|
58
39
|
none: false
|
59
|
-
requirements:
|
40
|
+
requirements:
|
60
41
|
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
hash: 1
|
63
|
-
segments:
|
64
|
-
- 1
|
65
|
-
- 5
|
66
|
-
- 1
|
42
|
+
- !ruby/object:Gem::Version
|
67
43
|
version: 1.5.1
|
68
|
-
|
69
|
-
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2154019700
|
47
|
+
description: string word diff with other string; Wdiff::Helper.to_html transforms
|
48
|
+
diff string in html snippet
|
70
49
|
email: jriga@zemis.co.uk
|
71
50
|
executables: []
|
72
|
-
|
73
51
|
extensions: []
|
74
|
-
|
75
|
-
extra_rdoc_files:
|
52
|
+
extra_rdoc_files:
|
76
53
|
- LICENSE.txt
|
77
54
|
- README.rdoc
|
78
|
-
files:
|
55
|
+
files:
|
79
56
|
- .document
|
80
57
|
- .rspec
|
81
58
|
- Gemfile
|
@@ -86,40 +63,35 @@ files:
|
|
86
63
|
- lib/wdiff.rb
|
87
64
|
- spec/spec_helper.rb
|
88
65
|
- spec/wdiff_spec.rb
|
89
|
-
|
90
|
-
homepage: http://github.com/
|
91
|
-
licenses:
|
66
|
+
- wdiff.gemspec
|
67
|
+
homepage: http://github.com/zemis/wdiff
|
68
|
+
licenses:
|
92
69
|
- MIT
|
93
70
|
post_install_message:
|
94
71
|
rdoc_options: []
|
95
|
-
|
96
|
-
require_paths:
|
72
|
+
require_paths:
|
97
73
|
- lib
|
98
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
75
|
none: false
|
100
|
-
requirements:
|
101
|
-
- -
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
|
104
|
-
segments:
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
segments:
|
105
81
|
- 0
|
106
|
-
|
107
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
hash: 1527886557485215717
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
84
|
none: false
|
109
|
-
requirements:
|
110
|
-
- -
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
|
113
|
-
segments:
|
114
|
-
- 0
|
115
|
-
version: "0"
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
116
89
|
requirements: []
|
117
|
-
|
118
90
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.
|
91
|
+
rubygems_version: 1.8.6
|
120
92
|
signing_key:
|
121
93
|
specification_version: 3
|
122
94
|
summary: adds the wdiff method to String instance
|
123
|
-
test_files:
|
95
|
+
test_files:
|
124
96
|
- spec/spec_helper.rb
|
125
97
|
- spec/wdiff_spec.rb
|