Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing a diff between two bodies of text in Rails

Is there an easy way to do this - create marked up text that shows the changes between two pieces of text. A built-in helper maybe? Looked but couldn't find!

like image 580
Newy Avatar asked May 12 '10 21:05

Newy


2 Answers

You can do this completely client side in javascript using something like jsdifflib (http://snowtide.com/jsdifflib).

like image 61
jonnii Avatar answered Oct 05 '22 01:10

jonnii


http://github.com/pvande/differ You could use that, which performs diff's on strings. You'd have to build some logic to format it into an output ready state. Probably using Builder::XmlMarkup in a helper.

There's also: http://github.com/myobie/htmldiff

Which seems to output markup - but it's not very well documented.

As far as a built in helper, I don't think Rails has anything built in. There's http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Diff.html - but unlike the first plugin, this is used on hashes, not strings.

like image 42
Robbie Avatar answered Oct 05 '22 00:10

Robbie