Exemple #1
0
 function testCompileSimpleBlock()
 {
     $block = '<li>{blocktrans}This email <em>{$email}</em> is already registered. If you forgot your password, you can recover it easily.{/blocktrans}</li>';
     $compiler = new Pluf_Template_Compiler('dummy', array(), false);
     $compiler->templateContent = $block;
     $this->assertEqual('<li><?php ob_start(); ?>This email <em>%%email%%</em> is already registered. If you forgot your password, you can recover it easily.<?php $_b_t_s=ob_get_contents(); ob_end_clean(); echo(Pluf_Translation::sprintf(__($_b_t_s), array(\'email\' => Pluf_Template_safeEcho($t->_vars->email, false)))); ?></li>', $compiler->getCompiledTemplate());
 }
 public function testCompileMultiFolders()
 {
     $folders = array(dirname(__FILE__) . '/tpl1', dirname(__FILE__) . '/tpl2');
     $compiler = new Pluf_Template_Compiler('tpl-extends.html', $folders);
     $compiled = file_get_contents(dirname(__FILE__) . '/tpl-extends.compiled.html');
     $this->assertEquals($compiled, $compiler->getCompiledTemplate() . "\n");
 }
 public function testCompile()
 {
     return '';
     $compiler = new Pluf_Template_Compiler('dummy', array(), false);
     $compiler->templateContent = '{blocktrans $count, $toto}We have one {$toto} element.{plural}We have {$counter} {$toto} elements.{/blocktrans}';
     $this->assertEquals('<?php $_b_t_c=$t->_vars[\'count\']; ob_start(); ?>We have one %2$s element.<?php $_b_t_s=ob_get_contents(); ob_end_clean(); ob_start(); ?>We have %1$d %2$s elements.<?php $_b_t_p=ob_get_contents(); ob_end_clean(); echo(sprintf(_n($_b_t_s, $_b_t_p, $_b_t_c), $_b_t_c, Pluf_Template_safeEcho($t->_vars[\'toto\'], false))); ?>', $compiler->getCompiledTemplate());
 }
Exemple #4
0
 /**
  * Constructor.
  *
  * If the folder name is not provided, it will default to
  * Pluf::f('template_folders')
  * If the cache folder name is not provided, it will default to
  * Pluf::f('tmp_folder')
  *
  * @param string Template name.
  * @param string Template folder paths (null)
  * @param string Cache folder name (null)
  */
 function __construct($template, $folders = null, $cache = null)
 {
     $this->tpl = $template;
     if (null == $folders) {
         $this->folders = Pluf::f('template_folders');
     } else {
         $this->folders = $folders;
     }
     if (null == $cache) {
         $this->cache = Pluf::f('tmp_folder');
     } else {
         $this->cache = $cache;
     }
     if (defined('IN_UNIT_TESTS')) {
         if (!isset($GLOBALS['_PX_tests_templates'])) {
             $GLOBALS['_PX_tests_templates'] = array();
         }
     }
     $this->compiled_template = $this->getCompiledTemplateName();
     $b = $this->compiled_template[1];
     $this->class = 'Pluf_Template_' . $b;
     $this->compiled_template = $this->compiled_template[0];
     if (!class_exists($this->class, false)) {
         if (!file_exists($this->compiled_template) or Pluf::f('debug')) {
             $compiler = new Pluf_Template_Compiler($this->tpl, $this->folders);
             $this->template_content = $compiler->getCompiledTemplate();
             $this->write($b);
         }
         include $this->compiled_template;
     }
 }
    public function testCompileSimpleAssignInLoop()
    {
        $compiler = new Pluf_Template_Compiler('dummy', array(), false);
        $compiler->templateContent = '{assign $counter = 1}
{foreach $lines as $line}
{$counter}
{assign $counter = $counter+1}
{/foreach}';
        $this->assertEquals('<?php $t->_vars[\'counter\'] = 1; ?>

<?php foreach ($t->_vars[\'lines\'] as $t->_vars[\'line\']): ?>

<?php Pluf_Template_safeEcho($t->_vars[\'counter\']); ?>

<?php $t->_vars[\'counter\'] = $t->_vars[\'counter\']+1; ?>

<?php endforeach; ?>', $compiler->getCompiledTemplate());
    }