Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> foo = [1, 2, 3]
- => [1, 2, 3]
- >> goo = [2, 3, 4]
- => [2, 3, 4]
- >> foo - goo
- => [1]
- gem install differ
- git clone git://github.com/myobie/htmldiff.git
- cd htmldiff
- gem build htmldiff.gemspec
- sudo gem install htmldiff-x.y.z.gem
- 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; }
- def diff str1, str2
- system "diff #{file_for str1} #{file_for str2}"
- end
- private
- def file_for text
- exp = Tempfile.new("bk", "/tmp").open
- exp.write(text)
- exp.close
- exp.path
- end
Add Comment
Please, Sign In to add comment