Author: Asmir Mustafic (goetas@gmail.com)
Exemplo n.º 1
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");
     }
     // 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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));
 }
Exemplo n.º 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);
 }
Exemplo n.º 7
0
 public function visit(\DOMElement $node, Compiler $context)
 {
     $context->compileAttributes($node);
     $context->compileChilds($node);
     DOMHelper::replaceWithSet($node, iterator_to_array($node->childNodes));
 }