Beispiel #1
0
 /**
  * Returns the node string value, line by line.
  * If the compiler is present, that means we need
  * to interpolate line contents
  * @param Filter $node
  * @param Compiler $compiler
  * @return mixed
  */
 protected function getNodeString(Filter $node, Compiler $compiler = null)
 {
     return array_reduce($node->block->nodes, function (&$result, $line) use($compiler) {
         $val = $compiler ? $compiler->interpolate($line->value) : $line->value;
         return $result .= $val . "\n";
     });
 }
Beispiel #2
0
 public function testEngineOptions()
 {
     $jade = new Jade(array('terse' => false, 'indentChar' => '@'));
     $compiler = new Compiler($jade);
     $jade->setCustomOption('foo', 'bar');
     $this->assertFalse($compiler->getOption('terse'));
     $this->assertSame('@', $compiler->getOption('indentChar'));
     $this->assertSame('bar', $compiler->getOption('foo'));
 }
Beispiel #3
0
 public function render($input, $scope = null, $includes = array())
 {
     if ($scope !== null && is_array($scope)) {
         extract($scope);
     }
     $parser = new Parser($input, array('includes' => $includes));
     $compiler = new Compiler($this->prettyprint);
     return $compiler->compile($parser->parse($input));
 }
Beispiel #4
0
 /**
  * @param Filter   $node
  * @param Compiler $compiler
  *
  * @return string
  */
 public function __invoke(Filter $node, Compiler $compiler)
 {
     $data = '';
     foreach ($node->block->nodes as $n) {
         if (isset($n->value)) {
             $data .= preg_match('/^[[:space:]]*\\|(?!\\|)(.*)/', $n->value, $m) ? ' ?> ' . $m[1] . '<?php ' : $n->value . "\n";
             continue;
         }
         $data .= ' ?> ' . $compiler->subCompiler()->compile($n) . '<?php ';
     }
     return $data ? '<?php ' . $data . ' ?> ' : $data;
 }
Beispiel #5
0
 /**
  * @param Filter   $node
  * @param Compiler $compiler
  *
  * @return string
  */
 public function __invoke(Filter $node, Compiler $compiler)
 {
     $data = '';
     foreach ($node->block->nodes as $n) {
         if (isset($n->value)) {
             $data .= preg_match('/^[[:space:]]*\\|(?!\\|)(.*)/', $n->value, $m) ? $compiler->wrapOutPhp($m[1]) : $n->value . "\n";
             continue;
         }
         $data .= $compiler->wrapOutPhp($compiler->subCompiler()->compile($n));
     }
     return $data ? $compiler->wrapInPhp($data) : $data;
 }
Beispiel #6
0
 public function __invoke(Filter $node, Compiler $compiler)
 {
     $nodes = $node->block->nodes;
     $indent = strlen($nodes[0]->value) - strlen(ltrim($nodes[0]->value));
     $code = '';
     foreach ($nodes as $line) {
         $code .= substr($compiler->interpolate($line->value), $indent) . "\n";
     }
     if (method_exists($this, 'parse')) {
         $code = $this->parse($code);
     }
     if (isset($this->tag)) {
         $code = '<' . $this->tag . (isset($this->textType) ? ' type="text/' . $this->textType . '"' : '') . '>' . $code . '</' . $this->tag . '>';
     }
     return $code;
 }
Beispiel #7
0
 /**
  * @param $input
  * @return string
  */
 public function compile($input)
 {
     $parser = new Parser($input, null, $this->options['extension']);
     $compiler = new Compiler($this->options['prettyprint'], $this->options['phpSingleLine'], $this->options['allowMixinOverride'], $this->filters);
     return $compiler->compile($parser->parse($input));
 }
Beispiel #8
0
 /**
  * Compile PHP code from a Pug input or a Pug file.
  *
  * @param string input
  *
  * @throws \Exception
  *
  * @return string
  */
 public function compile($input)
 {
     $parser = new Parser($input, null, $this->options);
     $compiler = new Compiler($this->options, $this->filters, $parser->getFilename());
     $php = $compiler->compile($parser->parse());
     if (version_compare(PHP_VERSION, '7.0.0') < 0) {
         $php = preg_replace_callback('/(' . preg_quote('\\Jade\\Compiler::getPropertyFromAnything', '/') . '\\(((?>[^()]+)|(?-2))*\\))[ \\t]*(\\(((?>[^()]+)|(?-2))*\\))/', function ($match) {
             return 'call_user_func(' . $match[1] . ', ' . $match[4] . ')';
         }, $php);
     }
     $postRender = $this->getOption('postRender');
     if (is_callable($postRender)) {
         $php = call_user_func($postRender, $php);
     }
     return $php;
 }
Beispiel #9
0
 public function testWithMixinAttributes()
 {
     $attributes = Compiler::withMixinAttributes(array('a' => 'b'), array(array('name' => 'class', 'value' => 'foo')));
     $this->assertSame(array('a' => 'b', 'class' => 'foo'), $attributes);
 }
Beispiel #10
0
 public function testNestedParenthesesCount()
 {
     $compiler = new Compiler();
     $code = $compiler->handleCode('b->c(a(d->e->f), g->h)');
     $this->assertSame(3, count($code));
 }
Beispiel #11
0
 /**
  * @param $input
  * @return string
  */
 public function compile($input)
 {
     $parser = new Parser($input, null, $this->options['extension']);
     $compiler = new Compiler($this->options['prettyprint'], $this->filters);
     return $compiler->compile($parser->parse($input));
 }
Beispiel #12
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionCode 2
  */
 public function testInvalidOptionWithEngineInConstructor()
 {
     $jade = new Jade();
     $compiler = new Compiler($jade);
     $compiler->getOption('foo');
 }