This commit is contained in:
Toks
2014-08-12 12:41:10 -04:00
parent 3d7e462f43
commit 424eb40c9d
2 changed files with 6 additions and 22 deletions

View File

@@ -1,10 +1,16 @@
module WikiPageVersionsHelper
def wiki_page_diff(thispage, otherpage)
pattern = Regexp.new('(?:<.+?>)|(?:\w+)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)')
other_names_pattern = Regexp.new('\S+|\s+')
thisarr = thispage.body.scan(pattern)
otharr = otherpage.body.scan(pattern)
if thispage.other_names.present? || otherpage.other_names.present?
thisarr = "#{thispage.other_names}\n\n".scan(other_names_pattern) + thisarr
otharr = "#{otherpage.other_names}\n\n".scan(other_names_pattern) + otharr
end
cbo = Diff::LCS::ContextDiffCallbacks.new
diffs = thisarr.diff(otharr, cbo)
@@ -48,24 +54,4 @@ module WikiPageVersionsHelper
output.join.gsub(/\r?\n/, '<br>').html_safe
end
def wiki_page_other_names_diff(thispage, otherpage)
new_names = otherpage.other_names_array
old_names = thispage.other_names_array
added_names = new_names - old_names
removed_names = old_names - new_names
unchanged_names = new_names & old_names
html = []
added_names.each do |name|
html << '<ins>' + name + '</ins>'
end
removed_names.each do |name|
html << '<del>' + name + '</del>'
end
unchanged_names.each do |name|
html << '<span>' + name + '</span>'
end
return html.join(" ").html_safe
end
end

View File

@@ -4,8 +4,6 @@
<p>Showing differences between <%= compact_time @thispage.updated_at %> (<%= link_to_user @thispage.updater %>) and <%= compact_time @otherpage.updated_at %> (<%= link_to_user @otherpage.updater %>)</p>
<p><%= wiki_page_other_names_diff(@thispage, @otherpage) %></p>
<div>
<%= wiki_page_diff(@thispage, @otherpage) %>
</div>