1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2017 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/allejo/stakx/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\stakx; |
9
|
|
|
|
10
|
|
|
use allejo\stakx\Command\BuildableCommand; |
11
|
|
|
use allejo\stakx\Document\BasePageView; |
12
|
|
|
use allejo\stakx\Document\ContentItem; |
13
|
|
|
use allejo\stakx\Document\DynamicPageView; |
14
|
|
|
use allejo\stakx\Document\PermalinkDocument; |
15
|
|
|
use allejo\stakx\Document\RepeaterPageView; |
16
|
|
|
use allejo\stakx\Document\StaticPageView; |
17
|
|
|
use allejo\stakx\Document\TemplateReadyDocument; |
18
|
|
|
use allejo\stakx\Exception\FileAwareException; |
19
|
|
|
use allejo\stakx\Filesystem\FilesystemLoader as fs; |
20
|
|
|
use allejo\stakx\FrontMatter\ExpandedValue; |
21
|
|
|
use allejo\stakx\Manager\BaseManager; |
22
|
|
|
use allejo\stakx\Manager\PageManager; |
23
|
|
|
use allejo\stakx\Manager\ThemeManager; |
24
|
|
|
use allejo\stakx\Filesystem\Folder; |
25
|
|
|
use allejo\stakx\System\FilePath; |
26
|
|
|
use allejo\stakx\Templating\TemplateBridgeInterface; |
27
|
|
|
use allejo\stakx\Templating\TemplateErrorInterface; |
28
|
|
|
use allejo\stakx\Templating\TemplateInterface; |
29
|
|
|
use Symfony\Component\Filesystem\Exception\FileNotFoundException; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* This class takes care of rendering the Twig body of PageViews with the respective information and it also takes care |
33
|
|
|
* of writing the rendered Twig to the filesystem. |
34
|
|
|
* |
35
|
|
|
* @internal |
36
|
|
|
* |
37
|
|
|
* @since 0.1.1 |
38
|
|
|
*/ |
39
|
|
|
class Compiler extends BaseManager |
40
|
|
|
{ |
41
|
|
|
/** @var string|false */ |
42
|
|
|
private $redirectTemplate; |
43
|
|
|
|
44
|
|
|
/** @var BasePageView[][] */ |
45
|
|
|
private $importDependencies; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Any time a PageView extends another template, that relationship is stored in this array. This is necessary so |
49
|
|
|
* when watching a website, we can rebuild the necessary PageViews when these base templates change. |
50
|
|
|
* |
51
|
|
|
* ``` |
52
|
|
|
* array['_layouts/base.html.twig'] = &PageView; |
53
|
|
|
* ``` |
54
|
|
|
* |
55
|
|
|
* @var TemplateInterface[] |
56
|
|
|
*/ |
57
|
|
|
private $templateDependencies; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* All of the PageViews handled by this Compiler instance indexed by their file paths relative to the site root. |
61
|
|
|
* |
62
|
|
|
* ``` |
63
|
|
|
* array['_pages/index.html.twig'] = &PageView; |
64
|
|
|
* ``` |
65
|
|
|
* |
66
|
|
|
* @var BasePageView[] |
67
|
|
|
*/ |
68
|
|
|
private $pageViewsFlattened; |
69
|
|
|
|
70
|
|
|
/** @var string[] */ |
71
|
|
|
private $templateMapping; |
72
|
|
|
|
73
|
|
|
/** @var BasePageView[][] */ |
74
|
|
|
private $pageViews; |
75
|
|
|
|
76
|
|
|
/** @var Folder */ |
77
|
|
|
private $folder; |
78
|
|
|
|
79
|
|
|
/** @var string */ |
80
|
|
|
private $theme; |
81
|
|
|
|
82
|
|
|
/** @var TemplateBridgeInterface */ |
83
|
|
|
private $templateBridge; |
84
|
|
|
|
85
|
14 |
|
public function __construct(TemplateBridgeInterface $templateBridge) |
86
|
|
|
{ |
87
|
14 |
|
parent::__construct(); |
88
|
|
|
|
89
|
14 |
|
$this->templateBridge = $templateBridge; |
90
|
14 |
|
$this->theme = ''; |
91
|
14 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string|false $template |
95
|
|
|
*/ |
96
|
|
|
public function setRedirectTemplate($template) |
97
|
|
|
{ |
98
|
|
|
$this->redirectTemplate = $template; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param Folder $folder |
103
|
|
|
*/ |
104
|
14 |
|
public function setTargetFolder(Folder $folder) |
105
|
|
|
{ |
106
|
14 |
|
$this->folder = $folder; |
107
|
14 |
|
} |
108
|
|
|
|
109
|
|
|
public function setPageManager(PageManager $manager) |
110
|
|
|
{ |
111
|
|
|
$this->pageViews = &$manager->getPageViews(); |
112
|
|
|
$this->pageViewsFlattened = &$manager->getPageViewsFlattened(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @deprecated Use setPageManager() |
117
|
|
|
* |
118
|
|
|
* @param BasePageView[][] $pageViews |
119
|
|
|
* @param BasePageView[] $pageViewsFlattened |
120
|
|
|
*/ |
121
|
|
|
public function setPageViews(array &$pageViews, array &$pageViewsFlattened) |
122
|
|
|
{ |
123
|
|
|
$this->pageViews = &$pageViews; |
124
|
|
|
$this->pageViewsFlattened = &$pageViewsFlattened; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param string $themeName |
129
|
|
|
*/ |
130
|
|
|
public function setThemeName($themeName) |
131
|
|
|
{ |
132
|
|
|
$this->theme = $themeName; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/// |
136
|
|
|
// Twig parent templates |
137
|
|
|
/// |
138
|
|
|
|
139
|
|
|
public function isImportDependency($filePath) |
140
|
|
|
{ |
141
|
|
|
return isset($this->importDependencies[$filePath]); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Check whether a given file path is used as a parent template by a PageView |
146
|
|
|
* |
147
|
|
|
* @param string $filePath |
148
|
|
|
* |
149
|
|
|
* @return bool |
150
|
|
|
*/ |
151
|
|
|
public function isParentTemplate($filePath) |
152
|
|
|
{ |
153
|
|
|
return isset($this->templateDependencies[$filePath]); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Rebuild all of the PageViews that used a given template as a parent |
158
|
|
|
* |
159
|
|
|
* @param string $filePath The file path to the parent Twig template |
160
|
|
|
*/ |
161
|
|
|
public function refreshParent($filePath) |
162
|
|
|
{ |
163
|
|
|
foreach ($this->templateDependencies[$filePath] as &$parentTemplate) |
|
|
|
|
164
|
|
|
{ |
165
|
|
|
$this->compilePageView($parentTemplate); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function getTemplateMappings() |
170
|
|
|
{ |
171
|
|
|
return $this->templateMapping; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/// |
175
|
|
|
// IO Functionality |
176
|
|
|
/// |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Compile all of the PageViews registered with the compiler. |
180
|
|
|
* |
181
|
|
|
* @since 0.1.0 |
182
|
|
|
*/ |
183
|
14 |
|
public function compileAll() |
184
|
|
|
{ |
185
|
14 |
|
foreach ($this->pageViewsFlattened as &$pageView) |
186
|
|
|
{ |
187
|
14 |
|
$this->compilePageView($pageView); |
188
|
14 |
|
} |
189
|
14 |
|
} |
190
|
|
|
|
191
|
|
|
public function compileImportDependencies($filePath) |
192
|
|
|
{ |
193
|
|
|
foreach ($this->importDependencies[$filePath] as &$dependent) |
194
|
|
|
{ |
195
|
|
|
$this->compilePageView($dependent); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function compileSome(array $filter = array()) |
200
|
|
|
{ |
201
|
|
|
/** @var BasePageView $pageView */ |
202
|
|
|
foreach ($this->pageViewsFlattened as &$pageView) |
203
|
|
|
{ |
204
|
|
|
$ns = $filter['namespace']; |
205
|
|
|
|
206
|
|
|
if ($pageView->hasDependencyOnCollection($ns, $filter['dependency']) || |
207
|
|
|
$pageView->hasDependencyOnCollection($ns, null) |
208
|
|
|
) { |
209
|
|
|
$this->compilePageView($pageView); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Compile an individual PageView from a given path. |
216
|
|
|
* |
217
|
|
|
* @param string $filePath |
218
|
|
|
* |
219
|
|
|
* @throws FileNotFoundException When the given file path isn't tracked by the Compiler. |
220
|
|
|
*/ |
221
|
|
|
public function compilePageViewFromPath($filePath) |
222
|
|
|
{ |
223
|
|
|
if (!isset($this->pageViewsFlattened[$filePath])) |
224
|
|
|
{ |
225
|
|
|
throw new FileNotFoundException(sprintf('The "%s" PageView is not being tracked by this compiler.', $filePath)); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
$this->compilePageView($this->pageViewsFlattened[$filePath]); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Compile an individual PageView item. |
233
|
|
|
* |
234
|
|
|
* This function will take care of determining *how* to treat the PageView and write the compiled output to a the |
235
|
|
|
* respective target file. |
236
|
|
|
* |
237
|
|
|
* @param DynamicPageView|RepeaterPageView|StaticPageView $pageView The PageView that needs to be compiled |
|
|
|
|
238
|
|
|
* |
239
|
|
|
* @since 0.1.1 |
240
|
|
|
*/ |
241
|
14 |
|
public function compilePageView(BasePageView &$pageView) |
242
|
|
|
{ |
243
|
14 |
|
$this->templateBridge->setGlobalVariable('__currentTemplate', $pageView->getAbsoluteFilePath()); |
244
|
14 |
|
$this->output->debug('Compiling {type} PageView: {pageview}', array( |
245
|
14 |
|
'pageview' => $pageView->getRelativeFilePath(), |
246
|
14 |
|
'type' => $pageView->getType() |
247
|
14 |
|
)); |
248
|
|
|
|
249
|
|
|
try |
250
|
|
|
{ |
251
|
14 |
|
switch ($pageView->getType()) |
252
|
|
|
{ |
253
|
14 |
|
case BasePageView::STATIC_TYPE: |
254
|
10 |
|
$this->compileStaticPageView($pageView); |
|
|
|
|
255
|
10 |
|
$this->compileStandardRedirects($pageView); |
256
|
10 |
|
break; |
257
|
|
|
|
258
|
4 |
|
case BasePageView::DYNAMIC_TYPE: |
259
|
2 |
|
$this->compileDynamicPageViews($pageView); |
|
|
|
|
260
|
2 |
|
$this->compileStandardRedirects($pageView); |
261
|
2 |
|
break; |
262
|
|
|
|
263
|
2 |
|
case BasePageView::REPEATER_TYPE: |
264
|
2 |
|
$this->compileRepeaterPageViews($pageView); |
|
|
|
|
265
|
2 |
|
$this->compileExpandedRedirects($pageView); |
266
|
2 |
|
break; |
267
|
14 |
|
} |
268
|
|
|
} |
269
|
14 |
|
catch (TemplateErrorInterface $e) |
270
|
|
|
{ |
271
|
|
|
throw new FileAwareException( |
272
|
|
|
$e->getMessage(), |
273
|
|
|
$e->getCode(), |
274
|
|
|
$e, |
275
|
|
|
$pageView->getRelativeFilePath(), |
276
|
|
|
$e->getTemplateLine() + $pageView->getLineOffset() |
|
|
|
|
277
|
|
|
); |
278
|
|
|
} |
279
|
14 |
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Write the compiled output for a static PageView. |
283
|
|
|
* |
284
|
|
|
* @since 0.1.1 |
285
|
|
|
* |
286
|
|
|
* @throws TemplateErrorInterface |
287
|
|
|
*/ |
288
|
10 |
|
private function compileStaticPageView(StaticPageView &$pageView) |
289
|
|
|
{ |
290
|
10 |
|
$targetFile = $pageView->getTargetFile(); |
291
|
10 |
|
$output = $this->renderStaticPageView($pageView); |
292
|
|
|
|
293
|
10 |
|
$this->output->notice('Writing file: {file}', array('file' => $targetFile)); |
294
|
10 |
|
$this->folder->writeFile($targetFile, $output); |
295
|
10 |
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Write the compiled output for a dynamic PageView. |
299
|
|
|
* |
300
|
|
|
* @param DynamicPageView $pageView |
301
|
|
|
* |
302
|
|
|
* @since 0.1.1 |
303
|
|
|
* |
304
|
|
|
* @throws TemplateErrorInterface |
305
|
|
|
*/ |
306
|
2 |
|
private function compileDynamicPageViews(DynamicPageView &$pageView) |
307
|
|
|
{ |
308
|
2 |
|
$contentItems = $pageView->getCollectableItems(); |
309
|
2 |
|
$template = $this->createTwigTemplate($pageView); |
310
|
|
|
|
311
|
2 |
|
foreach ($contentItems as &$contentItem) |
312
|
|
|
{ |
313
|
2 |
|
if ($contentItem->isDraft() && !Service::getParameter(BuildableCommand::USE_DRAFTS)) |
314
|
2 |
|
{ |
315
|
1 |
|
$this->output->debug('{file}: marked as a draft', array( |
316
|
1 |
|
'file' => $contentItem->getRelativeFilePath() |
317
|
1 |
|
)); |
318
|
|
|
|
319
|
1 |
|
continue; |
320
|
|
|
} |
321
|
|
|
|
322
|
2 |
|
$targetFile = $contentItem->getTargetFile(); |
323
|
2 |
|
$output = $this->renderDynamicPageView($template, $contentItem); |
|
|
|
|
324
|
|
|
|
325
|
2 |
|
$this->output->notice('Writing file: {file}', array('file' => $targetFile)); |
326
|
2 |
|
$this->folder->writeFile($targetFile, $output); |
327
|
|
|
|
328
|
2 |
|
$this->compileStandardRedirects($contentItem); |
|
|
|
|
329
|
2 |
|
} |
330
|
2 |
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Write the compiled output for a repeater PageView. |
334
|
|
|
* |
335
|
|
|
* @param RepeaterPageView $pageView |
336
|
|
|
|
337
|
|
|
* @since 0.1.1 |
338
|
|
|
* |
339
|
|
|
* @throws TemplateErrorInterface |
340
|
|
|
*/ |
341
|
2 |
|
private function compileRepeaterPageViews(RepeaterPageView &$pageView) |
342
|
|
|
{ |
343
|
2 |
|
$pageView->rewindPermalink(); |
344
|
|
|
|
345
|
2 |
|
$template = $this->createTwigTemplate($pageView); |
346
|
2 |
|
$permalinks = $pageView->getRepeaterPermalinks(); |
|
|
|
|
347
|
|
|
|
348
|
2 |
|
foreach ($permalinks as $permalink) |
349
|
|
|
{ |
350
|
2 |
|
$pageView->bumpPermalink(); |
|
|
|
|
351
|
2 |
|
$targetFile = $pageView->getTargetFile(); |
352
|
2 |
|
$output = $this->renderRepeaterPageView($template, $pageView, $permalink); |
|
|
|
|
353
|
|
|
|
354
|
2 |
|
$this->output->notice('Writing repeater file: {file}', ['file' => $targetFile]); |
355
|
2 |
|
$this->folder->writeFile($targetFile, $output); |
356
|
2 |
|
} |
357
|
2 |
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* @deprecated |
361
|
|
|
* |
362
|
|
|
* @todo This function needs to be rewritten or removed. Something |
363
|
|
|
* |
364
|
|
|
* @param ContentItem $contentItem |
365
|
|
|
*/ |
366
|
|
|
public function compileContentItem(ContentItem &$contentItem) |
367
|
|
|
{ |
368
|
|
|
$pageView = &$contentItem->getPageView(); |
|
|
|
|
369
|
|
|
$template = $this->createTwigTemplate($pageView); |
370
|
|
|
|
371
|
|
|
$this->templateBridge->setGlobalVariable('__currentTemplate', $pageView->getAbsoluteFilePath()); |
372
|
|
|
$contentItem->evaluateFrontMatter($pageView->getFrontMatter(false)); |
373
|
|
|
|
374
|
|
|
$targetFile = $contentItem->getTargetFile(); |
375
|
|
|
$output = $this->renderDynamicPageView($template, $contentItem); |
376
|
|
|
|
377
|
|
|
$this->output->notice('Writing file: {file}', array('file' => $targetFile)); |
378
|
|
|
$this->folder->writeFile($targetFile, $output); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/// |
382
|
|
|
// Redirect handling |
383
|
|
|
/// |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Write redirects for standard redirects. |
387
|
|
|
* |
388
|
|
|
* @throws TemplateErrorInterface |
389
|
|
|
* |
390
|
|
|
* @since 0.1.1 |
391
|
|
|
*/ |
392
|
12 |
|
private function compileStandardRedirects(PermalinkDocument &$pageView) |
393
|
|
|
{ |
394
|
12 |
|
$redirects = $pageView->getRedirects(); |
395
|
|
|
|
396
|
12 |
|
foreach ($redirects as $redirect) |
397
|
|
|
{ |
398
|
4 |
|
$redirectPageView = BasePageView::createRedirect( |
399
|
4 |
|
$redirect, |
400
|
4 |
|
$pageView->getPermalink(), |
401
|
4 |
|
$this->redirectTemplate |
402
|
4 |
|
); |
403
|
|
|
|
404
|
4 |
|
$this->compileStaticPageView($redirectPageView); |
405
|
12 |
|
} |
406
|
12 |
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* Write redirects for expanded redirects. |
410
|
|
|
* |
411
|
|
|
* @param RepeaterPageView $pageView |
412
|
|
|
* |
413
|
|
|
* @since 0.1.1 |
414
|
|
|
*/ |
415
|
2 |
|
private function compileExpandedRedirects(RepeaterPageView &$pageView) |
416
|
|
|
{ |
417
|
2 |
|
$permalinks = $pageView->getRepeaterPermalinks(); |
418
|
|
|
|
419
|
|
|
/** @var ExpandedValue[] $repeaterRedirect */ |
420
|
2 |
|
foreach ($pageView->getRepeaterRedirects() as $repeaterRedirect) |
421
|
|
|
{ |
422
|
|
|
/** |
423
|
|
|
* @var int $index |
424
|
|
|
* @var ExpandedValue $redirect |
425
|
|
|
*/ |
426
|
|
|
foreach ($repeaterRedirect as $index => $redirect) |
427
|
|
|
{ |
428
|
|
|
$redirectPageView = BasePageView::createRedirect( |
429
|
|
|
$redirect->getEvaluated(), |
430
|
|
|
$permalinks[$index]->getEvaluated(), |
431
|
|
|
$this->redirectTemplate |
432
|
|
|
); |
433
|
|
|
$this->compilePageView($redirectPageView); |
434
|
|
|
} |
435
|
2 |
|
} |
436
|
2 |
|
} |
437
|
|
|
|
438
|
|
|
/// |
439
|
|
|
// Twig Functionality |
440
|
|
|
/// |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Get the compiled HTML for a specific iteration of a repeater PageView. |
444
|
|
|
* |
445
|
|
|
* @param TemplateInterface $template |
446
|
|
|
* @param RepeaterPageView $pageView |
447
|
|
|
* @param ExpandedValue $expandedValue |
448
|
|
|
* |
449
|
|
|
* @since 0.1.1 |
450
|
|
|
* |
451
|
|
|
* @return string |
452
|
|
|
*/ |
453
|
2 |
|
private function renderRepeaterPageView(TemplateInterface &$template, RepeaterPageView &$pageView, ExpandedValue &$expandedValue) |
454
|
|
|
{ |
455
|
2 |
|
$pageView->evaluateFrontMatter([ |
456
|
2 |
|
'permalink' => $expandedValue->getEvaluated(), |
457
|
2 |
|
'iterators' => $expandedValue->getIterators(), |
458
|
2 |
|
]); |
459
|
|
|
|
460
|
|
|
return $template |
461
|
2 |
|
->render(array( |
462
|
2 |
|
'this' => $pageView->createJail(), |
463
|
2 |
|
)); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* Get the compiled HTML for a specific ContentItem. |
468
|
|
|
* |
469
|
|
|
* @since 0.1.1 |
470
|
|
|
* |
471
|
|
|
* @return string |
472
|
|
|
*/ |
473
|
2 |
|
private function renderDynamicPageView(TemplateInterface &$template, TemplateReadyDocument &$twigItem) |
474
|
|
|
{ |
475
|
|
|
return $template |
476
|
2 |
|
->render(array( |
477
|
2 |
|
'this' => $twigItem->createJail(), |
478
|
2 |
|
)); |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* Get the compiled HTML for a static PageView. |
483
|
|
|
* |
484
|
|
|
* @since 0.1.1 |
485
|
|
|
* |
486
|
|
|
* @throws TemplateErrorInterface |
487
|
|
|
* |
488
|
|
|
* @return string |
489
|
|
|
*/ |
490
|
10 |
|
private function renderStaticPageView(StaticPageView &$pageView) |
491
|
|
|
{ |
492
|
10 |
|
return $this |
493
|
10 |
|
->createTwigTemplate($pageView) |
494
|
10 |
|
->render(array( |
495
|
10 |
|
'this' => $pageView->createJail(), |
|
|
|
|
496
|
10 |
|
)); |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
/** |
500
|
|
|
* Create a Twig template that just needs an array to render. |
501
|
|
|
* |
502
|
|
|
* @since 0.1.1 |
503
|
|
|
* |
504
|
|
|
* @throws TemplateErrorInterface |
505
|
|
|
* |
506
|
|
|
* @return TemplateInterface |
507
|
|
|
*/ |
508
|
14 |
|
private function createTwigTemplate(BasePageView &$pageView) |
509
|
|
|
{ |
510
|
|
|
try |
511
|
|
|
{ |
512
|
14 |
|
$template = $this->templateBridge->createTemplate($pageView->getContent()); |
513
|
|
|
|
514
|
14 |
|
$this->templateMapping[$template->getTemplateName()] = $pageView->getRelativeFilePath(); |
515
|
|
|
|
516
|
14 |
|
if (Service::getParameter(BuildableCommand::WATCHING)) |
517
|
14 |
|
{ |
518
|
|
|
// Keep track of import dependencies |
519
|
|
|
foreach ($pageView->getImportDependencies() as $dependency) |
520
|
|
|
{ |
521
|
|
|
$this->importDependencies[$dependency][$pageView->getBasename()] = &$pageView; |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
// Keep track of Twig extends' |
525
|
|
|
$parent = $template->getParentTemplate(); |
526
|
|
|
|
527
|
|
|
while ($parent !== false) |
528
|
|
|
{ |
529
|
|
|
// Replace the '@theme' namespace in Twig with the path to the theme folder and create a UnixFilePath object from the given path |
530
|
|
|
$path = str_replace('@theme', fs::appendPath(ThemeManager::THEME_FOLDER, $this->theme), $parent->getTemplateName()); |
531
|
|
|
$path = new FilePath($path); |
532
|
|
|
|
533
|
|
|
$this->templateDependencies[(string)$path][$pageView->getBasename()] = &$pageView; |
534
|
|
|
|
535
|
|
|
$parent = $parent->getParentTemplate(); |
536
|
|
|
} |
537
|
|
|
} |
538
|
|
|
|
539
|
14 |
|
return $template; |
540
|
|
|
} |
541
|
|
|
catch (TemplateErrorInterface $e) |
542
|
|
|
{ |
543
|
|
|
$e |
544
|
|
|
->setTemplateLine($e->getTemplateLine() + $pageView->getLineOffset()) |
545
|
|
|
->setContent($pageView->getContent()) |
546
|
|
|
->setName($pageView->getRelativeFilePath()) |
547
|
|
|
->setRelativeFilePath($pageView->getRelativeFilePath()) |
548
|
|
|
->buildException() |
549
|
|
|
; |
550
|
|
|
|
551
|
|
|
throw $e; |
552
|
|
|
} |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
|