Skip to content

Commit 8235504

Browse files
hasan-ozbeyjfcherng
authored andcommitted
Ability to render HTML from JSON (#17)
1 parent 8e441ad commit 8235504

File tree

6 files changed

+105
-2
lines changed

6 files changed

+105
-2
lines changed

src/Renderer/AbstractRenderer.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,38 @@ final public function render(Differ $differ): string
140140
: $this->renderWoker($differ);
141141
}
142142

143+
/**
144+
* {@inheritdoc}
145+
*/
146+
final public function renderArray(array $differArray): string
147+
{
148+
return $this->renderArrayWoker($differArray);
149+
}
150+
143151
/**
144152
* The real worker for self::render().
145153
*
146154
* @param Differ $differ the differ object
147155
*/
148156
abstract protected function renderWoker(Differ $differ): string;
157+
158+
/**
159+
* The worker for array render.
160+
*
161+
* @param array $differArray the differ array
162+
*
163+
* @return string
164+
*/
165+
abstract protected function renderArrayWoker(array $differArray): string;
166+
167+
/**
168+
* Woker's base function.
169+
*
170+
* @param array $changes the changes array
171+
*
172+
* @return string
173+
*/
174+
abstract protected function baseWoker(array $changes): string;
149175

150176
/**
151177
* Update the Language object.

src/Renderer/Html/Inline.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,29 @@ final class Inline extends AbstractHtml
2626
protected function renderWoker(Differ $differ): string
2727
{
2828
$changes = $this->getChanges($differ);
29+
30+
return $this->baseWoker($changes);
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
protected function renderArrayWoker(array $differArray): string
37+
{
38+
$changes = $differArray;
2939

40+
return $this->baseWoker($changes);
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
protected function baseWoker(array $changes): string
47+
{
3048
if (empty($changes)) {
3149
return $this->getResultForIdenticals();
3250
}
33-
51+
3452
$wrapperClasses = \array_merge(
3553
$this->options['wrapperClasses'],
3654
['diff', 'diff-html', 'diff-inline']

src/Renderer/Html/Json.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ protected function renderWoker(Differ $differ): string
5050
);
5151
}
5252

53+
/**
54+
* {@inheritdoc}
55+
*/
56+
public function renderArrayWoker(array $differArray): string
57+
{
58+
return '';
59+
}
60+
61+
/**
62+
* {@inheritdoc}
63+
*/
64+
public function baseWoker(array $changes): string
65+
{
66+
return '';
67+
}
68+
5369
/**
5470
* Convert tags of changes to their string form for better readability.
5571
*

src/Renderer/Html/SideBySide.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,25 @@ final class SideBySide extends AbstractHtml
2626
protected function renderWoker(Differ $differ): string
2727
{
2828
$changes = $this->getChanges($differ);
29-
29+
30+
return $this->baseWoker($changes);
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
protected function renderArrayWoker(array $differArray): string
37+
{
38+
$changes = $differArray;
39+
40+
return $this->baseWoker($changes);
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
protected function baseWoker(array $changes): string
47+
{
3048
if (empty($changes)) {
3149
return $this->getResultForIdenticals();
3250
}

src/Renderer/RendererInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@ public function getResultForIdenticals(): string;
2222
* @param Differ $differ the Differ object to be rendered
2323
*/
2424
public function render(Differ $differ): string;
25+
26+
/**
27+
* Render the differ array and return the result.
28+
*
29+
* @param array $differArray the Differ array to be rendered
30+
*
31+
* @return string
32+
*/
33+
public function renderArray(array $differArray): string;
2534
}

src/Renderer/Text/AbstractText.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,20 @@ public function getResultForIdenticalsDefault(): string
2323
{
2424
return '';
2525
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function renderArrayWoker(array $differArray): string
31+
{
32+
return '';
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function baseWoker(array $changes): string
39+
{
40+
return '';
41+
}
2642
}

0 commit comments

Comments
 (0)