Skip to content

Commit

Permalink
Refactor HTML Inline Renderer to HTML Unified
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiLive authored and DigiLive committed Nov 21, 2020
1 parent 1ba255f commit cf516d1
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 50 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ standard formats including:

* Unified
* Context
* Inline HTML
* Side by Side HTML
* Unified HTML
* Unified Commandline colored output
Expand Down Expand Up @@ -94,9 +93,9 @@ directory. Included is a light and a dark theme.

<details><summary>More Example Pictures</summary><br>

#### HTML Inline Example
#### HTML Unified Example

![HTML Inline Example](assets/htmlInline.png "HTML Inline Example")
![HTML Unified Example](assets/htmlUnified.png "HTML Unified Example")

#### Text Unified Example

Expand Down
Binary file removed assets/htmlInline.png
Binary file not shown.
Binary file added assets/htmlUnified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions example/dark-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,29 @@ a, a:visited {
}

/*
* HTML Inline Diff
* HTML Unified Diff
*/

.DifferencesInline .ChangeReplace {
.DifferencesUnified .ChangeReplace {
color: #272822;
}

.DifferencesInline .ChangeReplace .Left,
.DifferencesInline .ChangeDelete .Left {
.DifferencesUnified .ChangeReplace .Left,
.DifferencesUnified .ChangeDelete .Left {
background: #FFDDDD;
color: #272822;
}

.DifferencesInline .ChangeReplace .Right,
.DifferencesInline .ChangeInsert .Right {
.DifferencesUnified .ChangeReplace .Right,
.DifferencesUnified .ChangeInsert .Right {
background: #DDFFDD;
}

.DifferencesInline .ChangeReplace ins {
.DifferencesUnified .ChangeReplace ins {
background: #008000;
}

.DifferencesInline .ChangeReplace del {
.DifferencesUnified .ChangeReplace del {
background: #EE9999;
color: #272822;
}
Expand Down
14 changes: 7 additions & 7 deletions example/example.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

use jblond\Diff;
use jblond\Diff\Renderer\Html\Inline;
use jblond\Diff\Renderer\Html\Merged;
use jblond\Diff\Renderer\Html\SideBySide;
use jblond\Diff\Renderer\Html\Unified;
use jblond\Diff\Renderer\Text\Context;
use jblond\Diff\Renderer\Text\Unified;
use jblond\Diff\Renderer\Text\Unified as TextUnified;

// Include and instantiate autoloader.
require '../vendor/autoload.php';
Expand Down Expand Up @@ -84,24 +84,24 @@ function changeCSS(cssFile, cssLinkIndex) {
echo $diff->isIdentical() ? 'No differences found.' : $diff->Render($renderer);
?>

<h2>HTML Inline Diff</h2>
<h2>HTML Unified Diff</h2>
<?php
// Generate an inline diff.
$renderer = new Inline($rendererOptions);
// Generate an unified diff.
$renderer = new Unified($rendererOptions);
echo $diff->isIdentical() ? 'No differences found.' : $diff->Render($renderer);
?>

<h2>HTML Merged Diff</h2>
<?php
// Generate an inline diff.
// Generate an merged diff.
$renderer = new Merged();
echo $diff->isIdentical() ? 'No differences found.' : $diff->Render($renderer);
?>

<h2>Text Unified Diff</h2>
<?php
// Generate a unified diff.
$renderer = new Unified();
$renderer = new TextUnified();
echo $diff->isIdentical() ?
'No differences found.' : '<pre>' . htmlspecialchars($diff->render($renderer)) . '</pre>';
?>
Expand Down
14 changes: 7 additions & 7 deletions example/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@ pre {
}

/*
* HTML Inline Diff
* HTML Unified Diff
*/
.DifferencesInline .ChangeReplace .Left,
.DifferencesInline .ChangeDelete .Left {
.DifferencesUnified .ChangeReplace .Left,
.DifferencesUnified .ChangeDelete .Left {
background: #FFDDDD;
}

.DifferencesInline .ChangeReplace .Right,
.DifferencesInline .ChangeInsert .Right {
.DifferencesUnified .ChangeReplace .Right,
.DifferencesUnified .ChangeInsert .Right {
background: #DDFFDD;
}

.DifferencesInline .ChangeReplace ins {
.DifferencesUnified .ChangeReplace ins {
background: #99EE99;
}

.DifferencesInline .ChangeReplace del {
.DifferencesUnified .ChangeReplace del {
background: #EE9999;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use jblond\Diff\Renderer\SubRendererInterface;

/**
* Inline HTML diff generator for PHP DiffLib.
* Unified HTML diff generator for PHP DiffLib.
*
* PHP version 7.2 or greater
*
Expand All @@ -21,7 +21,7 @@
* @version 2.3.0
* @link https://github.com/JBlond/php-diff
*/
class Inline extends MainRenderer implements SubRendererInterface
class Unified extends MainRenderer implements SubRendererInterface
{
/**
* @var array Associative array containing the default options available for this renderer and their default
Expand All @@ -41,11 +41,11 @@ class Inline extends MainRenderer implements SubRendererInterface
];

/**
* Inline constructor.
* Unified constructor.
*
* @param array $options Custom defined options for the inline diff renderer.
* @param array $options Custom defined options for the unified diff renderer.
*
* @see Inline::$subOptions
* @see Unified::$subOptions
*/
public function __construct(array $options = [])
{
Expand Down Expand Up @@ -73,7 +73,7 @@ public function render()
public function generateDiffHeader(): string
{
return <<<HTML
<table class="Differences DifferencesInline">
<table class="Differences DifferencesUnified">
<thead>
<tr>
<th>{$this->options['title1']}</th>
Expand Down
30 changes: 12 additions & 18 deletions tests/Diff/Renderer/Html/HtmlRenderersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Tests\Diff\Renderer\Html;

use jblond\Diff;
use jblond\Diff\Renderer\Html\Inline;
use jblond\Diff\Renderer\Html\Merged;
use jblond\Diff\Renderer\Html\SideBySide;
use jblond\Diff\Renderer\Html\Unified;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -65,50 +65,44 @@ public function testSideBySide()
}

/**
* Test the output of the HTML Inline renderer.
* Test the output of the HTML Unified renderer.
*
* @covers \jblond\Diff\Renderer\Html\Inline
* @covers \jblond\Diff\Renderer\Html\Merged
*/
public function testInline()
public function testMerged()
{
$diff = new Diff(
file_get_contents('tests/resources/a.txt'),
file_get_contents('tests/resources/b.txt')
);

$renderer = new Inline(
[
'format' => 'html',
'insertMarkers' => ['<ins>', '</ins>'],
'deleteMarkers' => ['<del>', '</del>'],
]
);
$renderer = new Merged();
$result = $diff->render($renderer);
if ($this->genOutputFiles) {
file_put_contents('htmlInline.txt', $result);
file_put_contents('htmlMerged.txt', $result);
}

$this->assertStringEqualsFile('tests/resources/htmlInline.txt', $result);
$this->assertStringEqualsFile('tests/resources/htmlMerged.txt', $result);
}

/**
* Test the output of the HTML Unified renderer.
*
* @covers \jblond\Diff\Renderer\Html\Merged
* @covers \jblond\Diff\Renderer\Html\Unified
*/
public function testMerged()
public function testUnified()
{
$diff = new Diff(
file_get_contents('tests/resources/a.txt'),
file_get_contents('tests/resources/b.txt')
);

$renderer = new Merged();
$renderer = new Unified();
$result = $diff->render($renderer);
if ($this->genOutputFiles) {
file_put_contents('htmlMerged.txt', $result);
file_put_contents('htmlUnified.txt', $result);
}

$this->assertStringEqualsFile('tests/resources/htmlMerged.txt', $result);
$this->assertStringEqualsFile('tests/resources/htmlUnified.txt', $result);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table class="Differences DifferencesInline">
<table class="Differences DifferencesUnified">
<thead>
<tr>
<th>Version1</th>
Expand Down

0 comments on commit cf516d1

Please sign in to comment.