Skip to content

Uniform the term "base, changed" into "old, new" #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ $result = $diff->render($renderer);
[
{
"tag": "rep",
"base": {
"old": {
"offset": 0,
"lines": [
"&lt;<del>p&gt;Hello World!&lt;/p</del>&gt;"
]
},
"changed": {
"new": {
"offset": 0,
"lines": [
"&lt;<ins>div&gt;Hello World!&lt;/div</ins>&gt;"
Expand All @@ -196,13 +196,13 @@ $result = $diff->render($renderer);
},
{
"tag": "eq",
"base": {
"old": {
"offset": 1,
"lines": [
"~~~~~~~~~~~~~~~~~~~"
]
},
"changed": {
"new": {
"offset": 1,
"lines": [
"~~~~~~~~~~~~~~~~~~~"
Expand All @@ -211,11 +211,11 @@ $result = $diff->render($renderer);
},
{
"tag": "ins",
"base": {
"old": {
"offset": 2,
"lines": []
},
"changed": {
"new": {
"offset": 2,
"lines": [
"Let's add a new line here."
Expand All @@ -224,13 +224,13 @@ $result = $diff->render($renderer);
},
{
"tag": "eq",
"base": {
"old": {
"offset": 2,
"lines": [
"X"
]
},
"changed": {
"new": {
"offset": 3,
"lines": [
"X"
Expand All @@ -241,13 +241,13 @@ $result = $diff->render($renderer);
[
{
"tag": "eq",
"base": {
"old": {
"offset": 6,
"lines": [
"N"
]
},
"changed": {
"new": {
"offset": 7,
"lines": [
"N"
Expand All @@ -256,13 +256,13 @@ $result = $diff->render($renderer);
},
{
"tag": "rep",
"base": {
"old": {
"offset": 7,
"lines": [
"Do you know in <del>Chinese, \"金槍魚罐頭\" means tuna</del> can."
]
},
"changed": {
"new": {
"offset": 8,
"lines": [
"Do you know in <ins>Japanese, \"魚の缶詰\" means fish</ins> can."
Expand All @@ -271,14 +271,14 @@ $result = $diff->render($renderer);
},
{
"tag": "eq",
"base": {
"old": {
"offset": 8,
"lines": [
"This is just a useless line.",
"G"
]
},
"changed": {
"new": {
"offset": 9,
"lines": [
"This is just a useless line.",
Expand All @@ -288,26 +288,26 @@ $result = $diff->render($renderer);
},
{
"tag": "del",
"base": {
"old": {
"offset": 10,
"lines": [
"// @todo Remember to delete this line"
]
},
"changed": {
"new": {
"offset": 11,
"lines": []
}
},
{
"tag": "eq",
"base": {
"old": {
"offset": 11,
"lines": [
"Say hello to my neighbors."
]
},
"changed": {
"new": {
"offset": 11,
"lines": [
"Say hello to my neighbors."
Expand Down
16 changes: 8 additions & 8 deletions src/Renderer/Html/AbstractHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public function getChanges(): array
if (!empty($lines = \array_slice($old, $i1, ($i2 - $i1)))) {
$formattedLines = $this->formatLines($lines);

$blocks[$lastBlock]['base']['lines'] += $formattedLines;
$blocks[$lastBlock]['changed']['lines'] += $formattedLines;
$blocks[$lastBlock]['old']['lines'] += $formattedLines;
$blocks[$lastBlock]['new']['lines'] += $formattedLines;
}

continue;
Expand Down Expand Up @@ -109,7 +109,7 @@ public function getChanges(): array
$lines
);

$blocks[$lastBlock]['base']['lines'] += $lines;
$blocks[$lastBlock]['old']['lines'] += $lines;
}

if (
Expand All @@ -124,7 +124,7 @@ public function getChanges(): array
$lines
);

$blocks[$lastBlock]['changed']['lines'] += $lines;
$blocks[$lastBlock]['new']['lines'] += $lines;
}
}

Expand Down Expand Up @@ -167,20 +167,20 @@ protected function renderChangedExtent(AbstractLineRenderer $lineRenderer, strin
* Get the default block.
*
* @param string $tag the operation tag
* @param int $i1 begin index of the diff of the source
* @param int $j1 begin index of the diff of the destination
* @param int $i1 begin index of the diff of the old array
* @param int $j1 begin index of the diff of the new array
*
* @return array the default block
*/
protected function getDefaultBlock(string $tag, int $i1, int $j1): array
{
return [
'tag' => $tag,
'base' => [
'old' => [
'offset' => $i1,
'lines' => [],
],
'changed' => [
'new' => [
'offset' => $j1,
'lines' => [],
],
Expand Down
34 changes: 17 additions & 17 deletions src/Renderer/Html/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ protected function renderTableEqual(array $change): string
{
$html = '';

foreach ($change['base']['lines'] as $no => $line) {
$oldLineNum = $change['base']['offset'] + $no + 1;
$newLineNum = $change['changed']['offset'] + $no + 1;
foreach ($change['old']['lines'] as $no => $line) {
$oldLineNum = $change['old']['offset'] + $no + 1;
$newLineNum = $change['new']['offset'] + $no + 1;

$html .=
'<tr data-type="=">' .
'<th class="f-num">' . $oldLineNum . '</th>' .
'<th class="t-num">' . $newLineNum . '</th>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<th class="n-new">' . $newLineNum . '</th>' .
'<th class="sign"></th>' .
'<td class="old">' . $line . '</td>' .
'</tr>';
Expand All @@ -151,13 +151,13 @@ protected function renderTableInsert(array $change): string
{
$html = '';

foreach ($change['changed']['lines'] as $no => $newLine) {
$newLineNum = $change['changed']['offset'] + $no + 1;
foreach ($change['new']['lines'] as $no => $newLine) {
$newLineNum = $change['new']['offset'] + $no + 1;

$html .=
'<tr data-type="+">' .
'<th></th>' .
'<th class="t-num">' . $newLineNum . '</th>' .
'<th class="n-new">' . $newLineNum . '</th>' .
'<th class="sign ins">+</th>' .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
Expand All @@ -177,12 +177,12 @@ protected function renderTableDelete(array $change): string
{
$html = '';

foreach ($change['base']['lines'] as $no => $oldLine) {
$oldLineNum = $change['base']['offset'] + $no + 1;
foreach ($change['old']['lines'] as $no => $oldLine) {
$oldLineNum = $change['old']['offset'] + $no + 1;

$html .=
'<tr data-type="-">' .
'<th class="f-num">' . $oldLineNum . '</th>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<th></th>' .
'<th class="sign del">-</th>' .
'<td class="old">' . $oldLine . '</td>' .
Expand All @@ -203,25 +203,25 @@ protected function renderTableReplace(array $change): string
{
$html = '';

foreach ($change['base']['lines'] as $no => $oldLine) {
$oldLineNum = $change['base']['offset'] + $no + 1;
foreach ($change['old']['lines'] as $no => $oldLine) {
$oldLineNum = $change['old']['offset'] + $no + 1;

$html .=
'<tr data-type="-">' .
'<th class="f-num">' . $oldLineNum . '</th>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<th></th>' .
'<th class="sign del">-</th>' .
'<td class="old">' . $oldLine . '</td>' .
'</tr>';
}

foreach ($change['changed']['lines'] as $no => $newLine) {
$newLineNum = $change['changed']['offset'] + $no + 1;
foreach ($change['new']['lines'] as $no => $newLine) {
$newLineNum = $change['new']['offset'] + $no + 1;

$html .=
'<tr data-type="+">' .
'<th></th>' .
'<th class="t-num">' . $newLineNum . '</th>' .
'<th class="n-new">' . $newLineNum . '</th>' .
'<th class="sign ins">+</th>' .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
Expand Down
52 changes: 26 additions & 26 deletions src/Renderer/Html/SideBySide.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ protected function renderTableEqual(array $change): string
{
$html = '';

foreach ($change['base']['lines'] as $no => $line) {
$oldLineNum = $change['base']['offset'] + $no + 1;
$newLine = $change['changed']['offset'] + $no + 1;
foreach ($change['old']['lines'] as $no => $line) {
$oldLineNum = $change['old']['offset'] + $no + 1;
$newLine = $change['new']['offset'] + $no + 1;

$html .=
'<tr>' .
'<th class="f-num">' . $oldLineNum . '</th>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<td class="old">' . $line . '</td>' .
'<th class="t-num">' . $newLine . '</th>' .
'<th class="n-new">' . $newLine . '</th>' .
'<td class="new">' . $line . '</td>' .
'</tr>';
}
Expand All @@ -149,14 +149,14 @@ protected function renderTableInsert(array $change): string
{
$html = '';

foreach ($change['changed']['lines'] as $no => $newLine) {
$newLineNum = $change['changed']['offset'] + $no + 1;
foreach ($change['new']['lines'] as $no => $newLine) {
$newLineNum = $change['new']['offset'] + $no + 1;

$html .=
'<tr>' .
'<th></th>' .
'<td class="old"></td>' .
'<th class="t-num">' . $newLineNum . '</th>' .
'<th class="n-new">' . $newLineNum . '</th>' .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
}
Expand All @@ -175,12 +175,12 @@ protected function renderTableDelete(array $change): string
{
$html = '';

foreach ($change['base']['lines'] as $no => $oldLine) {
$oldLineNum = $change['base']['offset'] + $no + 1;
foreach ($change['old']['lines'] as $no => $oldLine) {
$oldLineNum = $change['old']['offset'] + $no + 1;

$html .=
'<tr>' .
'<th class="f-num">' . $oldLineNum . '</th>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<td class="old">' . $oldLine . '</td>' .
'<th></th>' .
'<td class="new"></td>' .
Expand All @@ -201,43 +201,43 @@ protected function renderTableReplace(array $change): string
{
$html = '';

if (\count($change['base']['lines']) >= \count($change['changed']['lines'])) {
foreach ($change['base']['lines'] as $no => $oldLine) {
$oldLineNum = $change['base']['offset'] + $no + 1;
if (\count($change['old']['lines']) >= \count($change['new']['lines'])) {
foreach ($change['old']['lines'] as $no => $oldLine) {
$oldLineNum = $change['old']['offset'] + $no + 1;

if (isset($change['changed']['lines'][$no])) {
$newLineNum = $change['base']['offset'] + $no + 1;
$newLine = '<span>' . $change['changed']['lines'][$no] . '</span>';
if (isset($change['new']['lines'][$no])) {
$newLineNum = $change['old']['offset'] + $no + 1;
$newLine = '<span>' . $change['new']['lines'][$no] . '</span>';
} else {
$newLineNum = '';
$newLine = '';
}

$html .=
'<tr>' .
'<th class="f-num">' . $oldLineNum . '</th>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<td class="old"><span>' . $oldLine . '</span></td>' .
'<th class="t-num">' . $newLineNum . '</th>' .
'<th class="n-new">' . $newLineNum . '</th>' .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
}
} else {
foreach ($change['changed']['lines'] as $no => $newLine) {
$newLineNum = $change['changed']['offset'] + $no + 1;
foreach ($change['new']['lines'] as $no => $newLine) {
$newLineNum = $change['new']['offset'] + $no + 1;

if (isset($change['base']['lines'][$no])) {
$oldLineNum = $change['base']['offset'] + $no + 1;
$oldLine = '<span>' . $change['base']['lines'][$no] . '</span>';
if (isset($change['old']['lines'][$no])) {
$oldLineNum = $change['old']['offset'] + $no + 1;
$oldLine = '<span>' . $change['old']['lines'][$no] . '</span>';
} else {
$oldLineNum = '';
$oldLine = '';
}

$html .=
'<tr>' .
'<th class="f-num">' . $oldLineNum . '</th>' .
'<th class="n-old">' . $oldLineNum . '</th>' .
'<td class="old"><span>' . $oldLine . '</span></td>' .
'<th class="t-num">' . $newLineNum . '</th>' .
'<th class="n-new">' . $newLineNum . '</th>' .
'<td class="new">' . $newLine . '</td>' .
'</tr>';
}
Expand Down