dirb 1.0.0 → 1.1.0

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.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ *.swp
data/CHANGELOG ADDED
@@ -0,0 +1,5 @@
1
+ == 1.0.1 ==
2
+ * Compatibility with ruby 1.8.6 and 1.9
3
+
4
+ == 1.0.0 ==
5
+ * HTML output and better documentation
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.
data/README.md CHANGED
@@ -40,26 +40,28 @@ Here's an example of using Dirb to diff two strings
40
40
  Outputing the diff as html is easy too.
41
41
 
42
42
  >> puts Dirb::Diff.new(string1, string2).to_s(:html)
43
- <ul class="diff">
44
- <li class="del"><del>Hello how are you</del></li>
45
- <li class="ins"><ins>Hello how are you?</ins></li>
46
- <li class="unchanged"><span>I'm fine</span></li>
47
- <li class="del"><del>That's great</del></li>
48
- <li class="ins"><ins>That's swell</ins></li>
49
- </ul>
43
+ <div class="diff">
44
+ <ul>
45
+ <li class="del"><del>Hello how are you</del></li>
46
+ <li class="ins"><ins>Hello how are you?</ins></li>
47
+ <li class="unchanged"><span>I'm fine</span></li>
48
+ <li class="del"><del>That's great</del></li>
49
+ <li class="ins"><ins>That's swell</ins></li>
50
+ </ul>
51
+ </div>
50
52
 
51
53
  Then try adding this css to your stylesheets:
52
54
 
53
- .diff{overflow:auto;}
54
- .diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
55
- .diff del, .diff ins{display:block;text-decoration:none;}
56
- .diff li{padding:0; display:table-row;margin: 0;}
57
- .diff li.ins{background:#9f9;}
58
- .diff li.del{background:#ccf;}
59
- .diff li:hover{background:#ffc}
60
- .diff del, .diff ins, .diff span{white-space:pre;font-family:courier;}
55
+ .diff{overflow:auto;}
56
+ .diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
57
+ .diff del, .diff ins{display:block;text-decoration:none;}
58
+ .diff li{padding:0; display:table-row;margin: 0;}
59
+ .diff li.ins{background:#9f9;}
60
+ .diff li.del{background:#ccf;}
61
+ .diff li:hover{background:#ffc}
62
+ .diff del, .diff ins, .diff span{white-space:pre;font-family:courier;}
61
63
 
62
- Dirb::Diff also alows you to set a default format. Here we set the default to
64
+ `Dirb::Diff` also alows you to set a default format. Here we set the default to
63
65
  use ANSI termnial color escape sequences.
64
66
 
65
67
  >> Dirb::Diff.default_format = :color
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ task :default => :spec
7
7
  desc "Run all specs in spec directory"
8
8
  Spec::Rake::SpecTask.new(:spec) do |t|
9
9
  t.spec_files = FileList['spec/**/*_spec.rb']
10
+ t.spec_opts = %w{--color --format profile}
10
11
  end
11
12
 
12
13
  Rake::RDocTask.new do |rd|
@@ -19,7 +20,6 @@ begin
19
20
  require 'jeweler'
20
21
  Jeweler::Tasks.new do |s|
21
22
  s.name = %q{dirb}
22
- s.version = "0.1.0"
23
23
 
24
24
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
25
25
  s.authors = ["Sam Goldstein"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/dirb.gemspec CHANGED
@@ -1,22 +1,26 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dirb}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sam Goldstein"]
12
- s.date = %q{2010-06-29}
12
+ s.date = %q{2010-10-15}
13
13
  s.description = %q{Convenient diffing in ruby}
14
14
  s.email = %q{sgrock@gmail.com}
15
15
  s.extra_rdoc_files = [
16
- "README.md"
16
+ "LICENSE",
17
+ "README.md"
17
18
  ]
18
19
  s.files = [
19
- "README.md",
20
+ ".gitignore",
21
+ "CHANGELOG",
22
+ "LICENSE",
23
+ "README.md",
20
24
  "Rakefile",
21
25
  "VERSION",
22
26
  "dirb.gemspec",
@@ -26,7 +30,7 @@ Gem::Specification.new do |s|
26
30
  s.homepage = %q{http://github.com/samg/dirb/tree/master}
27
31
  s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
28
32
  s.require_paths = ["lib"]
29
- s.rubygems_version = %q{1.3.5}
33
+ s.rubygems_version = %q{1.3.7}
30
34
  s.summary = %q{A convenient way to diff string in ruby}
31
35
  s.test_files = [
32
36
  "spec/dirb_spec.rb"
@@ -36,9 +40,10 @@ Gem::Specification.new do |s|
36
40
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
41
  s.specification_version = 3
38
42
 
39
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
44
  else
41
45
  end
42
46
  else
43
47
  end
44
48
  end
49
+
data/lib/dirb.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'tempfile'
3
3
  require 'open3'
4
+ require 'erb'
4
5
  module Dirb
5
6
  class Diff
6
7
  class << self
@@ -25,7 +26,9 @@ module Dirb
25
26
  end
26
27
 
27
28
  def each &block
28
- diff.each_line.reject{|x| x =~ /^---|\+\+\+|@@/ }.each &block
29
+ diff.split("\n").reject{|x| x =~ /^---|\+\+\+|@@/ }.each do |line|
30
+ block.call line + "\n"
31
+ end
29
32
  end
30
33
 
31
34
  def tempfile(string)
@@ -37,9 +40,9 @@ module Dirb
37
40
 
38
41
  def to_s(format = nil)
39
42
  format ||= self.class.default_format
40
- formats = Format.instance_methods(false)
43
+ formats = Format.instance_methods(false).map{|x| x.to_s}
41
44
  if formats.include? format.to_s
42
- enum = self.each
45
+ enum = self.to_a
43
46
  enum.extend Format
44
47
  enum.send format
45
48
  else
@@ -79,11 +82,11 @@ module Dirb
79
82
  lines = map do |line|
80
83
  case line
81
84
  when /^\+/
82
- ' <li class="ins"><ins>' + line.gsub(/^./, '').chomp + '</ins></li>'
85
+ ' <li class="ins"><ins>' + ERB::Util.h(line.gsub(/^./, '').chomp) + '</ins></li>'
83
86
  when /^-/
84
- ' <li class="del"><del>' + line.gsub(/^./, '').chomp + '</del></li>'
87
+ ' <li class="del"><del>' + ERB::Util.h(line.gsub(/^./, '').chomp) + '</del></li>'
85
88
  when /^ /
86
- ' <li class="unchanged"><span>' + line.gsub(/^./, '').chomp + '</span></li>'
89
+ ' <li class="unchanged"><span>' + ERB::Util.h(line.gsub(/^./, '').chomp) + '</span></li>'
87
90
  end
88
91
  end
89
92
  %'<div class="diff">\n <ul>\n#{lines.join("\n")}\n </ul>\n</div>\n'
data/spec/dirb_spec.rb CHANGED
@@ -135,6 +135,21 @@ baz
135
135
  DIFF
136
136
  end
137
137
  end
138
+
139
+ it "should escape diffed html in html output" do
140
+ diff = Dirb::Diff.new("<script>alert('bar')</script>", "<script>alert('foo')</script>").to_s(:html)
141
+ diff.should include('&lt;script&gt;')
142
+ diff.should_not include('<script>')
143
+ end
144
+
145
+ it "should be easy to generate custom format" do
146
+ Dirb::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").map do |line|
147
+ case line
148
+ when /^\+/ then "line #{line.chomp} added"
149
+ when /^-/ then "line #{line.chomp} removed"
150
+ end
151
+ end.compact.join.should == "line +baz added"
152
+ end
138
153
  end
139
154
  end
140
155
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Sam Goldstein
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-06-29 00:00:00 -07:00
18
+ date: 2010-10-15 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -20,8 +26,12 @@ executables: []
20
26
  extensions: []
21
27
 
22
28
  extra_rdoc_files:
29
+ - LICENSE
23
30
  - README.md
24
31
  files:
32
+ - .gitignore
33
+ - CHANGELOG
34
+ - LICENSE
25
35
  - README.md
26
36
  - Rakefile
27
37
  - VERSION
@@ -39,21 +49,27 @@ rdoc_options:
39
49
  require_paths:
40
50
  - lib
41
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
42
53
  requirements:
43
54
  - - ">="
44
55
  - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
45
59
  version: "0"
46
- version:
47
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
48
62
  requirements:
49
63
  - - ">="
50
64
  - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
51
68
  version: "0"
52
- version:
53
69
  requirements: []
54
70
 
55
71
  rubyforge_project:
56
- rubygems_version: 1.3.5
72
+ rubygems_version: 1.3.7
57
73
  signing_key:
58
74
  specification_version: 3
59
75
  summary: A convenient way to diff string in ruby