colibri 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ MIT-LICENSE
2
+ README
3
+ Rakefile
4
+ init.rb
5
+ lib/colibri.rb
6
+ lib/diff_helper.rb
7
+ lib/output/simple_correction_diff.rb
8
+ lib/output/simple_html_diff.rb
9
+ lib/output/string_simple_correction_diff.rb
10
+ lib/output/vc_diff.rb
11
+ sample.css
12
+ Manifest
data/README ADDED
@@ -0,0 +1,54 @@
1
+ =Colibri
2
+ ====
3
+
4
+ This is a small plug-in to provide an easy way to display a diff of two "files"
5
+ (long strings...) as html. It uses the diff-lcs gem to calculate the diff.
6
+ The default output "generator" creates table-rows in the following scheme:
7
+
8
+ | Old-Line-Nr | Old-File | New-File | Old-Line-Nr |
9
+
10
+ It applies different css classes to the elements depending on match/difference.
11
+
12
+ ==Source
13
+ ====
14
+ https://github.com/IgorDobryn/colibri
15
+
16
+ ==Requirements
17
+ ====
18
+
19
+ This plug-in relies on the diff-lcs gem.
20
+
21
+ ==Installation
22
+ ====
23
+
24
+ install it as any other plug-in and be sure to include the provided sample css or
25
+ your own css rules to the applications-stylesheet.
26
+
27
+ ==Example
28
+ ====
29
+
30
+ in your view simply call:
31
+
32
+ <%= diff(@difftest.old, @difftest.new) %>
33
+
34
+ which results in:
35
+
36
+ <tr><td>1. </td><td><pre class="only_a">require 'digest/sha1'</pre></td><td><pre class="only_b">require 'digest/sha2'</pre></td><td>1. </td></tr>
37
+
38
+ <tr><td>2. </td><td colspan="2"><pre class="match"></pre></td><td>2. </td></tr>
39
+
40
+ <tr><td>3. </td><td colspan="2"><pre class="match">class User < ActiveRecord::Base</pre></td><td>3. </td></tr>
41
+
42
+ ...
43
+
44
+ ==Credits
45
+ ====
46
+ diff-lcs author and the provided exampels ;)
47
+
48
+ ==ToDo
49
+ ====
50
+
51
+ Tests...
52
+
53
+ Copyright (c) 2011 [Igor Dobryn / IgorDobryn@gmail.com], released under the MIT license
54
+
@@ -0,0 +1,17 @@
1
+ require 'psych'
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+
6
+ Echoe.new('colibri', '0.0.1') do |p|
7
+ p.description = "Display a diff of two files (long strings...) as html"
8
+ p.url = "https://github.com/IgorDobryn/colibri"
9
+ p.author = "Igor Dobryn"
10
+ p.email = "IgorDobryn@gmail.com"
11
+ p.ignore_pattern = ["tmp/*", "script/*"]
12
+ p.development_dependencies = ["diff-lcs", "erubis"]
13
+ p.summary = "This gem provide functionality for displaying defference between two files(long strings) as html"
14
+ end
15
+
16
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
17
+
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "colibri"
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Igor Dobryn"]
9
+ s.date = "2011-08-30"
10
+ s.description = "Display a diff of two files (long strings...) as html"
11
+ s.email = "IgorDobryn@gmail.com"
12
+ s.extra_rdoc_files = ["README", "lib/colibri.rb", "lib/diff_helper.rb", "lib/output/simple_correction_diff.rb", "lib/output/simple_html_diff.rb", "lib/output/string_simple_correction_diff.rb", "lib/output/vc_diff.rb"]
13
+ s.files = ["MIT-LICENSE", "README", "Rakefile", "init.rb", "lib/colibri.rb", "lib/diff_helper.rb", "lib/output/simple_correction_diff.rb", "lib/output/simple_html_diff.rb", "lib/output/string_simple_correction_diff.rb", "lib/output/vc_diff.rb", "sample.css", "Manifest", "colibri.gemspec"]
14
+ s.homepage = "https://github.com/IgorDobryn/colibri"
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Colibri", "--main", "README"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = "colibri"
18
+ s.rubygems_version = "1.8.10"
19
+ s.summary = "This gem provide functionality for displaying defference between two files(long strings) as html"
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_development_dependency(%q<diff-lcs>, [">= 0"])
26
+ s.add_development_dependency(%q<erubis>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<diff-lcs>, [">= 0"])
29
+ s.add_dependency(%q<erubis>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<diff-lcs>, [">= 0"])
33
+ s.add_dependency(%q<erubis>, [">= 0"])
34
+ end
35
+ end
data/init.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'erubis'
2
+ require 'colibri'
3
+ config.after_initialize do
4
+ # Include our helper into every view
5
+ ActionView::Base.send :include, DiffHelper
6
+ end
7
+
@@ -0,0 +1,16 @@
1
+ class Colibri
2
+ # add html_escape to class level ;)
3
+ extend ERB::Util
4
+ def self.diff(old, new, output = Output::SimpleHtmlDiff)
5
+ # html_escape code for display and split strings into lines array
6
+ a = html_escape(old).split(/\015?\012/)
7
+ b = html_escape(new).split(/\015?\012/)
8
+ #remove trailing.. whitespace
9
+ #a.map{|c| c.strip!}
10
+ #b.map{|c| c.strip!}
11
+ out = output.new
12
+ Diff::LCS.traverse_balanced(a, b, out)
13
+ out.content
14
+ end
15
+ end
16
+
@@ -0,0 +1,19 @@
1
+ module ColibriHelper
2
+ protected
3
+ # generates a simple line diff
4
+ def line_diff(old, new)
5
+ Colibri.diff(old,new)
6
+ end
7
+
8
+ # generates a simple correction diff with "inline-diffs"
9
+ def correction_diff(old, new)
10
+ Colibri.diff(old, new, Output::SimpleCorrectionDiff)
11
+ end
12
+
13
+ # generates a simple vc similar diff, where only the changes + some preceding
14
+ # lines are shown
15
+ def vc_diff(old,new)
16
+ Colibri.diff(old,new, Output::VcDiff)
17
+ end
18
+ end
19
+
@@ -0,0 +1,31 @@
1
+ class Output::SimpleCorrectionDiff #:nodoc:
2
+ include ERB::Util
3
+
4
+ attr_accessor :content
5
+
6
+ def initialize
7
+ @content = ""
8
+ end
9
+
10
+ def change(event)
11
+ out = Output::StringSimpleCorrectionDiff.new
12
+ Diff::LCS.traverse_sequences(event.old_element, event.new_element, out)
13
+ @content << %Q|<span class="change">#{out.content}#{out.closing}</span><br/></span><br/>\n|
14
+ end
15
+
16
+ # This will be called with both lines are the same
17
+ def match(event)
18
+ @content << %Q|<span class="match">#{event.new_element}</span><br/>\n|
19
+ end
20
+
21
+ # This will be called when there is a line in A that isn't in B
22
+ def discard_a(event)
23
+ @content << %Q|<span class="only_a"><del>#{event.old_element}</del></span><br/>\n|
24
+ end
25
+
26
+ # This will be called when there is a line in B that isn't in A
27
+ def discard_b(event)
28
+ @content << %Q|<span class="only_b"><ins>#{event.new_element}</ins></span><br/>\n|
29
+ end
30
+ end
31
+
@@ -0,0 +1,36 @@
1
+ class Output::SimpleHtmlDiff #:nodoc:
2
+ attr_accessor :content
3
+ attr_accessor :old_line
4
+ attr_accessor :new_line
5
+
6
+ def initialize
7
+ @content = ""
8
+ @old_line = 1
9
+ @new_line = 1
10
+ end
11
+
12
+ def change(event)
13
+ @content << %Q|<tr><td>#{old_line}. </td><td><pre class="only_a">#{event.old_element}</pre></td><td><pre class="only_b">#{event.new_element}</pre></td><td>#{new_line}. </td></tr>\n|
14
+ @old_line += 1
15
+ @new_line += 1
16
+ end
17
+
18
+ # This will be called with both lines are the same
19
+ def match(event)
20
+ @content << %Q|<tr><td>#{old_line}. </td><td colspan="2"><pre class="match">#{event.old_element}</pre></td><td>#{new_line}. </td></tr>\n|
21
+ @old_line += 1
22
+ @new_line += 1
23
+ end
24
+
25
+ # This will be called when there is a line in A that isn't in B
26
+ def discard_a(event)
27
+ @content << %Q|<tr><td>#{old_line}. </td><td><pre class="only_a">#{event.old_element}</pre></td><td></td><td></td></tr>\n|
28
+ @old_line += 1
29
+ end
30
+
31
+ # This will be called when there is a line in B that isn't in A
32
+ def discard_b(event)
33
+ @content << %Q|<tr><td></td><td></td><td><pre class="only_b">#{event.new_element}</pre></td><td>#{new_line}. </td></tr>\n|
34
+ @new_line += 1
35
+ end
36
+ end
@@ -0,0 +1,57 @@
1
+ class Output::StringSimpleCorrectionDiff #:nodoc:
2
+
3
+ attr_accessor :content, :last, :closing
4
+
5
+ def initialize
6
+ @content = ""
7
+
8
+ end
9
+
10
+ def change(event)
11
+ if @last.nil?
12
+ @content << %Q|<span class="change">|
13
+ elsif @last != :change
14
+ @content << %Q|#{closing}</span><span class="change">|
15
+ end
16
+ @content << %Q|<del class="only_a">#{event.old_element}</del><ins class="only_b">#{event.new_element.to_s}</ins>|
17
+ @last = :change
18
+ @closing = ""
19
+ end
20
+
21
+ # This will be called with both lines are the same
22
+ def match(event)
23
+ if @last.nil?
24
+ @content << %Q|<span class="match">|
25
+ elsif @last != :match
26
+ @content << %Q|#{closing}</span><span class="match">|
27
+ end
28
+ @content << event.old_element.to_s
29
+ @last = :match
30
+ @closing = ""
31
+ end
32
+
33
+ # This will be called when there is a line in A that isn't in B
34
+ def discard_a(event)
35
+ if @last.nil?
36
+ @content << %Q|<span class="only_a"><del>|
37
+ elsif @last != :only_a
38
+ @content << %Q|#{closing}</span><span class="only_a"><del>|
39
+ end
40
+ @content << %Q|#{event.old_element.to_s}|
41
+ @last = :only_a
42
+ @closing = "</del>"
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
+ if @last.nil?
48
+ @content << %Q|<span class="only_b"><ins>|
49
+ elsif @last != :only_b
50
+ @content << %Q|#{closing}</span><span class="only_b"><ins>|
51
+ end
52
+ @content << %Q|#{event.new_element.to_s}|
53
+ @last = :only_b
54
+ @closing = "</ins>"
55
+ end
56
+ end
57
+
@@ -0,0 +1,59 @@
1
+ class Output::VcDiff #:nodoc:
2
+ attr_accessor :content
3
+ attr_accessor :old_line
4
+ attr_accessor :new_line
5
+ attr_accessor :last_lines
6
+ attr_accessor :last
7
+
8
+ def initialize
9
+ @content = ""
10
+ @last_lines = []
11
+ @old_line = 1
12
+ @new_line = 1
13
+ end
14
+
15
+ def change(event)
16
+ add_last_lines unless @last == :change
17
+ @content << %Q|<tr><td>#{old_line}. </td><td><pre class="only_a">#{event.old_element}</pre></td><td><pre class="only_b">#{event.new_element}</pre></td><td>#{new_line}. </td></tr>\n|
18
+
19
+ @last = :change
20
+ @old_line += 1
21
+ @new_line += 1
22
+ end
23
+
24
+ # This will be called with both lines are the same
25
+ def match(event)
26
+ @last_lines.push %Q|<tr><td>#{old_line}. </td><td colspan="2"><pre class="match">#{event.old_element}</pre></td><td>#{new_line}. </td></tr>\n|
27
+ @old_line += 1
28
+ @new_line += 1
29
+ end
30
+
31
+ # This will be called when there is a line in A that isn't in B
32
+ def discard_a(event)
33
+ add_last_lines unless @last == :discard_a
34
+ @content << %Q|<tr><td>#{old_line}. </td><td><pre class="only_a">#{event.old_element}</pre></td><td></td><td></td></tr>\n|
35
+
36
+ @last = :discard_a
37
+ @old_line += 1
38
+ end
39
+
40
+ # This will be called when there is a line in B that isn't in A
41
+ def discard_b(event)
42
+ add_last_lines unless @last == :discard_b
43
+ @content << %Q|<tr><td></td><td></td><td><pre class="only_b">#{event.new_element}</pre></td><td>#{new_line}. </td></tr>\n|
44
+
45
+ @last = :discard_b
46
+ @new_line += 1
47
+ end
48
+
49
+ def add_last_lines(n = 3)
50
+ @content << %Q|<tr><td colspan="4">Next Change: </td></tr>\n|
51
+ start = @last_lines.length - n
52
+ start = 0 if start < 0
53
+ start.upto @last_lines.length do |i|
54
+ @content << @last_lines[i] if @last_lines[i]
55
+ end
56
+ @last_lines = []
57
+ end
58
+
59
+ end
@@ -0,0 +1,24 @@
1
+ .diff {
2
+ border: 1px solid black;
3
+ margin: 1em 2em;
4
+ }
5
+ pre {
6
+ padding-left: 1em;
7
+ margin: 0;
8
+ font-family: Lucida, Courier, monospaced;
9
+ }
10
+ .change {
11
+ background-color: #A6A6A6;
12
+ }
13
+
14
+ .match {
15
+ background-color: #DDFFDD;
16
+ }
17
+ .only_a {
18
+ background-color: #fdd;
19
+ color: red;
20
+ }
21
+ .only_b {
22
+ background-color: #ddf;
23
+ color: blue;
24
+ }
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colibri
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Igor Dobryn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: diff-lcs
16
+ requirement: &71500150 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *71500150
25
+ - !ruby/object:Gem::Dependency
26
+ name: erubis
27
+ requirement: &71499760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *71499760
36
+ description: Display a diff of two files (long strings...) as html
37
+ email: IgorDobryn@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files:
41
+ - README
42
+ - lib/colibri.rb
43
+ - lib/diff_helper.rb
44
+ - lib/output/simple_correction_diff.rb
45
+ - lib/output/simple_html_diff.rb
46
+ - lib/output/string_simple_correction_diff.rb
47
+ - lib/output/vc_diff.rb
48
+ files:
49
+ - MIT-LICENSE
50
+ - README
51
+ - Rakefile
52
+ - init.rb
53
+ - lib/colibri.rb
54
+ - lib/diff_helper.rb
55
+ - lib/output/simple_correction_diff.rb
56
+ - lib/output/simple_html_diff.rb
57
+ - lib/output/string_simple_correction_diff.rb
58
+ - lib/output/vc_diff.rb
59
+ - sample.css
60
+ - Manifest
61
+ - colibri.gemspec
62
+ homepage: https://github.com/IgorDobryn/colibri
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --line-numbers
67
+ - --inline-source
68
+ - --title
69
+ - Colibri
70
+ - --main
71
+ - README
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '1.2'
86
+ requirements: []
87
+ rubyforge_project: colibri
88
+ rubygems_version: 1.8.10
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: This gem provide functionality for displaying defference between two files(long
92
+ strings) as html
93
+ test_files: []