[dev] Fwd: Another renderer for Text_Diff

Jon Parise jon at horde.org
Sun Sep 12 22:49:19 PDT 2004


On Fri, Sep 10, 2004 at 03:16:07AM -0400, Chuck Hagenbuch wrote:

> >I've been in contact with Ciprian and hope to have a his inline diff
> >capabilities merged into Text_Diff some time soon, for what it's
> >worth.
>
> Heh, so have I. I'm planning on adding some sort of pattern to the
> rendering process to support the modified diffs. I guess we'll see
> what each of us comes up with. :)

I haven't gotten that far.  Attached is a slightly-modified version of
his renderer that's appropriate for use a Text/Renderer/inline.php.

If you're already working on it, I'm happy to yield to your efforts as
I'm not sure when I'll be able to get back to it.

-- 
Jon Parise (jon of horde.org) :: The Horde Project (http://horde.org/)
-------------- next part --------------
<?php
/*
 * "Inline" diff renderer.
 *
 * This class renders diffs in the Wiki-style "inline" format.
 *
 * $Horde: $
 * 
 * @author  Ciprian Popovici
 * @package Text_Diff
 */

class Text_Diff_Renderer_inline extends Text_Diff_Renderer {

	var $ins_prefix = '<ins>';
	var $ins_suffix = '</ins>';
	var $del_prefix = '<del>';
	var $del_suffix = '</del>';

    function Text_Diff_Renderer_inline($context_lines = 10000,
                                       $ins_prefix = null,
                                       $ins_suffix = null,
                                       $del_prefix = null,
                                       $del_suffix = null)
    {
        if (isset($ins_prefix))
        {
		    $this->ins_prefix = $ins_prefix;
        }
        if (isset($ins_suffix))
        {
		    $this->ins_suffix = $ins_suffix;
        }
        if (isset($del_prefix))
        {
		    $this->del_prefix = $del_prefix;
        }
        if (isset($del_suffix))
        {
		    $this->del_suffix = $del_suffix;
        }
		
        $this->_leading_context_lines = $context_lines;
        $this->_trailing_context_lines = $context_lines;
    }

    function _lines($lines, $prefix = ' ')
    {
        echo implode($lines, ' ');
    }

    function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
    {
		return '';
    }

    function _startBlock($header)
    {
        echo $header;
    }

    function _added($lines)
    {
        array_unshift($lines, $this->ins_prefix);
        array_push($lines, $this->ins_suffix);
        $this->_lines($lines);
    }

    function _deleted($lines)
    {
        array_unshift($lines, $this->del_prefix);
        array_push($lines, $this->del_suffix);
        $this->_lines($lines);
    }

    function _changed($orig, $final)
    {
        $this->_deleted($orig);
        $this->_added($final);
    }
}


More information about the dev mailing list