Ruby code converting unified diff to HTML similar to changeset screen at Trac
= diff_to_html
This is a Ruby class for converting unified diff, like the one you get with 'svn diff', to HTML like in changeset viewer of a tool like Trac, GitHub or Codenotifier, e.g. http://codenotifier.com/projects/49/commits/47#F0.
It's based on code from http://gurge.com/blog/2006/10/03/subversion-diff-viewer-cgi-in-ruby (thanks Adam Doppelt!), adopted lightly to support multifile diffs and to have more familiar output. It definitely have things to improve, so contribution/patches are very welcome.
install the gem:
gem install artemv-diff_to_html --source=http://gems.github.com
go to gem's 'examples' dir (it's .../ruby/lib/ruby/gems/1.8/gems/artemv-diff_to_html-x.x.x/examples/) and run 'ruby test.rb >out.html' - this will get diff from sample 'svn diff' and generate out.html. Resulting html is linked to diff.css in 'examples' directory - you'll need to copy it to your project's dir to use it.
To use in Rails project:
require 'diff_to_html'
diff = cat #{File.join(File.dirname(__FILE__), 'diff.svn')}
converter = SvnDiffToHtml.new #there's also GitDiffToHtml
puts converter.composite_to_html(diff)
to use in any Ruby program:
require 'rubygems' require 'diff_to_html' ...
== License
diff_to_html is released under the MIT license.
== Authors and credits
Authors:: Artem Vasiliev Original code:: Adam Doppelt, http://gurge.com/blog/2006/10/03/subversion-diff-viewer-cgi-in-ruby