annotate .svn/pristine/60/60c7c698ddb29ef3812a4b75182c078fbc9cc19b.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 module Redmine
Chris@909 19 module Helpers
Chris@909 20 class Diff
Chris@909 21 include ERB::Util
Chris@909 22 include ActionView::Helpers::TagHelper
Chris@909 23 include ActionView::Helpers::TextHelper
Chris@909 24 attr_reader :diff, :words
Chris@909 25
Chris@909 26 def initialize(content_to, content_from)
Chris@909 27 @words = content_to.to_s.split(/(\s+)/)
Chris@909 28 @words = @words.select {|word| word != ' '}
Chris@909 29 words_from = content_from.to_s.split(/(\s+)/)
Chris@909 30 words_from = words_from.select {|word| word != ' '}
Chris@909 31 @diff = words_from.diff @words
Chris@909 32 end
Chris@909 33
Chris@909 34 def to_html
Chris@909 35 words = self.words.collect{|word| h(word)}
Chris@909 36 words_add = 0
Chris@909 37 words_del = 0
Chris@909 38 dels = 0
Chris@909 39 del_off = 0
Chris@909 40 diff.diffs.each do |diff|
Chris@909 41 add_at = nil
Chris@909 42 add_to = nil
Chris@909 43 del_at = nil
Chris@909 44 deleted = ""
Chris@909 45 diff.each do |change|
Chris@909 46 pos = change[1]
Chris@909 47 if change[0] == "+"
Chris@909 48 add_at = pos + dels unless add_at
Chris@909 49 add_to = pos + dels
Chris@909 50 words_add += 1
Chris@909 51 else
Chris@909 52 del_at = pos unless del_at
Chris@909 53 deleted << ' ' + h(change[2])
Chris@909 54 words_del += 1
Chris@909 55 end
Chris@909 56 end
Chris@909 57 if add_at
Chris@909 58 words[add_at] = '<span class="diff_in">' + words[add_at]
Chris@909 59 words[add_to] = words[add_to] + '</span>'
Chris@909 60 end
Chris@909 61 if del_at
Chris@909 62 words.insert del_at - del_off + dels + words_add, '<span class="diff_out">' + deleted + '</span>'
Chris@909 63 dels += 1
Chris@909 64 del_off += words_del
Chris@909 65 words_del = 0
Chris@909 66 end
Chris@909 67 end
Chris@909 68 words.join(' ').html_safe
Chris@909 69 end
Chris@909 70 end
Chris@909 71 end
Chris@909 72 end