diffy 2.0.4 → 2.0.5

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/CONTRIBUTORS ADDED
@@ -0,0 +1,3 @@
1
+ * Sam Goldstein
2
+ * joelash
3
+ * chaffeqa
data/README.md CHANGED
@@ -74,6 +74,8 @@ Then try adding this css to your stylesheets:
74
74
  .diff del, .diff ins, .diff span{white-space:pre-wrap;font-family:courier;}
75
75
  .diff del strong{font-weight:normal;background:#fcc;}
76
76
  .diff ins strong{font-weight:normal;background:#9f9;}
77
+ .diff li.diff-comment { display: none; }
78
+ .diff li.diff-block-info { background: none repeat scroll 0 0 gray; }
77
79
 
78
80
  You can also diff files instead of strings
79
81
 
@@ -103,6 +105,23 @@ deletions, and unchanged in a diff.
103
105
 
104
106
  Use `#map`, `#inject`, or any of Enumerable's methods. Go crazy.
105
107
 
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
+
106
125
  Ruby Version Compatibility
107
126
  -------------------------
108
127
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.4
1
+ 2.0.5
data/lib/diffy/diff.rb CHANGED
@@ -14,7 +14,7 @@ module Diffy
14
14
  # +:source+:: Either _strings_ or _files_. Determines whether string1
15
15
  # and string2 should be interpreted as strings or file paths.
16
16
  def initialize(string1, string2, options = {})
17
- @options = {:diff => '-U 10000', :source => 'strings'}.merge(options)
17
+ @options = {:diff => '-U 10000', :source => 'strings', :include_diff_info => false}.merge(options)
18
18
  if ! ['strings', 'files'].include?(@options[:source])
19
19
  raise ArgumentError, "Invalid :source option #{@options[:source].inspect}. Supported options are 'strings' and 'files'."
20
20
  end
@@ -42,8 +42,10 @@ module Diffy
42
42
  end
43
43
 
44
44
  def each
45
- lines = diff.split("\n").reject{|x| x =~ /^(---|\+\+\+|@@|\\\\)/ }.
46
- map{|line| line + "\n"}
45
+ lines = case @options[:include_diff_info]
46
+ when false then diff.split("\n").reject{|x| x =~ /^(---|\+\+\+|@@|\\\\)/ }.map {|line| line + "\n" }
47
+ when true then diff.split("\n").map {|line| line + "\n" }
48
+ end
47
49
  if block_given?
48
50
  lines.each{|line| yield line}
49
51
  else
data/lib/diffy/format.rb CHANGED
@@ -3,11 +3,15 @@ module Diffy
3
3
  # ANSI color output suitable for terminal output
4
4
  def color
5
5
  map do |line|
6
- case line
6
+ case line
7
+ when /^(---|\+\+\+|\\\\)/
8
+ "\033[90m#{line.chomp}\033[0m"
7
9
  when /^\+/
8
10
  "\033[32m#{line.chomp}\033[0m"
9
11
  when /^-/
10
12
  "\033[31m#{line.chomp}\033[0m"
13
+ when /^@@/
14
+ "\033[36m#{line.chomp}\033[0m"
11
15
  else
12
16
  line.chomp
13
17
  end
@@ -17,12 +17,16 @@ module Diffy
17
17
  def wrap_line(line)
18
18
  cleaned = line.gsub(/^./, '').chomp
19
19
  case line
20
+ when /^(---|\+\+\+|\\\\)/
21
+ ' <li class="diff-comment"><span>' + line.chomp + '</span></li>'
20
22
  when /^\+/
21
23
  ' <li class="ins"><ins>' + cleaned + '</ins></li>'
22
24
  when /^-/
23
25
  ' <li class="del"><del>' + cleaned + '</del></li>'
24
26
  when /^ /
25
27
  ' <li class="unchanged"><span>' + cleaned + '</span></li>'
28
+ when /^@@/
29
+ ' <li class="diff-block-info"><span>' + line.chomp + '</span></li>'
26
30
  end
27
31
  end
28
32
 
data/spec/diffy_spec.rb CHANGED
@@ -55,6 +55,41 @@ describe Diffy::Diff do
55
55
  end
56
56
 
57
57
  end
58
+
59
+ describe "options[:include_diff_info]" do
60
+ it "defaults to false" do
61
+ @diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n")
62
+ @diffy.options[:include_diff_info].should == false
63
+ end
64
+
65
+ it "can be set to true" do
66
+ @diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :include_diff_info => true )
67
+ @diffy.options[:include_diff_info].should == true
68
+ end
69
+
70
+ it "includes all diff output" do
71
+ output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_diff_info => true ).to_s
72
+ output.to_s.should match( /@@/)
73
+ output.should match( /---/)
74
+ output.should match( /\+\+\+/)
75
+ end
76
+
77
+ describe "formats" do
78
+ it "works for :color" do
79
+ output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_diff_info => true ).to_s(:color)
80
+ output.should match( /\e\[0m\n\e\[36m\@\@/ )
81
+ output.to_s.should match( /\e\[90m---/)
82
+ output.to_s.should match( /\e\[0m\n\e\[90m\+\+\+/)
83
+ end
84
+
85
+ it "works for :html_simple" do
86
+ output = Diffy::Diff.new("foo\nbar\nbang\n", "foo\nbang\n", :include_diff_info => true ).to_s(:html_simple)
87
+ output.split("\n").should include( " <li class=\"diff-block-info\"><span>@@ -1,3 +1,2 @@</span></li>" )
88
+ output.should include( "<li class=\"diff-comment\"><span>---")
89
+ output.should include( "<li class=\"diff-comment\"><span>+++")
90
+ end
91
+ end
92
+ end
58
93
 
59
94
  describe "options[:diff]" do
60
95
  it "should accept an option to diff" do
@@ -118,7 +153,8 @@ describe Diffy::Diff do
118
153
  end
119
154
 
120
155
  it "should show one line added" do
121
- Diffy::Diff.new(@string2, @string1).to_s.should == <<-DIFF
156
+ Diffy::Diff.new(@string2, @string1).to_s.
157
+ should == <<-DIFF
122
158
  foo
123
159
  +bar
124
160
  bang
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diffy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 4
10
- version: 2.0.4
9
+ - 5
10
+ version: 2.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Goldstein
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-11 00:00:00 -07:00
18
+ date: 2011-11-21 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -61,6 +61,7 @@ extra_rdoc_files:
61
61
  files:
62
62
  - .rspec
63
63
  - CHANGELOG
64
+ - CONTRIBUTORS
64
65
  - Gemfile
65
66
  - LICENSE
66
67
  - README.md