예제 #1
0
 public function optimize(Renderer $renderer, Filter $node, $options)
 {
     $inserts = array();
     $content = '';
     foreach ($node->getChilds() as $child) {
         foreach ($child->getContent()->getChilds() as $item) {
             if ($item instanceof Text) {
                 $content .= $item->getContent();
             } else {
                 $hash = md5(mt_rand());
                 $inserts[$hash] = $item;
                 $content .= $hash;
             }
         }
         $content .= "\n";
     }
     $string = new InterpolatedString(array());
     $result = $this->filter($content, array(), array());
     foreach ($inserts as $hash => $insert) {
         $parts = explode($hash, $result, 2);
         $string->addChild(new Text(array(), $parts[0]));
         $string->addChild($insert);
         $result = $parts[1];
     }
     $string->addChild(new Text(array(), $result));
     $string->accept($renderer);
 }
예제 #2
0
파일: Twig.php 프로젝트: gunderjt/MtHaml
 public function optimize(Renderer $renderer, Filter $node, $options)
 {
     foreach ($node->getChilds() as $line) {
         $content = '';
         foreach ($line->getContent()->getChilds() as $child) {
             $content .= $child->getContent();
         }
         $renderer->write($content);
     }
 }
예제 #3
0
 protected function getContent(Filter $node)
 {
     $content = '';
     foreach ($node->getChilds() as $line) {
         foreach ($line->getContent()->getChilds() as $child) {
             $content .= $child->getContent();
         }
         $content .= "\n";
     }
     return $content;
 }
예제 #4
0
파일: Printer.php 프로젝트: gunderjt/MtHaml
 public function enterFilter(Filter $node)
 {
     $this->write('filter(' . $node->getFilter())->indent();
 }
 public function leaveFilter(Filter $node)
 {
     switch ($node->getFilter()) {
         case 'javascript':
             $this->undent()->write('//]]>')->write('</script>');
             break;
         case 'css':
             $this->undent()->write('/*]]>*/')->write('</style>');
             break;
         case 'plain':
             break;
         case 'preserve':
             $this->indent = array_pop($this->savedIndent);
             break;
     }
 }
 protected function parseFilter($buf)
 {
     if (!$buf->match('/:(.*)/A', $match)) {
         return null;
     }
     $node = new Filter($match['pos'][0], $match[1]);
     while (null !== ($next = $buf->peekLine())) {
         $indent = '';
         if ('' !== trim($next)) {
             $indent = $this->getIndentString(1, $next);
             if ('' === $indent) {
                 break;
             }
             if (strpos($next, $indent) !== 0) {
                 break;
             }
         }
         $buf->nextLine();
         $buf->eatChars(strlen($indent));
         $str = $this->parseInterpolatedString($buf, false);
         $node->addChild(new Statement($str->getPosition(), $str));
     }
     return $node;
 }
예제 #7
0
 public function leaveFilter(Filter $node)
 {
     $filter = $this->env->getFilter($node->getFilter());
     if (!$filter->isOptimizable($this, $node, $this->env->getOptions())) {
         $this->write('{% endfilter %}');
         $this->indent = $this->popSavedIndent();
     }
 }
예제 #8
0
 public function leaveFilter(Filter $node)
 {
     $filter = $this->env->getFilter($node->getFilter());
     if (!$filter->isOptimizable($this, $node, $this->env->getOptions())) {
         $this->undent();
         $this->write(') ?>');
         $this->popEchoMode();
     }
 }
예제 #9
0
 public function enterFilterChilds(Filter $node)
 {
     $filter = $this->env->getFilter($node->getFilter());
     if ($filter->isOptimizable($this, $node, $this->env->getOptions())) {
         $filter->optimize($this, $node, $this->env->getOptions());
         return false;
     }
 }