You are here

class TableDiffFormatter in Diff 5

Wikipedia Table style diff formatter. @todo document @private @subpackage DifferenceEngine

Hierarchy

Expanded class hierarchy of TableDiffFormatter

File

./DiffEngine.php, line 1036

View source
class TableDiffFormatter extends DiffFormatter {
  function TableDiffFormatter() {
    $this->leading_context_lines = 2;
    $this->trailing_context_lines = 2;
  }
  function _block_header($xbeg, $xlen, $ybeg, $ylen) {
    $r = '<tr><td colspan="2" align="left"><strong>' . t('Line @line', array(
      '@line' => $xbeg,
    )) . "</strong></td>\n" . '<td colspan="2" align="left"><strong>' . t('Line @line', array(
      '@line' => $ybeg,
    )) . "</strong></td></tr>\n";
    return $r;
  }
  function _start_block($header) {
    if ($this->show_header) {
      echo $header;
    }
  }
  function _end_block() {
  }
  function _lines($lines, $prefix = ' ', $color = 'white') {
  }

  # HTML-escape parameter before calling this
  function addedLine($line) {
    return "<td>+</td><td class='diff-addedline'><div>{$line}</div></td>";
  }

  # HTML-escape parameter before calling this
  function deletedLine($line) {
    return "<td>-</td><td class='diff-deletedline'><div>{$line}</div></td>";
  }

  # HTML-escape parameter before calling this
  function contextLine($line) {
    return "<td> </td><td class='diff-context'><div>{$line}</div></td>";
  }
  function emptyLine() {
    return '<td colspan="2">&nbsp;</td>';
  }
  function _added($lines) {
    foreach ($lines as $line) {
      echo '<tr>' . $this
        ->emptyLine() . $this
        ->addedLine(check_plain($line)) . "</tr>\n";
    }
  }
  function _deleted($lines) {
    foreach ($lines as $line) {
      echo '<tr>' . $this
        ->deletedLine(check_plain($line)) . $this
        ->emptyLine() . "</tr>\n";
    }
  }
  function _context($lines) {
    foreach ($lines as $line) {
      echo '<tr>' . $this
        ->contextLine(check_plain($line)) . $this
        ->contextLine(check_plain($line)) . "</tr>\n";
    }
  }
  function _changed($orig, $closing) {
    $diff = new WordLevelDiff($orig, $closing);
    $del = $diff
      ->orig();
    $add = $diff
      ->closing();

    # Notice that WordLevelDiff returns HTML-escaped output.

    # Hence, we will be calling addedLine/deletedLine without HTML-escaping.
    while ($line = array_shift($del)) {
      $aline = array_shift($add);
      echo '<tr>' . $this
        ->deletedLine($line) . $this
        ->addedLine($aline) . "</tr>\n";
    }
    foreach ($add as $line) {

      # If any leftovers
      echo '<tr>' . $this
        ->emptyLine() . $this
        ->addedLine($line) . "</tr>\n";
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DiffFormatter::$leading_context_lines property * Number of leading context "lines" to preserve. * * This should be left at zero for this class, but subclasses * may want to set this to other values.
DiffFormatter::$show_header property Should a block header be shown?
DiffFormatter::$trailing_context_lines property * Number of trailing context "lines" to preserve. * * This should be left at zero for this class, but subclasses * may want to set this to other values.
DiffFormatter::format function * Format a diff. * *
DiffFormatter::_block function
DiffFormatter::_end_diff function
DiffFormatter::_start_diff function
TableDiffFormatter::addedLine function
TableDiffFormatter::contextLine function
TableDiffFormatter::deletedLine function
TableDiffFormatter::emptyLine function
TableDiffFormatter::TableDiffFormatter function
TableDiffFormatter::_added function Overrides DiffFormatter::_added
TableDiffFormatter::_block_header function Overrides DiffFormatter::_block_header
TableDiffFormatter::_changed function Overrides DiffFormatter::_changed
TableDiffFormatter::_context function Overrides DiffFormatter::_context
TableDiffFormatter::_deleted function Overrides DiffFormatter::_deleted
TableDiffFormatter::_end_block function Overrides DiffFormatter::_end_block
TableDiffFormatter::_lines function Overrides DiffFormatter::_lines
TableDiffFormatter::_start_block function Overrides DiffFormatter::_start_block