|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
-
-
- namespace yii\gii\components;
-
-
- class DiffRendererHtmlInline extends \Diff_Renderer_Html_Array
- {
-
-
- public function render()
- {
- $changes = parent::render();
- $html = '';
- if (empty($changes)) {
- return $html;
- }
-
- $html .= <<<HTML
- <table class="Differences DifferencesInline">
- <thead>
- <tr>
- <th>Old</th>
- <th>New</th>
- <th>Differences</th>
- </tr>
- </thead>
- HTML;
- foreach ($changes as $i => $blocks) {
-
-
-
- if ($i > 0) {
- $html .= <<<HTML
- <tbody class="Skipped">
- <th data-line-number="…"></th>
- <th data-line-number="…"></th>
- <td> </td>
- </tbody>
- HTML;
- }
-
- foreach ($blocks as $change) {
- $tag = ucfirst($change['tag']);
- $html .= <<<HTML
- <tbody class="Change{$tag}">
- HTML;
-
- if ($change['tag'] === 'equal') {
- foreach ($change['base']['lines'] as $no => $line) {
- $fromLine = $change['base']['offset'] + $no + 1;
- $toLine = $change['changed']['offset'] + $no + 1;
- $html .= <<<HTML
- <tr>
- <th data-line-number="{$fromLine}"></th>
- <th data-line-number="{$toLine}"></th>
- <td class="Left">{$line}</td>
- </tr>
- HTML;
- }
- }
-
- elseif ($change['tag'] === 'insert') {
- foreach ($change['changed']['lines'] as $no => $line) {
- $toLine = $change['changed']['offset'] + $no + 1;
- $html .= <<<HTML
- <tr>
- <th data-line-number=" "></th>
- <th data-line-number="{$toLine}"></th>
- <td class="Right"><ins>{$line}</ins> </td>
- </tr>
- HTML;
- }
- }
-
- elseif ($change['tag'] === 'delete') {
- foreach ($change['base']['lines'] as $no => $line) {
- $fromLine = $change['base']['offset'] + $no + 1;
- $html .= <<<HTML
- <tr>
- <th data-line-number="{$fromLine}"></th>
- <th data-line-number=" "></th>
- <td class="Left"><del>{$line}</del> </td>
- </tr>
- HTML;
- }
- }
-
- elseif ($change['tag'] === 'replace') {
- foreach ($change['base']['lines'] as $no => $line) {
- $fromLine = $change['base']['offset'] + $no + 1;
- $html .= <<<HTML
- <tr>
- <th data-line-number="{$fromLine}"></th>
- <th data-line-number=" "></th>
- <td class="Left"><span>{$line}</span></td>
- </tr>
- HTML;
- }
-
- foreach ($change['changed']['lines'] as $no => $line) {
- $toLine = $change['changed']['offset'] + $no + 1;
- $html .= <<<HTML
- <tr>
- <th data-line-number="{$toLine}"></th>
- <th data-line-number=" "></th>
- <td class="Right"><span>{$line}</span></td>
- </tr>
- HTML;
- }
- }
- $html .= <<<HTML
- </tbody>
- HTML;
- }
- }
- $html .= <<<HTML
- </table>
- HTML;
-
- return $html;
- }
- }
|