|
19 | 19 | class Inline extends HtmlArray
|
20 | 20 | {
|
21 | 21 | /**
|
22 |
| - * Render a and return diff with changes between the two sequences |
23 |
| - * displayed inline (under each other) |
| 22 | + * Render a and return diff-view with changes between the two sequences displayed side by side. (under each other) |
24 | 23 | *
|
25 |
| - * @return string The generated inline diff. |
| 24 | + * @return string The generated inline diff-view. |
26 | 25 | */
|
27 | 26 | public function render(): string
|
28 | 27 | {
|
29 | 28 | $changes = parent::render();
|
| 29 | + |
30 | 30 | return parent::renderHtml($changes, $this);
|
31 | 31 | }
|
32 | 32 |
|
33 | 33 |
|
34 | 34 | /**
|
35 |
| - * Generates a string representation of a predefined table and its head with |
36 |
| - * titles from options. |
| 35 | + * Generates a string representation of the opening of a predefined table and its header with titles from options. |
37 | 36 | *
|
38 |
| - * @return string Html code representation of the table's header. |
| 37 | + * @return string HTML code representation of a table's header. |
39 | 38 | */
|
40 | 39 | public function generateTableHeader(): string
|
41 | 40 | {
|
42 |
| - $html = '<table class="Differences DifferencesInline">'; |
43 |
| - $html .= '<thead>'; |
44 |
| - $html .= '<tr>'; |
45 |
| - $html .= '<th>Old</th>'; |
46 |
| - $html .= '<th>New</th>'; |
47 |
| - $html .= '<th>Differences</th>'; |
48 |
| - $html .= '</tr>'; |
49 |
| - $html .= '</thead>'; |
50 |
| - return $html; |
| 41 | + return <<<HTML |
| 42 | +<table class="Differences DifferencesInline"> |
| 43 | + <thead> |
| 44 | + <tr> |
| 45 | + <th>{$this->options['title_a']}</th> |
| 46 | + <th>{$this->options['title_b']}</th> |
| 47 | + <th>Differences</th> |
| 48 | + </tr> |
| 49 | + </thead> |
| 50 | +HTML; |
51 | 51 | }
|
52 | 52 |
|
53 | 53 | /**
|
54 |
| - * Generates a string representation of one or more rows of a table of lines of text with no difference. |
| 54 | + * Generates a string representation of table rows showing text with no difference. |
| 55 | + * |
| 56 | + * @param array $change Contains the op-codes about the changes between two blocks. |
55 | 57 | *
|
56 |
| - * @param array &$change Array with data about changes. |
57 |
| - * @return string Html code representing one or more rows of text with no difference. |
| 58 | + * @return string HTML code representing table rows showing text with no difference. |
58 | 59 | */
|
59 |
| - public function generateTableRowsEqual(array &$change): string |
| 60 | + public function generateTableRowsEqual(array $change): string |
60 | 61 | {
|
61 |
| - $html = ""; |
| 62 | + $html = ''; |
| 63 | + |
62 | 64 | foreach ($change['base']['lines'] as $no => $line) {
|
63 |
| - $fromLine = $change['base']['offset'] + $no + 1; |
64 |
| - $toLine = $change['changed']['offset'] + $no + 1; |
65 |
| - $html .= '<tr>'; |
66 |
| - $html .= '<th>' . $fromLine . '</th>'; |
67 |
| - $html .= '<th>' . $toLine . '</th>'; |
68 |
| - $html .= '<td class="Left">' . $line . '</td>'; |
69 |
| - $html .= '</tr>'; |
| 65 | + $fromLine = $change['base']['offset'] + $no + 1; |
| 66 | + $toLine = $change['changed']['offset'] + $no + 1; |
| 67 | + |
| 68 | + $html .= <<<HTML |
| 69 | +<tr> |
| 70 | + <th>$fromLine</th> |
| 71 | + <th>$toLine</th> |
| 72 | + <td class="Left">$line</td> |
| 73 | +</tr> |
| 74 | +HTML; |
70 | 75 | }
|
| 76 | + |
71 | 77 | return $html;
|
72 | 78 | }
|
73 | 79 |
|
74 | 80 | /**
|
75 |
| - * Generates a string representation of one or more rows of a table of lines, where new text was added. |
| 81 | + * Generates a string representation of table rows showing added text. |
76 | 82 | *
|
77 |
| - * @param array &$change Array with data about changes. |
78 |
| - * @return string Html code representing one or more rows of added text. |
| 83 | + * @param array $change Contains the op-codes about the changes between two blocks of text. |
| 84 | + * |
| 85 | + * @return string HTML code representing table rows showing with added text. |
79 | 86 | */
|
80 |
| - public function generateTableRowsInsert(array &$change): string |
| 87 | + public function generateTableRowsInsert(array $change): string |
81 | 88 | {
|
82 |
| - $html = ""; |
| 89 | + $html = ''; |
| 90 | + |
83 | 91 | foreach ($change['changed']['lines'] as $no => $line) {
|
84 | 92 | $toLine = $change['changed']['offset'] + $no + 1;
|
85 |
| - $html .= '<tr>'; |
86 |
| - $html .= '<th> </th>'; |
87 |
| - $html .= '<th>' . $toLine . '</th>'; |
88 |
| - $html .= '<td class="Right"><ins>' . $line . '</ins> </td>'; |
89 |
| - $html .= '</tr>'; |
| 93 | + |
| 94 | + $html .= <<<HTML |
| 95 | +<tr> |
| 96 | + <th> </th> |
| 97 | + <th>$toLine</th> |
| 98 | + <td class="Right"> |
| 99 | + <ins>$line</ins> |
| 100 | +   |
| 101 | + </td> |
| 102 | +</tr> |
| 103 | +HTML; |
90 | 104 | }
|
| 105 | + |
91 | 106 | return $html;
|
92 | 107 | }
|
93 | 108 |
|
94 | 109 | /**
|
95 |
| - * Generates a string representation of one or more rows of a table of lines, where text was removed. |
| 110 | + * Generates a string representation of table rows showing removed text. |
| 111 | + * |
| 112 | + * @param array $change Contains the op-codes about the changes between two blocks of text. |
96 | 113 | *
|
97 |
| - * @param array &$change Array with data about changes. |
98 |
| - * @return string Html code representing one or more rows of removed text. |
| 114 | + * @return string HTML code representing table rows showing removed text. |
99 | 115 | */
|
100 |
| - public function generateTableRowsDelete(array &$change): string |
| 116 | + public function generateTableRowsDelete(array $change): string |
101 | 117 | {
|
102 |
| - $html = ""; |
| 118 | + $html = ''; |
| 119 | + |
103 | 120 | foreach ($change['base']['lines'] as $no => $line) {
|
104 | 121 | $fromLine = $change['base']['offset'] + $no + 1;
|
105 |
| - $html .= '<tr>'; |
106 |
| - $html .= '<th>' . $fromLine . '</th>'; |
107 |
| - $html .= '<th> </th>'; |
108 |
| - $html .= '<td class="Left"><del>' . $line . '</del> </td>'; |
109 |
| - $html .= '</tr>'; |
| 122 | + |
| 123 | + $html .= <<<HTML |
| 124 | +<tr> |
| 125 | + <th>$fromLine</th> |
| 126 | + <th> </th> |
| 127 | + <td class="Left"> |
| 128 | + <del>$line</del> |
| 129 | +   |
| 130 | + </td> |
| 131 | +</tr> |
| 132 | +HTML; |
110 | 133 | }
|
| 134 | + |
111 | 135 | return $html;
|
112 | 136 | }
|
113 | 137 |
|
114 | 138 | /**
|
115 |
| - * Generates a string representation of one or more rows of a table of lines, where text was partially modified. |
| 139 | + * Generates a string representation of table rows showing partialy modified text. |
| 140 | + * |
| 141 | + * @param array $change Contains the op-codes about the changes between two blocks of text. |
116 | 142 | *
|
117 |
| - * @param array &$change Array with data about changes. |
118 |
| - * @return string Html code representing one or more rows of modified. |
| 143 | + * @return string Html code representing table rows showing modified text. |
119 | 144 | */
|
120 | 145 | public function generateTableRowsReplace(array &$change): string
|
121 | 146 | {
|
122 |
| - $html = ""; |
| 147 | + $html = ''; |
123 | 148 |
|
124 | 149 | foreach ($change['base']['lines'] as $no => $line) {
|
125 | 150 | $fromLine = $change['base']['offset'] + $no + 1;
|
126 |
| - $html .= '<tr>'; |
127 |
| - $html .= '<th>' . $fromLine . '</th>'; |
128 |
| - $html .= '<th> </th>'; |
129 |
| - $html .= '<td class="Left"><span>' . $line . '</span></td>'; |
130 |
| - $html .= '</tr>'; |
| 151 | + |
| 152 | + $html .= <<<HTML |
| 153 | +<tr> |
| 154 | + <th>$fromLine</th> |
| 155 | + <th> </th> |
| 156 | + <td class="Left"> |
| 157 | + <span>$line</span> |
| 158 | + </td> |
| 159 | +</tr> |
| 160 | +HTML; |
131 | 161 | }
|
132 | 162 |
|
133 | 163 | foreach ($change['changed']['lines'] as $no => $line) {
|
134 | 164 | $toLine = $change['changed']['offset'] + $no + 1;
|
135 |
| - $html .= '<tr>'; |
136 |
| - $html .= '<th> </th>'; |
137 |
| - $html .= '<th>' . $toLine . '</th>'; |
138 |
| - $html .= '<td class="Right"><span>' . $line . '</span></td>'; |
139 |
| - $html .= '</tr>'; |
| 165 | + |
| 166 | + $html .= <<<HTML |
| 167 | +<tr> |
| 168 | + <th> </th> |
| 169 | + <th>$toLine</th> |
| 170 | + <td class="Right"> |
| 171 | + <span>$line</span> |
| 172 | + </td> |
| 173 | +</tr> |
| 174 | +HTML; |
140 | 175 | }
|
141 | 176 |
|
142 | 177 | return $html;
|
|
0 commit comments