저자: Asmir Mustafic (goetas@gmail.com)
예제 #1
0
파일: EmbedNode.php 프로젝트: goetas/twital
 public function visit(\DOMElement $node, Compiler $context)
 {
     if ($node->hasAttribute("from-exp")) {
         $filename = $node->getAttribute("from-exp");
     } elseif ($node->hasAttribute("from")) {
         $filename = '"' . $node->getAttribute("from") . '"';
     } else {
         throw new Exception("The 'from' or 'from-exp' attribute is required");
     }
     // remove any non-element node
     foreach (iterator_to_array($node->childNodes) as $child) {
         if (!$child instanceof \DOMElement) {
             $child->parentNode->removeChild($child);
         }
     }
     $context->compileChilds($node);
     $code = "embed {$filename}";
     if ($node->hasAttribute("ignore-missing") && $node->hasAttribute("ignore-missing") !== false) {
         $code .= " ignore missing";
     }
     if ($node->hasAttribute("with")) {
         $code .= " with " . $node->getAttribute("with");
     }
     if ($node->hasAttribute("only") && $node->getAttribute("only") !== "false") {
         $code .= " only";
     }
     $ext = $context->createControlNode($code);
     $set = iterator_to_array($node->childNodes);
     $n = $node->ownerDocument->createTextNode("\n");
     array_unshift($set, $n);
     array_unshift($set, $ext);
     $set[] = $context->createControlNode("endembed");
     DOMHelper::replaceWithSet($node, $set);
 }
예제 #2
0
 public function visit(\DOMAttr $att, Compiler $context)
 {
     $node = $att->ownerElement;
     DOMHelper::removeChilds($node);
     $pi = $context->createPrintNode(html_entity_decode($att->value));
     $node->appendChild($pi);
     $node->removeAttributeNode($att);
 }
예제 #3
0
 public function addCustomNamespace(TemplateEvent $event)
 {
     foreach (iterator_to_array($event->getTemplate()->getDocument()->childNodes) as $child) {
         if ($child instanceof \DOMElement) {
             DOMHelper::checkNamespaces($child, $this->customNamespaces);
         }
     }
 }
예제 #4
0
파일: MacroNode.php 프로젝트: goetas/twital
 public function visit(\DOMElement $node, Compiler $context)
 {
     if (!$node->hasAttribute("name")) {
         throw new Exception("Name attribute is required");
     }
     $context->compileChilds($node);
     $set = iterator_to_array($node->childNodes);
     $start = $context->createControlNode("macro " . $node->getAttribute("name") . "(" . $node->getAttribute("args") . ")");
     array_unshift($set, $start);
     $set[] = $context->createControlNode("endmacro");
     DOMHelper::replaceWithSet($node, $set);
 }
예제 #5
0
파일: BlockNode.php 프로젝트: goetas/twital
 public function visit(\DOMElement $node, Compiler $context)
 {
     if (!$node->hasAttribute("name")) {
         throw new Exception("Name attribute is required");
     }
     $sandbox = $node->ownerDocument->createElementNS(Twital::NS, "sandbox");
     $node->parentNode->insertBefore($sandbox, $node);
     $node->parentNode->removeChild($node);
     $sandbox->appendChild($node);
     $context->compileAttributes($node);
     $context->compileChilds($node);
     $start = $context->createControlNode("block " . $node->getAttribute("name"));
     $end = $context->createControlNode("endblock");
     $sandbox->insertBefore($start, $sandbox->firstChild);
     $sandbox->appendChild($end);
     DOMHelper::replaceWithSet($sandbox, iterator_to_array($sandbox->childNodes));
     DOMHelper::replaceWithSet($node, iterator_to_array($node->childNodes));
 }
예제 #6
0
 public function visit(\DOMElement $node, Compiler $context)
 {
     if ($node->hasAttribute("from-exp")) {
         $filename = $node->getAttribute("from-exp");
     } elseif ($node->hasAttribute("from")) {
         $filename = '"' . $node->getAttribute("from") . '"';
     } else {
         throw new Exception("The 'from' or 'from-exp' attribute is required");
     }
     $context->compileChilds($node);
     $ext = $context->createControlNode("extends {$filename}");
     $set = iterator_to_array($node->childNodes);
     if (count($set)) {
         $n = $node->ownerDocument->createTextNode("\n");
         array_unshift($set, $n);
     }
     array_unshift($set, $ext);
     DOMHelper::replaceWithSet($node, $set);
 }
예제 #7
0
파일: OmitNode.php 프로젝트: goetas/twital
 public function visit(\DOMElement $node, Compiler $context)
 {
     $context->compileAttributes($node);
     $context->compileChilds($node);
     DOMHelper::replaceWithSet($node, iterator_to_array($node->childNodes));
 }