public function __construct($path) { $cacheFile = $path . '/routes.php'; if (is_file($cacheFile = $path . '/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->parser); $macroSet->addMacro('url', function($node) use (&$routes, $file) { $routes[$node->args] = (string) $file; }); $latte->__invoke(file_get_contents($file)); } file_put_contents($cacheFile, '<?php return ' . var_export($routes, TRUE) . ';'); } foreach ($routes as $mask => $file) { $this[] = new Routers\Route($mask, function($presenter) use ($file) { return $presenter->createTemplate(NULL, function() { $latte = new Nette\Latte\Engine; $macroSet = new Latte\Macros\MacroSet($latte->parser); $macroSet->addMacro('url', ''); return $latte; })->setFile($file); }); } }
public function templatePrepareFilters($template) { $latte = new \Nette\Latte\Engine(); $template->registerFilter($latte); $set = \Nette\Latte\Macros\MacroSet::install($latte->parser); $set->addMacro('popup', 'Macros::popup(%node.word, $template) '); }
/** * @param \Nette\Latte\Parser */ public static function install(\Nette\Latte\Parser $parser) { $me = parent::install($parser); // n:phref $me->addMacro('@phref', function(MacroNode $node, $writer) use ($me) { return ' ?> href="<?php ' . $me->macroPlink($node, $writer) . ' ?>"<?php '; }); // image $me->addMacro('image', array($me, 'macroImage')); // n:src $me->addMacro('@src', function(MacroNode $node, $writer) use ($me) { return ' ?> src="<?php ' . $me->macroImage($node, $writer) . ' ?>"<?php '; }); // n:ihref $me->addMacro('@ihref', function(MacroNode $node, $writer) use ($me) { return ' ?> href="<?php ' . $me->macroImage($node, $writer) . ' ?>"<?php '; }); // file $me->addMacro('file', array($me, 'macroFile')); // n:fhref $me->addMacro('@fhref', function(MacroNode $node, $writer) use ($me) { return ' ?> href="<?php ' . $me->macroFile($node, $writer) . ' ?>"<?php '; }); }
public function templatePrepareFilters($template) { $latte = new \Nette\Latte\Engine(); $template->registerFilter($latte); $set = \Nette\Latte\Macros\MacroSet::install($latte->parser); $set->addMacro('css', callback('\\Tatami\\Components\\AssetsLoader\\Macro', 'macroCss')); $set->addMacro('js', callback('\\Tatami\\Components\\AssetsLoader\\Macro', 'macroJs')); $set->addMacro('image', callback('\\Tatami\\Components\\AssetsLoader\\Macro', 'macroImage')); }
/** * * @param Presenter $presenter * @return FileTemplate */ private function createTemplate(Presenter $presenter) { $template = new FileTemplate(); $latte = new Engine(); $template->registerFilter($latte); $set = MacroSet::install($latte->getCompiler()); $template->control = $template->presenter = $presenter; return $template; }
/** * * @param Presenter $presenter * @return FileTemplate */ private function createTemplate(Presenter $presenter) { $template = new FileTemplate(); $latte = new Engine(); $template->registerFilter($latte); $set = MacroSet::install($latte->parser); $template->control = $template->presenter = $presenter; $template->setTranslator($presenter->context->translator); return $template; }
/** * Load latte and set aditional macros * @author Pavel Železný <*****@*****.**> * @param \Nette\Templating\Template $template * @return void */ public function templatePrepareFilters($template) { $template->registerFilter($latte = new \Nette\Latte\Engine()); $set = \Nette\Latte\Macros\MacroSet::install($latte->getCompiler()); $set->addMacro('src', NULL, NULL, 'echo \'src="\'.\\Nette\\Templating\\Helpers::dataStream(file_get_contents(%node.word)).\'"\''); }