public function getPanel() { $template = new FileTemplate(dirname(__FILE__) . '/template.latte'); $template->registerFilter(new LatteFilter()); $template->registerHelper("editorLink", callback(__CLASS__, "getEditorLink")); $template->registerHelper("substr", "substr"); $template->presenterClass = $this->getPresenter()->getReflection(); $template->actionName = $this->getPresenter()->getAction(true); $template->templateFileName = $this->getTemplateFileName(); $template->layoutFileName = $this->getLayoutFileName(); $template->appDirPathLength = strlen(realpath($this->getAppDir())); $template->interestedMethods = $this->getInterestedMethodReflections(); $template->parentClasses = $this->getParentClasses(); $template->usedComponentMethods = $this->getUsedComponentMethods(); $template->unusedComponentMethods = $this->getUnusedComponentMethods(); return $template->__toString(); }
/** * @param array $report See ScreenshotMaker::$report */ public function generate(array $report) { foreach (Finder::findFiles('*.png')->in($this->outDir) as $image) { /** @var \SplFileInfo $image */ $blank = Image::fromBlank(120, 120, array('green' => 255, 'blue' => 255, 'red' => 255)); $blank->place(Image::fromFile($image->getPathname())->resize(120, 120)); $blank->save(dirname($image->getPathname()) . '/' . $image->getBasename('.png') . '.thumb.png'); } $tpl = new Nette\Templating\FileTemplate(__DIR__ . '/../templates/report.latte'); $tpl->registerFilter(new Nette\Latte\Engine()); $tpl->registerHelperLoader('Nette\\Templating\\Helpers::loader'); $tpl->registerHelper('resultName', function ($result) { static $names = array(StepEvent::PASSED => 'passed', StepEvent::SKIPPED => 'skipped', StepEvent::PENDING => 'pending', StepEvent::UNDEFINED => 'undefined', StepEvent::FAILED => 'failed'); return isset($names[$result]) ? $names[$result] : '[unknown]'; }); $tpl->registerHelper('resultClass', function ($result) { static $names = array(StepEvent::PASSED => 'passed', StepEvent::SKIPPED => 'skipped', StepEvent::PENDING => 'pending', StepEvent::UNDEFINED => 'undefined', StepEvent::FAILED => 'failed'); return isset($names[$result]) ? $names[$result] : '[unknown]'; }); // render $tpl->report = $report; file_put_contents($this->outDir . '/index.html', $tpl->__toString()); }
/** * @return Nette\Templating\ITemplate */ protected function createTemplate() { $template = new Nette\Templating\FileTemplate(); $presenter = $this->getPresenter(FALSE); $template->onPrepareFilters[] = callback($this, 'templatePrepareFilters'); // default parameters $template->control = $this; $template->presenter = $presenter; if ($presenter instanceof Presenter) { $template->setCacheStorage($presenter->getContext()->templateCacheStorage); $template->user = $presenter->getUser(); $template->netteHttpResponse = $presenter->getHttpResponse(); $template->netteCacheStorage = $presenter->getContext()->cacheStorage; $template->baseUri = $template->baseUrl = rtrim($presenter->getHttpRequest()->getUrl()->getBaseUrl(), '/'); $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl); // flash message if ($presenter->hasFlashSession()) { $id = $this->getParamId('flash'); $template->flashes = $presenter->getFlashSession()->{$id}; } } if (!isset($template->flashes) || !is_array($template->flashes)) { $template->flashes = array(); } // default helpers $template->registerHelper('escape', 'Nette\\Templating\\DefaultHelpers::escapeHtml'); $template->registerHelper('escapeUrl', 'rawurlencode'); $template->registerHelper('stripTags', 'strip_tags'); $template->registerHelper('nl2br', 'nl2br'); $template->registerHelper('substr', 'iconv_substr'); $template->registerHelper('repeat', 'str_repeat'); $template->registerHelper('replaceRE', 'Nette\\Utils\\Strings::replace'); $template->registerHelper('implode', 'implode'); $template->registerHelper('number', 'number_format'); $template->registerHelperLoader('Nette\\Templating\\DefaultHelpers::loader'); return $template; }
/** @return Nette\Templating\FileTemplate */ public function getTemplate() { $template = new Nette\Templating\FileTemplate(); $template->registerFilter(new Nette\Latte\Engine()); $template->registerHelper('json', function ($array) { return json_encode($array); }); $template->registerHelper('toArray', function ($array) { if ($array instanceof \Traversable) { $array = iterator_to_array($array); } return array_map(function ($object) { return $object->toArray(); }, $array); }); $template->setFile(__DIR__ . '/template.latte'); $template->basePath = Nette\Environment::getHttpRequest()->getUrl()->basePath; return $template; }
/** * Creates template instance * * @return Nette\Templating\FileTemplate * * @throws Nette\InvalidStateException if template file was not set * @throws Nette\InvalidArgumentException if template file does not exists */ protected function createTemplate() { if (empty($this->templateFile)) { throw new Nette\InvalidStateException("Template file was not set. Forget to call " . get_called_class() . "::setTempplate()?"); } if (!file_exists($this->templateFile)) { throw new Nette\InvalidArgumentException("Invoice template file '{$this->templateFile}' does not exist."); } $template = new Nette\Templating\FileTemplate($this->templateFile); $template->registerFilter(new Nette\Latte\Engine()); $template->registerHelperLoader('Nette\\Templating\\DefaultHelpers::loader'); $template->registerHelper('currency', 'vStore\\Latte\\Helpers\\Shop::currency'); $template->baseUrl = rtrim($this->context->httpRequest->getUrl()->getBaseUrl(), '/'); $template->renderer = $this; return $template; }
/** * Renders HTML code for custom panel. * @return string * @see IDebugPanel::getPanel() */ public function getPanel() { $session = Environment::getSession('debug/RequestsPanel'); $logs = $session->logs; if ($this->response instanceof TextResponse) { unset($session->logs); $template = new FileTemplate(dirname(__FILE__) . '/bar.requests.panel.latte'); $template->registerFilter(new LatteFilter()); $template->registerHelper('plural', 'Helpers::plural'); $template->logs = $logs; $template->numberOfLogs = count($logs); return $template->__toString(); } }
/** * Renders HTML code for custom panel. * @return string * @see IDebugPanel::getPanel() */ public function getPanel() { if ($this->response instanceof \Nette\Application\Responses\ForwardResponse || $this->response instanceof \Nette\Application\Responses\RedirectResponse) { return ''; } /** @var Template */ $template = new FileTemplate(); $template->setFile(dirname(__FILE__) . "/bar.latte"); $template->registerFilter(new Engine()); $template->presenter = $template->control = $template->rootComponent = Environment::getApplication()->getPresenter(); if ($template->presenter === NULL) { return NULL; } $template->wrap = static::$wrap; $template->cache = static::$cache ? Environment::getCache('Debugger.Panels.ComponentTree') : NULL; $template->dumps = static::$dumps; $template->parametersOpen = static::$parametersOpen; $template->presenterOpen = static::$presenterOpen; $template->showSources = static::$showSources; $template->omittedVariables = static::$omittedTemplateVariables; $template->registerHelper('parametersInfo', callback($this, 'getParametersInfo')); $template->registerHelper('editlink', callback($this, 'buildEditorLink')); $template->registerHelper('highlight', callback($this, 'highlight')); $template->registerHelper('filterMethods', callback($this, 'filterMethods')); $template->registerHelper('renderedTemplates', callback($this, 'getRenderedTemplates')); $template->registerHelper('isPersistent', callback($this, 'isPersistent')); $template->registerHelperLoader('Nette\\Templating\\Helpers::loader'); ob_start(); $template->render(); return ob_get_clean(); }