Skip to content

Development #18

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

Merged
merged 4 commits into from
Dec 3, 2019
Merged
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
32 changes: 22 additions & 10 deletions example/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
<head>
<meta charset="utf-8"/>
<title>PHP LibDiff - Examples</title>
<link rel="stylesheet" href="styles.css" type="text/css" charset="utf-8"/>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
<body>
<h1>PHP LibDiff - Examples</h1>
<hr />
<?php
// include autoloader
require dirname(__FILE__).'/../lib/Autoloader.php';
new \jblond\Autoloader();
use jblond\Autoloader;
use jblond\Diff;
use jblond\Diff\Renderer\Html\Inline;
use jblond\Diff\Renderer\Html\SideBySide;
use jblond\Diff\Renderer\Text\Context;
use jblond\Diff\Renderer\Text\Unified;

require dirname(__FILE__) . '/../lib/Autoloader.php';
new Autoloader();

// Include two sample files for comparison
$a = explode("\n", file_get_contents(dirname(__FILE__).'/a.txt'));
$b = explode("\n", file_get_contents(dirname(__FILE__).'/b.txt'));
$a = explode("\n", file_get_contents(dirname(__FILE__) . '/a.txt'));
$b = explode("\n", file_get_contents(dirname(__FILE__) . '/b.txt'));

// Options for generating the diff
$options = array(
Expand All @@ -24,14 +31,16 @@
);

// Initialize the diff class
$diff = new \jblond\Diff($a, $b, $options);
// \jblond\diff
$diff = new Diff($a, $b, $options);

?>
<h2>Side by Side Diff</h2>
<?php

// Generate a side by side diff
$renderer = new \jblond\Diff\Renderer\Html\SideBySide(array(
// \jblond\Diff\Renderer\Html
$renderer = new SideBySide(array(
'title_a' => 'Custom title for OLD version',
'title_b' => 'Custom title for NEW version',
));
Expand All @@ -42,15 +51,17 @@
<?php

// Generate an inline diff
$renderer = new \jblond\Diff\Renderer\Html\Inline;
// \jblond\Diff\Renderer\Html
$renderer = new Inline();
echo $diff->render($renderer);

?>
<h2>Unified Diff</h2>
<pre><?php

// Generate a unified diff
$renderer = new \jblond\Diff\Renderer\Text\Unified();
// \jblond\Diff\Renderer\Text
$renderer = new Unified();
echo htmlspecialchars($diff->render($renderer));

?>
Expand All @@ -59,7 +70,8 @@
<pre><?php

// Generate a context diff
$renderer = new \jblond\Diff\Renderer\Text\Context;
// jblond\Diff\Renderer\Text\Context
$renderer = new Context();
echo htmlspecialchars($diff->render($renderer));
?>
</pre>
Expand Down
6 changes: 1 addition & 5 deletions example/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ body {
background: #fc0;
}

.Differences .Skipped {
background: #f7f7f7;
}

.DifferencesInline .ChangeReplace .Left,
.DifferencesInline .ChangeDelete .Left {
background: #fdd;
Expand All @@ -90,4 +86,4 @@ body {
pre {
width: 100%;
overflow: auto;
}
}
2 changes: 1 addition & 1 deletion lib/jblond/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.13
* @version 1.14
* @link https://github.com/JBlond/php-diff
*/
class Diff
Expand Down
5 changes: 1 addition & 4 deletions lib/jblond/Diff/Renderer/Html/HtmlArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.13
* @version 1.14
* @link https://github.com/JBlond/php-diff
*/
class HtmlArray extends RendererAbstract
Expand Down Expand Up @@ -47,9 +47,6 @@ public function renderHtml($changes, $object)
// If this is a separate block, we're condensing code so output ...,
// indicating a significant portion of the code has been collapsed as
// it is the same
if ($i > 0) {
$html .= $object->generateSkippedTable();
}

foreach ($blocks as $change) {
$html .= '<tbody class="Change' . ucfirst($change['tag']) . '">';
Expand Down
17 changes: 1 addition & 16 deletions lib/jblond/Diff/Renderer/Html/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.13
* @version 1.14
* @link https://github.com/JBlond/php-diff
*/
class Inline extends HtmlArray
Expand Down Expand Up @@ -50,21 +50,6 @@ public function generateTableHeader(): string
return $html;
}

/**
* Generates a string representation of empty table body.
*
* @return string Html code representing empty table body.
*/
public function generateSkippedTable(): string
{
$html = '<tbody class="Skipped">';
$html .= '<th>&hellip;</th>';
$html .= '<th>&hellip;</th>';
$html .= '<td>&#xA0;</td>';
$html .= '</tbody>';
return $html;
}

/**
* Generates a string representation of one or more rows of a table of lines of text with no difference.
*
Expand Down
16 changes: 1 addition & 15 deletions lib/jblond/Diff/Renderer/Html/SideBySide.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.13
* @version 1.14
* @link https://github.com/JBlond/php-diff
*/
class SideBySide extends HtmlArray
Expand Down Expand Up @@ -48,20 +48,6 @@ public function generateTableHeader(): string
return $html;
}

/**
* Generates a string representation of empty table body.
*
* @return string Html code representing empty table body.
*/
public function generateSkippedTable(): string
{
$html = '<tbody class="Skipped">';
$html .= '<th>&hellip;</th><td>&#xA0;</td>';
$html .= '<th>&hellip;</th><td>&#xA0;</td>';
$html .= '</tbody>';
return $html;
}

/**
* Generates a string representation of one or more rows of a table of lines of text with no difference.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/RendererAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.13
* @version 1.14
* @link https://github.com/JBlond/php-diff
*/
abstract class RendererAbstract
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Text/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.13
* @version 1.14
* @link https://github.com/JBlond/php-diff
*/
class Context extends RendererAbstract
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Text/Unified.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.13
* @version 1.14
* @link https://github.com/JBlond/php-diff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/SequenceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.13
* @version 1.14
* @link https://github.com/JBlond/php-diff
*/
class SequenceMatcher
Expand Down