summaryrefslogtreecommitdiffstats
path: root/app/helpers/wiki_helper.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-07-14 11:25:03 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-07-14 11:25:03 +0000
commit5e20417e6d523372320861f1d9a446ddd75e041f (patch)
tree9f276a706577f6959fb7465e00e74c3f69258c6e /app/helpers/wiki_helper.rb
parentbf74efcd1159d9872cdbdc55e9b859c3b2928ffc (diff)
downloadredmine-5e20417e6d523372320861f1d9a446ddd75e041f.tar.gz
redmine-5e20417e6d523372320861f1d9a446ddd75e041f.zip
Added wiki diff.
Diff can be viewed from the page history, or directly from the project activity page for each edit. Uses Lars Christensen's diff library. git-svn-id: http://redmine.rubyforge.org/svn/trunk@583 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers/wiki_helper.rb')
-rw-r--r--app/helpers/wiki_helper.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb
index 32b376925..980035bd4 100644
--- a/app/helpers/wiki_helper.rb
+++ b/app/helpers/wiki_helper.rb
@@ -16,4 +16,41 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module WikiHelper
+
+ def html_diff(wdiff)
+ words = wdiff.words.collect{|word| h(word)}
+ words_add = 0
+ words_del = 0
+ dels = 0
+ del_off = 0
+ wdiff.diff.diffs.each do |diff|
+ add_at = nil
+ add_to = nil
+ del_at = nil
+ deleted = ""
+ diff.each do |change|
+ pos = change[1]
+ if change[0] == "+"
+ add_at = pos + dels unless add_at
+ add_to = pos + dels
+ words_add += 1
+ else
+ del_at = pos unless del_at
+ deleted << ' ' + change[2]
+ words_del += 1
+ end
+ end
+ if add_at
+ words[add_at] = '<span class="diff_in">' + words[add_at]
+ words[add_to] = words[add_to] + '</span>'
+ end
+ if del_at
+ words.insert del_at - del_off + dels + words_add, '<span class="diff_out">' + deleted + '</span>'
+ dels += 1
+ del_off += words_del
+ words_del = 0
+ end
+ end
+ simple_format_without_paragraph(words.join(' '))
+ end
end