示例#1
0
 public function enterTagAttributes(Tag $node)
 {
     $this->attrs = array();
     $this->tag = $node;
     // Do not attempt to merge attributes if any attribute
     // name cannot be guessed at compile time.
     //
     // Else it may change the output (e.g. the unknown attribute
     // name could be 'class')
     foreach ($node->getAttributes() as $attr) {
         if (null === $this->getString($attr->getName())) {
             return false;
         }
     }
 }
 public function enterTagAttributes(Tag $node)
 {
     $hasDynAttr = false;
     foreach ($node->getAttributes() as $attr) {
         $nameNode = $attr->getName();
         $valueNode = $attr->getValue();
         if ($attr instanceof TagAttributeList) {
             $hasDynAttr = true;
             break;
         }
         if ($nameNode && (!$nameNode->isConst() || !$valueNode || !$valueNode->isConst())) {
             $hasDynAttr = true;
             break;
         }
     }
     if (!$hasDynAttr) {
         return;
     }
     $this->renderDynamicAttributes($node);
     return false;
 }
 protected function renderDynamicAttributes(Tag $tag)
 {
     $list = array();
     $n = 0;
     $this->raw(' <?php echo MtHaml\\Runtime::renderAttributes(array(');
     $this->setEchoMode(false);
     foreach ($tag->getAttributes() as $attr) {
         if (0 !== $n) {
             $this->raw(', ');
         }
         if ($attr instanceof TagAttributeInterpolation) {
             $this->raw('MtHaml\\Runtime\\AttributeInterpolation::create(');
             $attr->getValue()->accept($this);
             $this->raw(')');
         } else {
             if ($attr instanceof TagAttributeList) {
                 $this->raw('MtHaml\\Runtime\\AttributeList::create(');
                 $attr->getValue()->accept($this);
                 $this->raw(')');
             } else {
                 $this->raw('array(');
                 $attr->getName()->accept($this);
                 $this->raw(', ');
                 if ($value = $attr->getValue()) {
                     $attr->getValue()->accept($this);
                 } else {
                     $this->raw('TRUE');
                 }
                 $this->raw(')');
             }
         }
         ++$n;
     }
     $this->raw(')');
     $this->setEchoMode(true);
     $this->raw(', ');
     $this->raw($this->stringLiteral($this->env->getOption('format')));
     $this->raw(', ');
     $this->raw($this->stringLiteral($this->charset));
     $this->raw('); ?>');
 }
示例#4
0
 protected function renderDynamicAttributes(Tag $tag)
 {
     $this->raw(' ');
     foreach ($tag->getAttributes() as $attr) {
         $this->addDebugInfos($attr);
         break;
     }
     $this->raw('{{ mthaml_attributes([');
     $this->setEchoMode(false);
     foreach (array_values($tag->getAttributes()) as $i => $attr) {
         if (0 !== $i) {
             $this->raw(', ');
         }
         if ($attr instanceof TagAttributeInterpolation) {
             $this->raw('mthaml_attribute_interpolation(');
             $attr->getValue()->accept($this);
             $this->raw(')');
         } elseif ($attr instanceof TagAttributeList) {
             $this->raw('mthaml_attribute_list(');
             $attr->getValue()->accept($this);
             $this->raw(')');
         } else {
             $this->raw('[');
             $attr->getName()->accept($this);
             $this->raw(', ');
             if ($attr->getValue()) {
                 $attr->getValue()->accept($this);
             } else {
                 $this->raw('true');
             }
             $this->raw(']');
         }
     }
     $this->raw(']');
     $this->setEchoMode(true);
     $this->raw(', ');
     $this->raw($this->stringLiteral($this->env->getOption('format')));
     $this->raw(', ');
     $this->raw($this->stringLiteral($this->charset));
     $this->raw($this->env->getOption('enable_escaper') && $this->env->getOption('escape_attrs') ? '' : ', false');
     $this->raw(')|raw }}');
 }