Skip to content

Commit 8bee18d

Browse files
committed
Add: Json renderer Options
1 parent 46528f2 commit 8bee18d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ standard formats including:
1515
* Side by Side HTML
1616
* Unified HTML
1717
* Unified Commandline colored output
18+
* JSON
1819

1920
The logic behind the core of the diff engine (ie, the sequence matcher) is
2021
primarily based on the Python difflib package. The reason for doing so is
@@ -147,9 +148,9 @@ at [jQuery-Merge-for-php-diff](https://github.com/DigiLive/jQuery-Merge-for-php-
147148

148149
Contributors since I forked the repo.
149150

150-
* maxxer
151-
* Creris
152-
* jfcherng
151+
* [maxxer](https://github.com/maxxer)
152+
* [Creris](https://github.com/Creris)
153+
* [jfcherng](https://github.com/jfcherng)
153154
* [DigiLive](https://github.com/DigiLive)
154155

155156
### License (BSD License)

lib/jblond/Diff/Renderer/Text/Json.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@
2222
*/
2323
class Json extends MainRendererAbstract
2424
{
25+
26+
/**
27+
* @var array Associative array containing the default options available for this renderer and their default
28+
* value.
29+
*/
30+
private $subOptions = [
31+
'json' => JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
32+
];
33+
34+
/**
35+
* InlineCli constructor.
36+
*
37+
* @param array $options Custom defined options for the InlineCli diff renderer.
38+
*
39+
* @see Json::$subOptions
40+
*/
41+
public function __construct(array $options = [])
42+
{
43+
parent::__construct($this->subOptions);
44+
$this->setOptions($options);
45+
}
46+
2547
/**
2648
* @return false|string
2749
*/
@@ -33,7 +55,7 @@ public function render()
3355
foreach ($opCodes as $key => $group) {
3456
$return[] = $this->toArray($group);
3557
}
36-
return json_encode($return, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
58+
return json_encode($return, $this->options['json']);
3759
}
3860

3961
/**

0 commit comments

Comments
 (0)