# encoding: utf-8 #-- # Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) # Copyright (C) 2008 Johan Sørensen # Copyright (C) 2008 Tor Arne Vestbø # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . #++ module Gitorious module Diff class InlineTableCallback < BaseCallback def self.with_comments(comments, template) table_callback = new table_callback.comments = comments table_callback.template = template table_callback end attr_accessor :template def comments=(comments) @comment_callback = CommentCallback.new(comments) end def addline(line) %Q{} + render_comment_count(line) + %Q{} + %Q{#{line.new_number}} + %Q{} + %Q{#{render_line(line)}} end def remline(line) %Q{} + render_comment_count(line) + %Q{#{line.old_number}} + %Q{} + %Q{} + %Q{#{render_line(line)}} end # FIXME: We don't use this one for inline diffs (?) def modline(line) %Q{} + render_comment_count(line) + %Q{#{line.old_number}} + %Q{#{line.new_number}} + %Q{#{render_line(line)}} end def unmodline(line) %Q{} + render_comment_count(line) + %Q{#{line.old_number}} + %Q{#{line.new_number}} + %Q{#{render_line(line)}} end def sepline(line) %Q{} + render_comment_count(line) + %Q{…} + %Q{…} + %Q{} end def nonewlineline(line) %Q{} + render_comment_count(line) + %Q{#{line.old_number}} + %Q{#{line.new_number}} + %Q{#{render_line(line)}} end protected def render_comment_count(line) if @comment_callback @comment_callback.count(line) else "" end end def render_comments_for(line) return "" unless @comment_callback return "" if @comment_callback.comment_count_ending_on_line(line).zero? %Q{
} + @comment_callback.render_for(line, template) + "
" end def render_line(line) '' + super + '' + render_comments_for(line) end end end end