示例#1
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     $aAttrs = $aObject->attributes();
     if (!$aAttrs->has('rel')) {
         $aAttrs->set('rel', 'stylesheet');
     }
     if ($aAttrs->has('src') and !$aAttrs->has('href')) {
         $aAttrs->set('href', $aAttrs->string('src'));
     }
     if (strtolower($aAttrs->string('rel')) == 'stylesheet' and !$aAttrs->bool('ignore')) {
         $sHref = $aAttrs->get('href');
         $aDev->preprocessStream()->write("jc\\resrc\\HtmlResourcePool::singleton()->addRequire({$sHref},jc\\resrc\\HtmlResourcePool::RESRC_CSS) ;");
         // 清除后文中的空白字符
         ClearCompiler::clearAfterWhitespace($aObject);
     } else {
         $this->compileTag($aObject->headTag(), $aObjectContainer, $aDev, $aCompilerManager);
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         if ($aTailTag = $aObject->tailTag()) {
             $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
             $this->compileTag($aTailTag, $aObjectContainer, $aDev, $aCompilerManager);
         }
     }
 }
示例#2
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aAttrs = $aObject->attributes();
     $sType = strtolower($aAttrs->string('type'));
     if (in_array($sType, array('text/php', 'php'))) {
         foreach ($aObject->iterator() as $aChild) {
             if ($aChild instanceof AttributeValue) {
                 continue;
             }
             $aDev->write(ExpressionCompiler::compileExpression($aChild->source(), $aObjectContainer->variableDeclares(), false, true));
         }
     } else {
         if ($aAttrs->has('src') and !$aAttrs->bool('ignore')) {
             $sSrc = $aAttrs->get('src');
             $aDev->preprocessStream()->write("\\org\\jecat\\framework\\resrc\\HtmlResourcePool::singleton()->addRequire({$sSrc},\\org\\jecat\\framework\\resrc\\HtmlResourcePool::RESRC_JS) ;");
             // 清除后文中的空白字符
             ClearCompiler::clearAfterWhitespace($aObject);
         } else {
             parent::compile($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         }
     }
 }
示例#3
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     $aAttrs = $aObject->attributes();
     // 指定view名称
     if ($aAttrs->has('xpath')) {
         $sXpath = $aAttrs->get('xpath');
     } else {
         if ($aAttrs->has('name')) {
             $sXpath = $aAttrs->get('name');
         } else {
             $sXpath = null;
         }
     }
     if ($sXpath) {
         $arrViewXPaths = "array({$sXpath})";
         $bUseXpath = true;
     } else {
         $arrViewXPaths = 'null';
         $bUseXpath = false;
     }
     $sLayout = $aAttrs->string('layout') ?: ViewAssembler::layout_vertical;
     // model
     if ($aAttrs->has('mode')) {
         $nMode = ViewAssembler::filterModeToPriority($aAttrs->string('mode'));
     } else {
         $nMode = $bUseXpath ? ViewAssembler::hard : ViewAssembler::soft;
     }
     $nNodeViewId =& $aDev->properties(true)->getRef('node.view.id');
     if ($nNodeViewId === null) {
         $nNodeViewId = 0;
     } else {
         $nNodeViewId++;
     }
     $sViewAssemblyListId = "\$this->id().'-pos{$nNodeViewId}'";
     // 视图的预处理
     $aDev->preprocessStream()->write("\r\n// define view assembly list -------------------");
     $aDev->preprocessStream()->write("if( empty(\$this) or !(\$this instanceof jc\\mvc\\view\\IView) )");
     $aDev->preprocessStream()->write("{");
     $aDev->preprocessStream()->write("\tthrow new jc\\lang\\Exception('UI标签 <view> 必须用于视图类。') ;");
     $aDev->preprocessStream()->write("}");
     $aDev->preprocessStream()->write("jc\\mvc\\view\\ViewAssembler::singleton()->defineAssemblyList(\r\n\t\t{$sViewAssemblyListId}\r\n\t\t, '{$sLayout}'\r\n\t\t, array(\r\n\t\t\t'priority' => {$nMode},\r\n\t\t\t'xpaths' => {$arrViewXPaths},\r\n\t\t\t'view' => \$this ,\r\n\t\t)\r\n) ;");
     $aDev->write("\r\n// display views ");
     $sViewAssemblyListId = "\$aVariables->theView->id().'-pos{$nNodeViewId}'";
     $aDev->write("jc\\mvc\\view\\ViewAssembler::singleton()->displayAssemblyList({$sViewAssemblyListId},\$aDevice) ;");
     return;
 }