diffyはRubyのStringクラスのdiffを扱うGemです。
出力パターンも相当に頑張ってます。
文字
>> puts Diffy::Diff.new("alpha\nbeta","alpha\ngumma").to_s
alpha -beta \ No newline at end of file +gumma \ No newline at end of file
シンプルなhtml出力
>> puts Diffy::Diff.new("alpha\nbeta","alpha\ngumma").to_s(:html_simple)
<div class="diff"> <ul> <li class="unchanged"><span>alpha</span></li> <li class="del"><del>beta</del></li> <li class="ins"><ins>gumma</ins></li> </ul> </div>
gitっぽく+と-を入れる
>> puts Diffy::Diff.new("alpha\nbeta","alpha\ngumma", :include_plus_and_minus_in_html => true).to_s(:html_simple)
<div class="diff"> <ul> <li class="unchanged"><span><span class="symbol"> </span>alpha</span></li> <li class="del"><del><span class="symbol">-</span>beta</del></li> <li class="ins"><ins><span class="symbol">+</span>gumma</ins></li> </ul> </div>
html出力
>> puts Diffy::Diff.new("alpha\nbeta","alpha\ngumma").to_s(:html)
<div class="diff"> <ul> <li class="unchanged"><span>alpha</span></li> <li class="del"><del><strong>bet</strong>a</del></li> <li class="ins"><ins><strong>gumm</strong>a</ins></li> </ul> </div>