/** * Loads template-specific macro and helper libraries. * * @param \ApiGen\Template $template Template instance */ private function registerCustomTemplateMacros(Template $template) { $latte = new Nette\Latte\Engine(); if (!empty($this->config->template['options']['extensions'])) { $this->output("Loading custom template macro and helper libraries\n"); $broker = new Broker(new Broker\Backend\Memory(), 0); $baseDir = dirname($this->config->template['config']); foreach ((array) $this->config->template['options']['extensions'] as $fileName) { $pathName = $baseDir . DIRECTORY_SEPARATOR . $fileName; if (is_file($pathName)) { try { $reflectionFile = $broker->processFile($pathName, true); foreach ($reflectionFile->getNamespaces() as $namespace) { foreach ($namespace->getClasses() as $class) { if ($class->isSubclassOf('ApiGen\\MacroSet')) { // Macro set include $pathName; call_user_func(array($class->getName(), 'install'), $latte->compiler); $this->output(sprintf(" %s (macro set)\n", $class->getName())); } elseif ($class->implementsInterface('ApiGen\\IHelperSet')) { // Helpers set include $pathName; $className = $class->getName(); $template->registerHelperLoader(callback(new $className($template), 'loader')); $this->output(sprintf(" %s (helper set)\n", $class->getName())); } } } } catch (\Exception $e) { throw new \Exception(sprintf('Could not load macros and helpers from file "%s"', $pathName), 0, $e); } } else { throw new \Exception(sprintf('Helper file "%s" does not exist.', $pathName)); } } } $template->registerFilter($latte); }