Skip to content
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

To output or not to output when there's no difference... #52

Closed
DigiLive opened this issue Jul 17, 2020 · 4 comments
Closed

To output or not to output when there's no difference... #52

DigiLive opened this issue Jul 17, 2020 · 4 comments
Assignees

Comments

@DigiLive
Copy link
Collaborator

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)

@JBlond
Copy link
Owner

JBlond commented Jul 17, 2020

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.

@DigiLive
Copy link
Collaborator Author

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'

@vendeeglobe
Copy link

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

@DigiLive
Copy link
Collaborator Author

DigiLive commented Jul 22, 2020

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.

@DigiLive DigiLive self-assigned this Jul 22, 2020
DigiLive pushed a commit that referenced this issue Jul 23, 2020
- Fixed calling Diff::getGroupedOpCodes() twice.
@JBlond JBlond closed this as completed in fda4852 Jul 23, 2020
JBlond added a commit that referenced this issue Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants