You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: As an example, the post uses the library's HTML Merged renderer.
The same will apply for all renderers which implement SubRendererInterface.
One of our users seem to patch our renderers so they would fit his own needs.
Mainly he just wanted to get of the table header which we generate at the method below.
publicfunctiongenerateDiffHeader(): string
{
return<<<HTML<table class="Differences DifferencesMerged"> <thead> // <- This header. <tr> <th colspan="2">Merge of {$this->options['title1']} & {$this->options['title2']}</th> </tr> </thead>HTML;
}
To get rid of the table header, he removed the concerning lines in the source code:
Of course this will work and no one is stopping you to do so.
But what happens when we release a new version of the library?
Updating the downloaded version will drop all of your custom changes.
You'll have to patch the file again or... You don't patch at all.
Not patching means you either accept the header being there or you're gonna customize the render as how it's meant to be customized.
Create a class for your customizations.
usejblond\Diff\Renderer\Html\Merged;
class CustomizedMerged extends Merged
{
// Override the Diff header generator.publicfunctiongenerateDiffHeader(): string
{
return<<<HTML<table class="Differences DifferencesMerged"><!-- No table header here. -->HTML;
}
}
Instantiate your customizing class and render the diff view.
Since the customizations are now in your own separated (from the library) file, you don't have to worry about your changes being overwritten when updating to a new release of the library.
Also when a bug is found in the library and need to refer to the troubling lines of code, the line numbers remain the same between our and your copy of the library.
Bonus:
With this use case, its also sufficient enough just to hide the table header with CSS, by adding the following to your style-sheet:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Quick answer... You don't. You either create your own renderer or extend an existing one.
Documentation can be found at the Wiki.
Note: As an example, the post uses the library's HTML
Merged
renderer.The same will apply for all renderers which implement
SubRendererInterface
.One of our users seem to patch our renderers so they would fit his own needs.
Mainly he just wanted to get of the table header which we generate at the method below.
To get rid of the table header, he removed the concerning lines in the source code:
Of course this will work and no one is stopping you to do so.
But what happens when we release a new version of the library?
Updating the downloaded version will drop all of your custom changes.
You'll have to patch the file again or... You don't patch at all.
Not patching means you either accept the header being there or you're gonna customize the render as how it's meant to be customized.
Since the customizations are now in your own separated (from the library) file, you don't have to worry about your changes being overwritten when updating to a new release of the library.
Also when a bug is found in the library and need to refer to the troubling lines of code, the line numbers remain the same between our and your copy of the library.
Bonus:
With this use case, its also sufficient enough just to hide the table header with CSS, by adding the following to your style-sheet:
Beta Was this translation helpful? Give feedback.
All reactions