class TableDiffFormatter in Diff 5
Wikipedia Table style diff formatter. @todo document @private @subpackage DifferenceEngine
Hierarchy
- class \DiffFormatter
- class \TableDiffFormatter
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"> </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";
}
}
}