Skip to content

Commit

Permalink
Using namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Mat Chapman committed Mar 12, 2014
1 parent fffdd03 commit 8e3a417
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
7 changes: 6 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
require 'vendor/autoload.php';


$htmldiff = new Gathercontent\Htmldiff\Htmldiff;

echo $htmldiff->compare($text2, $text1, true);

/*
$diff = new cogpowered\FineDiff\Diff(new cogpowered\FineDiff\Granularity\Paragraph, new Gathercontent\Htmldiff\Render\CustomRenderer);
echo $diff->render($html1, $html2);
echo $diff->render($html1, $html2);*/
17 changes: 16 additions & 1 deletion php_html_examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,19 @@
</td>
</tr>
</tbody>
</table>';
</table>';

$text1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas
consequat felis eu lectus volutpat congue. Fusce nec massa eget risus
commodo convallis a in metus. Nam rhoncus sed enim aliquam tincidunt.
Donec pretium eros nec dui cursus ullamcorper. Donec vel dignissim elit.
Vivamus aliquet nec lectus et aliquet. Proin id rutrum est. Integer
suscipit dolor ornare, hendrerit enim in, lacinia neque. Ut id nulla
elit. Suspendisse molestie sem eleifend arcu dignissim rutrum.';
$text2 = 'Lorem dolor sit amet, consectetur adipiscing elit. Maecenas
consequat felis eu lectus volutpat congue. Fusce nec massa eget risus
commodo convallis a in metus. Nam rhoncus sed enim aliquam tincidunt.
Donec pretium eros nec dui cursus ullamcorper. Donec vel dignissim elit.
Vivamus aliquet nec lectus et aliquet. Proin id rutrum est. Integer
suscipit dolor ornare, hendrerit enim in, lacinia neque. Ut id nulla
elit. Suspendisse molestie sem eleifend arcu dignissim rutrum.';
9 changes: 6 additions & 3 deletions src/htmldiff.php → src/Gathercontent/Htmldiff/Htmldiff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

namespace Gathercontent\Htmldiff;
class HTMLDiff {

class Htmldiff {

private $attributes = array();

Expand Down Expand Up @@ -160,8 +162,9 @@ public function compare($old, $new, $plain_text=false) {
$this->old = $old;
$this->new = $new;

$diff = new FineDiff($this->old, $this->new, FineDiff::$wordGranularity);
return $diff->renderDiffToHTML();
$granularity = new \cogpowered\FineDiff\Granularity\Word;
$diff = new \cogpowered\FineDiff\Diff($granularity);
return $diff->render($this->old, $this->new);
}
else {

Expand Down
2 changes: 1 addition & 1 deletion src/Gathercontent/Htmldiff/Render/CustomRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use cogpowered\FineDiff\Parser\OpcodeInterface;

class CustomRenderer extends Renderer
class CustomRenderer extends \cogpowered\FineDiff\Render\Renderer
{
public function callback($opcode, $from, $from_offset, $from_len)
{
Expand Down

0 comments on commit 8e3a417

Please sign in to comment.