Ejemplo n.º 1
0
 /**
  * Replace <ktml:content> with the view content
  *
  * @param string $text  The text to parse
  * @param TemplateInterface $template A template object
  * @return void
  */
 public function filter(&$text, TemplateInterface $template)
 {
     $matches = array();
     if (preg_match_all('#<ktml:content(.*)>#siU', $text, $matches)) {
         foreach ($matches[0] as $key => $match) {
             $attributes = array_merge($this->_attributes, $this->parseAttributes($matches[1][$key]));
             $content = $template->content();
             if (!empty($content)) {
                 //If attributes are set but no decorator set it to <div>
                 $element = null;
                 if (!empty($attributes)) {
                     if (isset($attributes['decorator'])) {
                         $element = trim(strtolower($attributes['decorator']));
                         unset($attributes['decorator']);
                     } else {
                         $element = 'div';
                     }
                 }
                 //Do not decorate if no element is defined
                 if ($element) {
                     $attribs = '';
                     if (!empty($attributes)) {
                         $attribs = ' ' . $this->buildAttributes($attributes);
                     }
                     $content = sprintf('<' . $element . '%s>%s</' . $element . '>', $attribs, PHP_EOL . $content . PHP_EOL);
                 }
             }
             //Remove the tags
             $text = str_replace($match, $content, $text);
         }
     }
 }
Ejemplo n.º 2
0
 public function appendChild(TemplateInterface $template)
 {
     $ref = $this->_getChildViewContainer();
     if ($ref) {
         $ref->append($template->markup());
         return $ref;
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Replace <ktml:template:[format]></ktml:template:[format]> and rendered the content
  *
  * @param string $text  The text to parse
  * @param TemplateInterface $template A template object.
  * @return void
  */
 public function filter(&$text, TemplateInterface $template)
 {
     $factory = $this->getObject('template.engine.factory');
     $types = $factory->getFileTypes();
     $types = implode('|', $types);
     $matches = array();
     if (preg_match_all('#<ktml:template:(' . $types . ')>(.*)<\\/ktml:template:(' . $types . ')>#siU', $text, $matches)) {
         foreach ($matches[0] as $key => $match) {
             $data = $template->getData();
             $html = $factory->createEngine($matches[1][$key], array('functions' => $template->getFunctions()))->render($matches[2][$key], $data);
             $text = str_replace($match, $html, $text);
         }
     }
 }
 /**
  * 
  * @param TemplateInterface $template
  * @param array $nameValueMap
  * @return string
  */
 public function renderTemplate(TemplateInterface $template, array $nameValueMap = [])
 {
     try {
         $this->template = $template->withNameValueMap($nameValueMap);
         while (true) {
             $template = $this->template;
             $this->template = null;
             $this->rendered = $template->render($this);
             if ($this->template === null) {
                 break;
             }
         }
         return $this->rendered;
     } finally {
         $this->rendered = null;
         $this->template = null;
     }
 }
Ejemplo n.º 5
0
 /**
  * Add the action if left empty
  *
  * @param string $text       Template text
  * @param TemplateInterface $template A template object
  * @return TemplateFilterForm
  */
 protected function _addAction(&$text, TemplateInterface $template)
 {
     // All: Add the action if left empty
     if (preg_match_all('#<\\s*form.*?action=""#sim', $text, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             $str = str_replace('action=""', 'action="' . $template->route() . '"', $match[0]);
             $text = str_replace($match[0], $str, $text);
         }
     }
     return $this;
 }
Ejemplo n.º 6
0
 public function addCollectionTemplate(TemplateInterface $template)
 {
     $this->templates[$template->getName()] = $template;
 }
Ejemplo n.º 7
0
 /**
  * Render
  */
 public function __destruct()
 {
     $this->template->render();
 }
 /**
  * @param TemplateInterface $template
  * @param string $filePath
  * @return bool
  */
 public function dump(TemplateInterface $template, $filePath)
 {
     $wasSuccessful = file_put_contents($filePath, $template->render()) !== false;
     return $wasSuccessful;
 }
 /**
  * Init Template
  *
  * @param array $options
  */
 protected function initTemplate(array $options = array())
 {
     $options['path_template'] = isset($options['path_template']) ? $options['path_template'] : 'templates';
     $options['path_template'] = YOURLS_PLUGINDIR . '/' . static::APP_NAMESPACE . '/' . $options['path_template'];
     $options['path_cache'] = isset($options['path_cache']) ? $options['path_cache'] : 'cache/twig';
     $options['path_cache'] = YOURLS_ABSPATH . '/' . $options['path_cache'];
     $options['namespace'] = static::APP_NAMESPACE;
     $this->_template = Template::factory('twig');
     $this->_template->init($options);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function setPath($path)
 {
     $this->template->setPath($path);
 }