Mercurial > hg > soundsoftware-site
comparison lib/redmine/helpers/diff.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 051f544170fe |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 module Redmine | 18 module Redmine |
20 class Diff | 20 class Diff |
21 include ERB::Util | 21 include ERB::Util |
22 include ActionView::Helpers::TagHelper | 22 include ActionView::Helpers::TagHelper |
23 include ActionView::Helpers::TextHelper | 23 include ActionView::Helpers::TextHelper |
24 attr_reader :diff, :words | 24 attr_reader :diff, :words |
25 | 25 |
26 def initialize(content_to, content_from) | 26 def initialize(content_to, content_from) |
27 @words = content_to.to_s.split(/(\s+)/) | 27 @words = content_to.to_s.split(/(\s+)/) |
28 @words = @words.select {|word| word != ' '} | 28 @words = @words.select {|word| word != ' '} |
29 words_from = content_from.to_s.split(/(\s+)/) | 29 words_from = content_from.to_s.split(/(\s+)/) |
30 words_from = words_from.select {|word| word != ' '} | 30 words_from = words_from.select {|word| word != ' '} |
31 @diff = words_from.diff @words | 31 @diff = words_from.diff @words |
32 end | 32 end |
33 | 33 |
34 def to_html | 34 def to_html |
35 words = self.words.collect{|word| h(word)} | 35 words = self.words.collect{|word| h(word)} |
36 words_add = 0 | 36 words_add = 0 |
37 words_del = 0 | 37 words_del = 0 |
38 dels = 0 | 38 dels = 0 |
39 del_off = 0 | 39 del_off = 0 |
40 diff.diffs.each do |diff| | 40 diff.diffs.each do |diff| |
41 add_at = nil | 41 add_at = nil |
42 add_to = nil | 42 add_to = nil |
43 del_at = nil | 43 del_at = nil |
44 deleted = "" | 44 deleted = "" |
45 diff.each do |change| | 45 diff.each do |change| |
46 pos = change[1] | 46 pos = change[1] |
47 if change[0] == "+" | 47 if change[0] == "+" |
48 add_at = pos + dels unless add_at | 48 add_at = pos + dels unless add_at |
49 add_to = pos + dels | 49 add_to = pos + dels |
63 dels += 1 | 63 dels += 1 |
64 del_off += words_del | 64 del_off += words_del |
65 words_del = 0 | 65 words_del = 0 |
66 end | 66 end |
67 end | 67 end |
68 words.join(' ') | 68 words.join(' ').html_safe |
69 end | 69 end |
70 end | 70 end |
71 end | 71 end |
72 end | 72 end |