Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Micro-blog: small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 5, 2014
1 parent 56bd201 commit c21c4b3
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Micro-blog/www/data/TemplateRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ public function __construct($path, $cachePath)
if (is_file($cacheFile = $cachePath . '/routes.php')) {
$routes = require $cacheFile;
} else {
$routes = array();
foreach (Nette\Utils\Finder::findFiles('*.latte')->from($path) as $file) {
$latte = new Latte\Engine;
$macroSet = new Latte\Macros\MacroSet($latte->getCompiler());
$macroSet->addMacro('url', function($node) use (&$routes, $file) {
$routes[$node->args] = (string) $file;
});
$latte->compile($file);
}
$routes = $this->scanRoutes($path);
file_put_contents($cacheFile, '<?php return ' . var_export($routes, TRUE) . ';');
}

Expand All @@ -39,4 +31,19 @@ public function __construct($path, $cachePath)
}
}


public function scanRoutes($path)
{
$routes = array();
$latte = new Latte\Engine;
$macroSet = new Latte\Macros\MacroSet($latte->getCompiler());
$macroSet->addMacro('url', function($node) use (&$routes, &$file) {
$routes[$node->args] = (string) $file;
});
foreach (Nette\Utils\Finder::findFiles('*.latte')->from($path) as $file) {
$latte->compile($file);
}
return $routes;
}

}

0 comments on commit c21c4b3

Please sign in to comment.