/**
  * Render the templates
  *
  * @param \Nette\Forms\Form $form
  * @param string $mode
  *
  * @return void
  */
 public function render(Nette\Forms\Form $form, $mode = NULL)
 {
     if ($this->form !== $form) {
         $this->form = $form;
         // translators
         if ($translator = $this->form->getTranslator()) {
             $this->template->setTranslator($translator);
         }
         // controls placeholders & classes
         foreach ($this->form->getControls() as $control) {
             $this->prepareControl($control);
         }
         $formEl = $form->getElementPrototype();
         if (!$formEl->class || stripos('form-', (string) $formEl->class) === FALSE) {
             $formEl->addClass('form-horizontal');
         }
     }
     $this->template->form = $this->form;
     $this->template->_form = $this->form;
     $this->template->renderer = $this;
     if ($mode === NULL) {
         $this->template->render();
     } elseif ($mode === 'begin') {
         FormMacros::renderFormBegin($this->form, array());
     } elseif ($mode === 'end') {
         FormMacros::renderFormEnd($this->form);
     } else {
         $this->template->setFile(__DIR__ . '/@parts.latte');
         $this->template->mode = $mode;
         $this->template->render();
         $this->template->setFile(__DIR__ . '/@form.latte');
     }
 }
Exemplo n.º 2
0
 /**
  * Add gettext helpers to template.
  *
  * @param Template
  * @param ITranslator
  */
 public static function registerHelpers(Template $template, ITranslator $translator)
 {
     $template->registerHelper('gettext', array($translator, 'gettext'));
     $template->registerHelper('ngettext', array($translator, 'ngettext'));
     $template->registerHelper('pgettext', array($translator, 'pgettext'));
     $template->registerHelper('npgettext', array($translator, 'npgettext'));
 }
Exemplo n.º 3
0
 public function prepareFilters(Template $template)
 {
     $this->latte = $this->latteFactory->invoke();
     foreach ($this->macroFactories as $factory) {
         $this->container->{Container::getMethodName($factory, FALSE)}($this->latte->getCompiler());
     }
     $template->registerFilter($this->latte);
 }
 /**
  * Render the templates.
  * @param Form    $form
  * @param string  $mode
  * @param array   $args
  */
 public function render(Form $form, $mode = NULL, $args = NULL)
 {
     if ($this->template === NULL) {
         if ($presenter = $form->lookup('Nette\\Application\\UI\\Presenter', FALSE)) {
             /** @var \Nette\Application\UI\Presenter $presenter */
             $this->template = clone $presenter->getTemplate();
         } else {
             $this->template = new FileTemplate();
             $this->template->registerFilter(new \Nette\Latte\Engine());
         }
     }
     if ($this->form !== $form) {
         $this->form = $form;
         // translators
         if ($translator = $this->form->getTranslator()) {
             $this->template->setTranslator($translator);
         }
         // controls placeholders & classes
         foreach ($this->form->getControls() as $control) {
             $this->prepareControl($control);
         }
         $formEl = $form->getElementPrototype();
         if (!($classes = self::getClasses($formEl)) || stripos($classes, 'form-') === FALSE) {
             //$formEl->addClass('form-horizontal');
         }
     } elseif ($mode === 'begin') {
         foreach ($this->form->getControls() as $control) {
             /** @var \Nette\Forms\Controls\BaseControl $control */
             $control->setOption('rendered', FALSE);
         }
     }
     $this->template->setFile(__DIR__ . '/@form.latte');
     $this->template->setParameters(array_fill_keys(array('control', '_control', 'presenter', '_presenter'), NULL) + array('_form' => $this->form, 'form' => $this->form, 'renderer' => $this));
     if ($mode === NULL) {
         if ($args) {
             $this->form->getElementPrototype()->addAttributes($args);
         }
         $this->template->render();
     } elseif ($mode === 'begin') {
         FormMacros::renderFormBegin($this->form, (array) $args);
     } elseif ($mode === 'end') {
         FormMacros::renderFormEnd($this->form);
     } else {
         $attrs = array('input' => array(), 'label' => array());
         foreach ((array) $args as $key => $val) {
             if (stripos($key, 'input-') === 0) {
                 $attrs['input'][substr($key, 6)] = $val;
             } elseif (stripos($key, 'label-') === 0) {
                 $attrs['label'][substr($key, 6)] = $val;
             }
         }
         $this->template->setFile(__DIR__ . '/@parts.latte');
         $this->template->mode = $mode;
         $this->template->attrs = (array) $attrs;
         $this->template->render();
     }
 }
Exemplo n.º 5
0
 private static function renderTemplateAsync(Template $tpl)
 {
     $partial = $tpl->__toString();
     // render, but component will provide only placeholders
     $ret = Flow::run(self::$components);
     $html = preg_replace_callback('/\\x01(\\d+)\\x02/', function ($m) use($ret) {
         return $ret[$m[1]];
     }, $partial);
     return $html;
 }
Exemplo n.º 6
0
 public function createNewTemplate($fileName = NULL)
 {
     $template = NULL;
     if ($fileName !== NULL) {
         $template = new \Nette\Templating\FileTemplate();
         $template->setFile($fileName);
     } else {
         $template = new Nette\Templating\Template();
     }
     $template->setTranslator($this->getPresenter()->context->translator);
     $template->registerFilter(new \Nette\Latte\Engine());
     $template->registerHelperLoader('Nette\\Templating\\Helpers::loader');
     //$baseUrl = rtrim($this->presenter->context->httpRequest->getUrl()->getBaseUrl(), '/');
     $template->basePath = $this->getBasePath();
     $template->themePath = $template->basePath . '/' . strtolower($this->presenter->pageManagerService->getCurrentModule());
     $template->_presenter = $this->presenter;
     $template->_control = $this;
     return $template;
 }
 /**
  * Render the templates
  *
  * @param \Nette\Forms\Form $form
  *
  * @return void
  */
 public function render(Nette\Forms\Form $form)
 {
     if ($this->form !== $form) {
         $this->form = $form;
         // translators
         if ($translator = $this->form->getTranslator()) {
             $this->template->setTranslator($translator);
         }
         // controls placeholders & classes
         foreach ($this->form->getControls() as $control) {
             $this->prepareControl($control);
         }
         $formEl = $form->getElementPrototype();
         if (stripos('form-', $formEl->class) === FALSE) {
             $formEl->addClass('form-horizontal');
         }
     }
     $this->template->form = $this->form;
     $this->template->renderer = $this;
     $this->template->render();
 }
Exemplo n.º 8
0
 /**
  * Render the templates
  *
  * @param \Nette\Forms\Form $form
  * @return void
  */
 public function render(\Nette\Forms\Form $form)
 {
     if ($form === $this->form) {
         // don't forget for second run, @hosiplan! ;)
         foreach ($this->form->getControls() as $control) {
             $control->setOption('rendered', false);
         }
         echo $this->template;
         return;
     }
     // Store the current form instance
     $this->form = $form;
     // Translator available?
     if ($translator = $form->getTranslator()) {
         // intentional =
         $this->template->setTranslator($translator);
     }
     // Pre-proccess form
     $errors = $form->getErrors();
     foreach ($form->getControls() as $control) {
         $control->setOption('rendered', false);
         if (!$control->getOption('blockname', false)) {
             $ex = explode('\\', get_class($control));
             $control->setOption('blockname', end($ex));
         }
         if ($this->errorsAtInputs) {
             $errors = array_diff($errors, $control->errors);
         }
     }
     // Assign to template
     $this->template->form = $form;
     $this->template->errors = $errors;
     $this->template->renderer = $this;
     $this->template->errorsAtInputs = $this->errorsAtInputs;
     // And echo the output
     echo $this->template;
 }
 /**
  * @param Latte\Template|\Nette\Bridges\ApplicationLatte\Template|\Nette\Templating\Template $template
  * @param ITranslator $translator
  */
 private static function overrideTemplateTranslator($template, ITranslator $translator)
 {
     if ($template instanceof Latte\Template) {
         $template->getEngine()->addFilter('translate', array(new TemplateHelpers($translator), 'translate'));
     } elseif ($template instanceof \Nette\Bridges\ApplicationLatte\Template) {
         $template->getLatte()->addFilter('translate', array(new TemplateHelpers($translator), 'translate'));
     } elseif ($template instanceof \Nette\Templating\Template) {
         $template->registerHelper('translate', array(new TemplateHelpers($translator), 'translate'));
     }
     return $translator;
 }
 /**
  * Render the templates
  *
  * @param \Nette\Forms\Form $form
  * @param string $mode
  * @param array $args
  * @return void
  */
 public function render(Nette\Forms\Form $form, $mode = NULL, $args = NULL)
 {
     if ($this->template === NULL) {
         if ($presenter = $form->lookup('Nette\\Application\\UI\\Presenter', FALSE)) {
             /** @var \Nette\Application\UI\Presenter $presenter */
             $this->template = clone $presenter->getTemplate();
         } else {
             $this->template = new Nette\Bridges\ApplicationLatte\Template(new Nette\Latte\Engine());
         }
     }
     if ($this->form !== $form) {
         $this->form = $form;
         // translators
         if ($translator = $this->form->getTranslator()) {
             $this->template->setTranslator($translator);
         }
         // controls placeholders & classes
         foreach ($this->form->getControls() as $control) {
             $this->prepareControl($control);
         }
         $formEl = $form->getElementPrototype();
         if (!($classes = self::getClasses($formEl)) || stripos($classes, 'form-') === FALSE) {
             $this->horizontalMode = $this->mode === self::MODE_HORIZONTAL;
             if ($this->mode !== self::MODE_NO_CLASS) {
                 $formEl->addClass($this->mode);
             }
         }
     } elseif ($mode === 'begin') {
         foreach ($this->form->getControls() as $control) {
             /** @var \Nette\Forms\Controls\BaseControl $control */
             $control->setOption('rendered', FALSE);
         }
     }
     $this->template->setFile(__DIR__ . '/@form.latte');
     $this->template->setParameters(array_fill_keys(array('control', '_control', 'presenter', '_presenter'), NULL) + array('_form' => $this->form, 'form' => $this->form, 'renderer' => $this));
     if ($this->horizontalMode) {
         $this->template->labelCols = $this->labelColumns;
         $this->template->inputCols = $this->inputColumns;
         $this->template->labelClass = $this->columnClassPrefix . $this->labelColumns;
         $this->template->inputClass = $this->columnClassPrefix . $this->inputColumns;
         $this->template->skipClass = $this->columnClassPrefix . 'offset-' . $this->labelColumns;
     }
     if ($mode === NULL) {
         if ($args) {
             $this->form->getElementPrototype()->addAttributes($args);
         }
         $this->template->render();
     } elseif ($mode === 'begin') {
         FormMacros::renderFormBegin($this->form, (array) $args);
     } elseif ($mode === 'end') {
         FormMacros::renderFormEnd($this->form);
     } else {
         $attrs = array('input' => array(), 'label' => array(), 'pair' => array(), 'pair-class' => '');
         foreach ((array) $args as $key => $val) {
             if (stripos($key, 'input-') === 0) {
                 $attrs['input'][substr($key, 6)] = $val;
             } elseif (stripos($key, 'label-') === 0) {
                 $attrs['label'][substr($key, 6)] = $val;
             } elseif ($key === 'class') {
                 $attrs['pair-class'] = $val;
             } else {
                 $attrs['pair'][$key] = $val;
             }
         }
         if ($this->horizontalMode) {
             if (isset($attrs['label']['class'])) {
                 $attrs['label']['class'] .= ' ' . $this->columnClassPrefix . $this->labelColumns;
             } else {
                 $attrs['label']['class'] = $this->columnClassPrefix . $this->labelColumns;
             }
         }
         $this->template->setFile(__DIR__ . '/@parts.latte');
         $this->template->mode = $mode;
         $this->template->attrs = (array) $attrs;
         $this->template->render();
     }
 }
Exemplo n.º 11
0
 public function render()
 {
     $this->template->setFile(dirname(__FILE__) . '/fb.latte');
     $this->template->render();
 }
Exemplo n.º 12
0
 private function _avelancheTransform($text, $filterParams = NULL, $templateParams = NULL)
 {
     //dump($filterParams);
     $_temp = $text;
     $hash = NULL;
     $oldHash = NULL;
     for ($i = 1; $i <= 50; $i++) {
         $template = new \Nette\Templating\Template();
         $template->setTranslator($this->presenter->context->translator);
         $template->setSource($_temp);
         $template->add('_presenter', $this->presenter);
         $template->add('_control', $this->presenter);
         $template->add('_page', $this);
         if ($templateParams !== NULL) {
             foreach ($templateParams as $k => $v) {
                 $template->add($k, $v);
             }
         }
         $template->onPrepareFilters[] = function ($template) use($filterParams) {
             $template->registerFilter(new Bubo\Filters\CMSFilter($filterParams));
         };
         $template->onPrepareFilters[] = function ($template) {
             $template->registerFilter(new \Nette\Latte\Engine());
         };
         //$template->setCacheStorage(new \Nette\Caching\Storages\PhpFileStorage(TEMP_DIR.'/cache'));
         $_temp = $template->__toString();
         if (($hash = sha1($_temp)) == $oldHash) {
             break;
         }
         $oldHash = $hash;
     }
     return $_temp;
 }
Exemplo n.º 13
0
 /**
  * create helper to template
  */
 public function registerAsHelper(Template $template)
 {
     $template->registerHelper('currency', callback($this, 'format'));
     $template->registerHelper('currencyTo', callback($this, 'formatTo'));
     $template->bank = $this;
 }
Exemplo n.º 14
0
 /**
  * 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)).\'"\'');
 }
 /**
  * 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 = new \Nette\Latte\Macros\MacroSet($latte->getCompiler());
     $set->addMacro('src', NULL, NULL, 'echo \'src="\'.\\Nette\\Templating\\Helpers::dataStream(file_get_contents(%node.word)).\'"\'');
     $set->addMacro('stylesheet', 'echo \'<style type="text/css">\'.file_get_contents(%node.word).\'</style>\'');
     if (class_exists('Tracy\\Dumper')) {
         $dumperMethod = '\\Tracy\\Dumper::toHtml';
     } else {
         $dumperMethod = '\\Nette\\Diagnostics\\Helpers::clickableDump';
     }
     $set->addMacro('clickableDump', 'echo ' . $dumperMethod . '(%node.word)');
 }
Exemplo n.º 16
0
 /**
  * Prepares Latte macros
  *
  * @param  Nette\Latte\Compiler
  * @return void
  */
 protected function lattePrepareMacros(Nette\Latte\Compiler $compiler, Nette\Templating\Template $template)
 {
     Nette\Latte\Macros\CoreMacros::install($compiler);
     $compiler->addMacro('cache', new Nette\Latte\Macros\CacheMacro($compiler));
     // Must be after CoreMacros (overrides {_'xxx'})
     vBuilder\Latte\Macros\TranslationMacros::install($compiler);
     // Must be before UIMacros
     vBuilder\Latte\Macros\SystemMacros::install($compiler);
     // Auto-extend for templates
     $autoExtend = NULL;
     if ($template instanceof Nette\Templating\FileTemplate && $template->getFile() != "" && $template->getFile() != $this->getDefaultTemplateFile() && file_exists($this->getDefaultTemplateFile())) {
         // If the basename is same but the dir differs
         if (preg_match('#^(.*?)([^/]+)$#', $template->getFile(), $mCurrent) && preg_match('#^(.*?)([^/]+)$#', $this->getDefaultTemplateFile(), $mDefault)) {
             if ($mCurrent[2] == $mDefault[2]) {
                 $autoExtend = $this->getDefaultTemplateFile();
             }
         }
     }
     if ($autoExtend) {
         vBuilder\Latte\Macros\UIMacros::installWithAutoExtend($compiler, $autoExtend);
     } else {
         vBuilder\Latte\Macros\UIMacros::install($compiler);
     }
     Nette\Latte\Macros\FormMacros::install($compiler);
     vBuilder\Latte\Macros\RegionMacros::install($compiler);
 }