palmister 0.0.1 → 0.0.2
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/lib/palmister/simple_correction_diff.rb +21 -19
- data/lib/palmister/simple_html_diff.rb +28 -26
- data/lib/palmister/simple_line_diff.rb +18 -16
- data/lib/palmister/vc_diff.rb +46 -45
- data/lib/palmister/version.rb +1 -1
- metadata +1 -1
@@ -1,31 +1,33 @@
|
|
1
1
|
#require 'action_view/template_handlers/erb'
|
2
|
-
|
3
|
-
|
2
|
+
module Palmister
|
3
|
+
class SimpleCorrectionDiff #:nodoc:
|
4
|
+
include ERB::Util
|
4
5
|
|
5
|
-
|
6
|
+
attr_accessor :content
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def initialize
|
9
|
+
@content = ""
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def change(event)
|
13
|
+
out = Palmister::StringSimpleCorrectionDiff.new
|
14
|
+
Diff::LCS.traverse_sequences(event.old_element, event.new_element, out)
|
15
|
+
@content << %Q|<span class="change">#{out.content}#{out.closing}</span><br/></span><br/>\n|
|
16
|
+
end
|
16
17
|
|
17
18
|
# This will be called with both lines are the same
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def match(event)
|
20
|
+
@content << %Q|<span class="match">#{event.new_element}</span><br/>\n|
|
21
|
+
end
|
21
22
|
|
22
23
|
# This will be called when there is a line in A that isn't in B
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def discard_a(event)
|
25
|
+
@content << %Q|<span class="only_a"><del>#{event.old_element}</del></span><br/>\n|
|
26
|
+
end
|
26
27
|
|
27
28
|
# This will be called when there is a line in B that isn't in A
|
28
|
-
|
29
|
-
|
29
|
+
def discard_b(event)
|
30
|
+
@content << %Q|<span class="only_b"><ins>#{event.new_element}</ins></span><br/>\n|
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
@@ -1,36 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Palmister
|
2
|
+
class SimpleHtmlDiff #:nodoc:
|
3
|
+
attr_accessor :content
|
4
|
+
attr_accessor :old_line
|
5
|
+
attr_accessor :new_line
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def initialize
|
8
|
+
@content = ""
|
9
|
+
@old_line = 1
|
10
|
+
@new_line = 1
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def change(event)
|
14
|
+
@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|
|
15
|
+
@old_line += 1
|
16
|
+
@new_line += 1
|
17
|
+
end
|
17
18
|
|
18
19
|
# This will be called with both lines are the same
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def match(event)
|
21
|
+
@content << %Q|<tr><td>#{old_line}. </td><td colspan="2"><pre class="match">#{event.old_element}</pre></td><td>#{new_line}. </td></tr>\n|
|
22
|
+
@old_line += 1
|
23
|
+
@new_line += 1
|
24
|
+
end
|
24
25
|
|
25
26
|
# This will be called when there is a line in A that isn't in B
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def discard_a(event)
|
28
|
+
@content << %Q|<tr><td>#{old_line}. </td><td><pre class="only_a">#{event.old_element}</pre></td><td></td><td></td></tr>\n|
|
29
|
+
@old_line += 1
|
30
|
+
end
|
30
31
|
|
31
32
|
# This will be called when there is a line in B that isn't in A
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def discard_b(event)
|
34
|
+
@content << %Q|<tr><td></td><td></td><td><pre class="only_b">#{event.new_element}</pre></td><td>#{new_line}. </td></tr>\n|
|
35
|
+
@new_line += 1
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Palmister
|
2
|
+
class SimpleLineDiff #:nodoc:
|
3
|
+
attr_accessor :content
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def initialize
|
6
|
+
@content = ""
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def change(event)
|
10
|
+
@content << %Q|<span class="only_a">#{event.old_element}</span><br/>\n<span class="only_b">#{event.new_element}</span><br/>\n|
|
11
|
+
end
|
11
12
|
|
12
13
|
# This will be called with both lines are the same
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def match(event)
|
15
|
+
@content << %Q|<span class="match">#{event.old_element}</span><br/>\n|
|
16
|
+
end
|
16
17
|
|
17
18
|
# This will be called when there is a line in A that isn't in B
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def discard_a(event)
|
20
|
+
@content << %Q|<span class="only_a">#{event.old_element}</span><br/>\n|
|
21
|
+
end
|
21
22
|
|
22
23
|
# This will be called when there is a line in B that isn't in A
|
23
|
-
|
24
|
-
|
24
|
+
def discard_b(event)
|
25
|
+
@content << %Q|<span class="only_b">#{event.new_element}</span><br/>\n|
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/palmister/vc_diff.rb
CHANGED
@@ -1,59 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
module Palmister
|
2
|
+
class VcDiff #:nodoc:
|
3
|
+
attr_accessor :content
|
4
|
+
attr_accessor :old_line
|
5
|
+
attr_accessor :new_line
|
6
|
+
attr_accessor :last_lines
|
7
|
+
attr_accessor :last
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@content = ""
|
11
|
+
@last_lines = []
|
12
|
+
@old_line = 1
|
13
|
+
@new_line = 1
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def change(event)
|
17
|
+
add_last_lines unless @last == :change
|
18
|
+
@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
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
@last = :change
|
21
|
+
@old_line += 1
|
22
|
+
@new_line += 1
|
23
|
+
end
|
23
24
|
|
24
25
|
# This will be called with both lines are the same
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def match(event)
|
27
|
+
@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|
|
28
|
+
@old_line += 1
|
29
|
+
@new_line += 1
|
30
|
+
end
|
30
31
|
|
31
32
|
# This will be called when there is a line in A that isn't in B
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def discard_a(event)
|
34
|
+
add_last_lines unless @last == :discard_a
|
35
|
+
@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
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
@last = :discard_a
|
38
|
+
@old_line += 1
|
39
|
+
end
|
39
40
|
|
40
41
|
# This will be called when there is a line in B that isn't in A
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def discard_b(event)
|
43
|
+
add_last_lines unless @last == :discard_b
|
44
|
+
@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
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
@last = :discard_b
|
47
|
+
@new_line += 1
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
def add_last_lines(n = 3)
|
51
|
+
@content << %Q|<tr><td colspan="4">Next Change: </td></tr>\n|
|
52
|
+
start = @last_lines.length - n
|
53
|
+
start = 0 if start < 0
|
54
|
+
start.upto @last_lines.length do |i|
|
55
|
+
@content << @last_lines[i] if @last_lines[i]
|
56
|
+
end
|
57
|
+
@last_lines = []
|
55
58
|
end
|
56
|
-
@last_lines = []
|
57
59
|
end
|
58
|
-
|
59
60
|
end
|
data/lib/palmister/version.rb
CHANGED