To output or not to output when there's no difference...
Closed this issue · 4 comments
HTML Side by Side Diff, HTML Inline Diff and HTML Unified Diff will produce output string No differences found.
It's hard-coded in the HtmlArray
class.
@JBlond Let me know if, and into what, you want this to be changed.
Originally posted by @DigiLive in #50 (comment)
I can live with that. I don't know what else I would choose. An idea is to have an option to set that to blank / nothing.
We can make it return a false
when there are no differences.
A false sent to the output buffer will produce no output.
echo false; // Will render nothing
This way we can do something like:
echo $diff->render($renderer);
// Renders the differences or nothing
or
$rendererOutput = $diff->render($renderer);
echo $rendererOutput === false ? 'No differences found.' : $rendererOutput ;
// Renders the differences or 'No differences found'
In WackoWiki we check for nodiff in advance and the template engine sets then [ ' _t: NoDifferences ' ].
if (!$diff->getGroupedOpcodes())
{
$tpl->phpdiff_nodiff = true;
break;
}
https://github.com/WackoWiki/wackowiki/blob/master/wacko/handler/page/diff.php#L330
In WackoWiki we check for nodiff in advance and the template engine sets then [ ' _t: NoDifferences ' ].
if (!$diff->getGroupedOpcodes()) { $tpl->phpdiff_nodiff = true; break; }
https://github.com/WackoWiki/wackowiki/blob/master/wacko/handler/page/diff.php#L330
This is not advised...
The return value of method Diff::getGroupedOpCodes
isn't empty when the trimEqual
option is set to false.
It's also possible the visibility of this method might changes in the future.
We can add another method to the Diff
class for exposing differences (or not) to avoid the overhead of calling the MainRenderer
.
Edit:
I've just noticed MainRenderer
also reacts on the non-empty return value as describes before.
I'll write a method for knowing if the're differences or not.