Skip to content

Instantly share code, notes, and snippets.

@johnthethird
Created December 15, 2009 17:57
Show Gist options
  • Save johnthethird/257124 to your computer and use it in GitHub Desktop.
Save johnthethird/257124 to your computer and use it in GitHub Desktop.
script/plugin install git://github.com/myobie/htmldiff.git
# bottom of environment.rb
require 'htmldiff'
# in model
class Page < ActiveRecord::Base
extend HTMLDiff
end
# in view
<h1>Revisions for <%= @page.name %></h1>
<ul>
<% @page.revisions.each do |revision| %>
<li>
<b>Revised <%= distance_of_time_in_words_to_now revision.created_at %> ago</b><BR>
<%= Page.diff(
revision.changes['description'][0],
revision.changes['description'][1]
) %>
<BR><BR>
</li>
<% end %>
# in style.css
ins.diffmod, ins.diffins { background: #d4fdd5; text-decoration: none; }
del.diffmod, del.diffdel { color: #ff9999; }
(from http://stackoverflow.com/questions/80091/diff-a-ruby-string-or-array/739161#739161)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment