Exemplo n.º 1
0
 function testGenerateExpression()
 {
     $code_writer = new WactCodeWriter();
     $component = new WactCompilerTag(null, null, null);
     $property = new WactCompilerProperty();
     $component->registerProperty('hello', $property);
     $attribute = new WactAttributeExpressionFragment('hello', $component, $this->filter_dictionary);
     $attribute->generatePreStatement($code_writer);
     $attribute->generateExpression($code_writer);
     $attribute->generatePostStatement($code_writer);
     $this->assertEqual($code_writer->renderCode(), '');
 }
Exemplo n.º 2
0
 function generateTagContent($code)
 {
     $parent = $this->findParentByClass('WactPagerNavigatorTag');
     $code->writePhp('if (!' . $parent->getComponentRefCode() . '->hasPrev()) {');
     parent::generateTagContent($code);
     $code->writePhp('}');
 }
Exemplo n.º 3
0
 function generateTagContent($code)
 {
     $name = $this->getAttribute('name');
     $code->writePhp('if ("' . $name . '" == lmbToolkit :: instance()->getLocale()) {');
     parent::generateTagContent($code);
     $code->writePhp('}');
 }
Exemplo n.º 4
0
 function generateTagContent($code)
 {
     $code->writePHP('if (');
     $code->writePHP($this->attributeNodes['exp']->generateExpression($code));
     $code->writePHP('){');
     parent::generateTagContent($code);
     $code->writePHP('}');
 }
Exemplo n.º 5
0
 function generateTagContent($code)
 {
     $parent = $this->findParentByClass('WactPagerNavigatorTag');
     $code->writePhp('if (' . $parent->getComponentRefCode() . '->hasPrev()) {');
     $code->writePhp($this->getDataSourceRefCode() . '["href"] = ' . $parent->getComponentRefCode() . '->getPageUri( ' . $parent->getComponentRefCode() . '->getDisplayedPage() - 1 );' . "\n");
     parent::generateTagContent($code);
     $code->writePhp('}' . "\n");
 }
Exemplo n.º 6
0
 function generateTagContent($code)
 {
     $parent = $this->findParentByClass('WactPagerNavigatorTag');
     $code->writePhp('if (!' . $parent->getComponentRefCode() . '->isDisplayedSection()) {');
     $code->writePhp($this->getDataSourceRefCode() . '["href"] = ' . $parent->getComponentRefCode() . '->getSectionUri();' . "\n");
     $code->writePhp($this->getDataSourceRefCode() . '["number_begin"] = ' . $parent->getComponentRefCode() . '->getSectionBeginPage();' . "\n");
     $code->writePhp($this->getDataSourceRefCode() . '["number_end"] = ' . $parent->getComponentRefCode() . '->getSectionEndPage();' . "\n");
     parent::generateTagContent($code);
     $code->writePhp('}');
 }
Exemplo n.º 7
0
 function generateTagContent($code)
 {
     $tempvar = $code->getTempVariable();
     $code->writePHP('$' . $tempvar . ' = ');
     $this->attributeNodes['for']->generateExpression($code);
     $code->writePHP(';');
     $code->writePHP('if (is_scalar($' . $tempvar . ' )) $' . $tempvar . '= trim($' . $tempvar . ');');
     $code->writePHP('if (!empty($' . $tempvar . ')){');
     parent::generateTagContent($code);
     $code->writePHP('}');
 }
Exemplo n.º 8
0
 /**
  * Calls the parent getComponentRefCode() method and writes it to the
  * compiled template, appending an addChild() method used to create
  * this component at runtime
  */
 function generateConstructor($code_writer)
 {
     $this->generateUniqueId($code_writer);
     if ($this->runtimeIncludeFile) {
         $code_writer->registerInclude($this->runtimeIncludeFile);
     }
     $code_writer->writePHP($this->unique_var . ' = new ' . $this->runtimeComponentName . '(\'' . $this->getServerId() . '\');' . "\n");
     $code_writer->writePHP($this->getComponentRefCode() . ' = ' . $this->unique_var . ';' . "\n");
     $code_writer->writePHP($this->parent->getComponentRefCode() . '->addChild(' . $this->unique_var . ');' . "\n");
     parent::generateConstructor($code_writer);
 }
Exemplo n.º 9
0
 function preParse()
 {
     if (!$this->hasAttribute('target') && !$this->hasAttribute('to')) {
         $this->raiseCompilerError('Required attribute not found', array('attribute' => 'target or to'));
     }
     if ($this->hasAttribute('target') && $this->hasAttribute('to')) {
         $this->raiseCompilerError('Both target and to attribute are not supported');
     }
     $this->_fillToAttributeFromTargetAttribute();
     return parent::preParse();
 }
Exemplo n.º 10
0
 function generateTagContent($code)
 {
     $counter = '$' . $code->getTempVariable();
     $value_attr = $this->attributeNodes['value'];
     if ($value_attr->isConstant()) {
         $value = $value_attr->getValue();
         $code->writePhp('for(' . $counter . '=0;' . $counter . ' < ' . $value . '; ' . $counter . '++){');
     } else {
         $value = '$' . $code->getTempVariable();
         $code->writePHP($value . ' = ');
         $value_attr->generateExpression($code);
         $code->writePHP(';');
         $code->writePhp('for(' . $counter . '=0;' . $counter . ' < ' . $value . '; ' . $counter . '++){');
     }
     parent::generateTagContent($code);
     $code->writePhp('}');
 }
Exemplo n.º 11
0
 function postGenerate($code_writer)
 {
     $contents = $code_writer->getTempVariable();
     $hexencode = $code_writer->getTempVariable();
     $arr = $code_writer->getTempVariable();
     $code_writer->writePHP('function ' . $hexencode . '($char) {');
     $code_writer->writePHP('  return \'%\' . bin2hex($char);');
     $code_writer->writePHP('}');
     $code_writer->writePHP('$' . $contents . ' = ob_get_contents();');
     $code_writer->writePHP('ob_end_clean();');
     $code_writer->writePHP('$' . $arr . ' = str_split($' . $contents . ');');
     $code_writer->writePHP('if (is_array($' . $arr . ')) {');
     $code_writer->writePHP('  $' . $contents . ' = implode("", array_map("' . $hexencode . '", $' . $arr . '));');
     $code_writer->writePHP('}');
     $code_writer->writeHTML('<script type="text/javascript" language="javascript">document.write(unescape(\'');
     $code_writer->writePHP('echo $' . $contents . ';');
     $code_writer->writeHTML('\'))</script>');
     parent::postGenerate($code_writer);
 }
Exemplo n.º 12
0
 function generateTagContent($code)
 {
     $ratio_var = $code->getTempVarRef();
     $code->writePHP($ratio_var . ' = ');
     $this->generateRatioAttributeValue($code);
     $code->writePhp(";\n");
     $ListList = $this->findParentByClass('WactListListTag');
     $code->writePhp('if (!' . $ListList->getComponentRefCode($code) . '->valid()){' . "\n");
     $count_var = $code->getTempVarRef();
     $items_left_var = $code->getTempVarRef();
     $code->writePhp($count_var . ' = ' . $ListList->getComponentRefCode($code) . '->countPaginated();');
     $code->writePhp("if ({$count_var}/{$ratio_var} > 1) \n");
     $code->writePhp($items_left_var . " = ceil({$count_var}/{$ratio_var})*{$ratio_var} - {$count_var}; \n");
     $code->writePhp("else \n");
     $code->writePhp($items_left_var . " = 0;\n");
     $code->writePhp("if ({$items_left_var}){\n");
     $code->writePhp($this->getDatasource()->getComponentRefCode() . "->set('" . $this->var_name . "', {$items_left_var});");
     parent::generateTagContent($code);
     $code->writePhp('}' . "\n");
     $code->writePhp('}' . "\n");
 }
Exemplo n.º 13
0
 /**
  * @param WactCodeWriter
  */
 function generateChildren($code_writer)
 {
     parent::generateChildren($code_writer);
     if (NULL !== ($context = $this->getAttribute('context'))) {
         $contexts = array('root', 'parent', 'current');
         if (!in_array($context, $contexts)) {
             $context = 'current';
         }
     } else {
         $context = 'current';
     }
     if (NULL !== ($output = $this->getAttribute('output'))) {
         $outputs = array('print_r', 'var_dump');
         if (!in_array($output, $outputs)) {
             $output = 'print_r';
         }
     } else {
         $output = 'print_r';
     }
     $code_writer->writeHTML('<div aligh="left"><hr /><h3>Begin ' . ucfirst($context) . ' DataSpace</h3><hr /></div>');
     switch ($context) {
         case 'root':
             $Context = $this->getRootDataSource();
             break;
         case 'parent':
             $Context = $this->getParentDataSource();
             break;
         default:
             $Context = $this->getDataSource();
             break;
     }
     $code_writer->writeHTML('<pre>');
     $code_writer->writePHP('if ( is_object(' . $Context->getComponentRefCode() . ') && method_exists (' . $Context->getComponentRefCode() . ',"export") ) {');
     $code_writer->writePHP($output . '(' . $Context->getComponentRefCode() . '->export());');
     $code_writer->writePHP('} else {');
     $code_writer->writeHTML('Dataspace unavailable');
     $code_writer->writePHP('}');
     $code_writer->writeHTML('</pre>');
     $code_writer->writeHTML('<div aligh="left"><hr /><h3>End ' . ucfirst($context) . ' DataSpace</h3><hr /></div>');
 }
Exemplo n.º 14
0
 /**
  * @param WactCompiler
  **/
 function preParse($compiler)
 {
     parent::preParse($compiler);
     $locator = $compiler->getTemplateLocator();
     if (!($file = $this->getAttribute('file'))) {
         $this->raiseRequiredAttributeError($file);
     }
     $source_file = $locator->locateSourceTemplate($file);
     if (empty($source_file)) {
         $this->raiseCompilerError('Template source file not found', array('file_name' => $file));
     }
     if ($this->getBoolAttribute('literal')) {
         $this->addChild(new WactTextNode(null, $locator->readTemplateFile($source_file)));
     } elseif ($this->getBoolAttribute('source')) {
         $this->addChild(new WactTextNode(null, highlight_string($locator->readTemplateFile($source_file), true)));
     } else {
         if ($this->getBoolAttribute('in_datasource')) {
             $this->_createNewDatasourceTag($compiler);
             $compiler->parseTemplate($file, $this->new_datasource_tag);
         } else {
             $compiler->parseTemplate($file, $this);
         }
     }
 }
Exemplo n.º 15
0
 function testRestrictSelfNesting()
 {
     $tag_info = new WactTagInfo('CompilerTag', 'whatever');
     $tag_info->setRestrictSelfNesting(true);
     $component = new WactCompilerTag(new WactSourceLocation('my_file', 13), 'whatever', $tag_info);
     $parent = new WactCompilerTag(new WactSourceLocation('my_file', 10), 'whatEver', $tag_info);
     $component->parent = $parent;
     try {
         $component->preParse();
         $this->assertTrue(false);
     } catch (WactException $e) {
         $this->assertWantedPattern('/Tag cannot be nested within the same tag/', $e->getMessage());
         $this->assertEqual($e->getParam('same_tag_file'), 'my_file');
         $this->assertEqual($e->getParam('same_tag_line'), 10);
     }
 }
Exemplo n.º 16
0
 function generateNow($code_writer)
 {
     return parent::generate($code_writer);
 }
Exemplo n.º 17
0
 function generateTagContent($code)
 {
     $code->writePhp('if (' . $this->findParentByClass('WactPagerNavigatorTag')->getComponentRefCode() . '->isFirst()) {');
     parent::generateTagContent($code);
     $code->writePhp('}');
 }