Esempio n. 1
0
 public function __construct()
 {
     $this->parser = new Parser();
     Macros\CoreMacros::install($this->parser);
     $this->parser->addMacro('cache', new Macros\CacheMacro($this->parser));
     Macros\UIMacros::install($this->parser);
     Macros\FormMacros::install($this->parser);
 }
Esempio n. 2
0
 public function __construct()
 {
     $this->parser = new Parser();
     $this->compiler = new Compiler();
     $this->compiler->defaultContentType = Compiler::CONTENT_XHTML;
     CoreMacros::install($this->compiler);
     $this->compiler->addMacro('cache', new GlobalCacheMacro($this->compiler));
     FormMacros::install($this->compiler);
 }
Esempio n. 3
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);
     vBuilder\Latte\Macros\UIMacros::install($compiler);
     Nette\Latte\Macros\FormMacros::install($compiler);
     vBuilder\Latte\Macros\RegionMacros::install($compiler);
 }
Esempio n. 4
0
 /**
  * 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 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();
     }
 }
 /**
  * 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');
     }
 }
Esempio n. 6
0
 /**
  * @param Form $form
  * @param array $args
  */
 private static function renderFormBegin(Form $form, array $args)
 {
     if ($form->getRenderer() instanceof BootstrapRenderer) {
         $form->render('begin', $args);
     } else {
         Latte\Macros\FormMacros::renderFormBegin($form, $args);
     }
 }
Esempio n. 7
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);
 }