-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
54 lines (48 loc) · 1.38 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require file_exists(__DIR__ . '/vendor')
? __DIR__ . '/vendor/autoload.php'
: __DIR__ . '/../../autoload.php';
$loader->add('Clevis\\TemplatePreview', __DIR__ . '/src');
\Tracy\Debugger::enable(\Tracy\Debugger::DEBUG);
$project = __DIR__ . '/../../../app';
$appLoader = new \Nette\Loaders\RobotLoader();
$storage = new \Nette\Caching\Storages\FileStorage(__DIR__. '/temp');
$appLoader->setCacheStorage($storage);
$appLoader->addDirectory($project);
$appLoader->register();
if (!isset($_GET['template']))
{
$templates = [];
foreach (\Nette\Utils\Finder::findFiles('*.latte')->from($project) as $file)
{
$short = substr($file, strlen($project));
$short = ltrim($short, '/');
$package = explode('/', $short)[0];
$templates[$package][realpath($file)] = $short;
}
$latte = new \Latte\Engine();
$latte->render(__DIR__ . '/src/templates/list.latte', [
'templates' => $templates,
]);
}
else
{
$template = $_GET['template'];
$layout = NULL;
if (strpos(basename($template), '@') !== 0)
{
$in = dirname($template);
do
{
foreach (\Nette\Utils\Finder::findFiles('@layout.latte')->from($in) as $layout => $info)
{
// layout set
break 2;
}
$in = dirname($in);
} while ($in !== '/');
}
$renderer = new \Clevis\TemplatePreview\Renderer($template, $layout, __DIR__ . '/temp');
echo $renderer->render();
}