Compiles a do-instruction into PHTML.

@param Node $node the do-node to compile

@return string The compiled PHTML
@throws Exception
3726
protected function compileDo(Node $node)
    {

        $subject = $node->subject;

        if (!empty($subject))
            $this->throwException(
                "Do-loops can't have a subject, they only accept children to repeat.",
                $node
            );

        if (!$node->next() || $node->next()->type !== 'while')
            $this->throwException(
                "A do-statement needs a while-statement with a condition following immediately, {$node->next()->type} was provided"
            );

        //Notice that the } wont have closing ? >, php needs this.
        //Check compileWhile to see the combination of both
        $phtml = $this->createCode("do {").$this->newLine();
        $phtml .= $this->compileChildren($node->children).$this->newLine();
        $phtml .= $this->indent().$this->createCode('}', '<?php ', '').$this->newLine();

        return $phtml;
    }
1270203
public function transform($node)
    {
        $blocksData = $this->transformBlock($node);
        $documentData = array(
            'id' => $node->getNodeId() . '-' . $node->getLanguage(). '-' . $node->getSiteId(),
            'elementId' => $node->getId(),
            'nodeId' => $node->getNodeId(),
            'siteId' => $node->getSiteId(),
            'language' => $node->getLanguage(),
            'name' => $node->getName(),
            'blocks' => $blocksData
        );

        if (!is_null($node->getUpdatedAt())) {
            $documentData['updatedAt'] = $node->getUpdatedAt()->getTimestamp();
        }

        $document = new Document($documentData['id'], $documentData);

        return $document;
    }
997722
protected function renderNode($node)
    {
        if (is_string($node)) {
            $node = ['name' => $node];
        }
        if (!isset($node['name'])) {
            throw new InvalidConfigException("The 'name' option is required.");
        }

        $lines = [];

        $nodeOptions = array_merge([
            'data-node-id' => $node['id'],
            'data-node-name' => Html::encode($node['name']),
            'data-action-name' => 'move',   ///[node move action]
            'data-action-url' => Url::to(ArrayHelper::getValue($node, 'move-url', $this->createUrl('move', $node))),
            // more node data ...
        ], $this->nodeOptions, ArrayHelper::getValue($node, 'options', []));
        $tag = ArrayHelper::remove($nodeOptions, 'tag', 'li');

        $lines[] = Html::beginTag($tag, $nodeOptions);

        $lines[] = Html::beginTag('div');

        $lines[] = $this->renderNodeName($node);
        $lines[] = $this->renderNodeActions($node);

        $lines[] = Html::endTag('div');

        if (!empty($node['nodes'])) {
            $lines[] =  $this->renderNodes($node['nodes']);
        }

        $lines[] =  Html::endTag($tag);

        return implode("\n", $lines);
    }
1221099
function it_compiles_nodes_using_a_generic_solution($node)
    {
        $node->compile($this)->will(function ($args) {
            $args[0]->write('echo $message');
        });

        $this->repr($node)->getSource()->shouldMatch('/echo \$message/');
    }
498232
public function _body($node) {
		$params = '';
		if (isset($node['@attrib'])) {
			$params = $this->resolveAttr($node['@attrib']);
			unset($node['@attrib']);
		}
		$content = array();
		// bypass inner content nodes
		foreach ($node as $el)
			$content[] = $this->template->build($el);
		return '<body'.$params.'>'.implode("\n", $content)."\n".
			$this->render('footer')."\n".'</body>';
	}
260744
public function enterNode(Node $node)
    {
        if (!$node instanceof Instanceof_) {
            return;
        }

        if (($node->expr instanceof Scalar && !$node->expr instanceof Encapsed) || $node->expr instanceof ConstFetch) {
            throw new FatalErrorException(self::EXCEPTION_MSG, 0, E_ERROR, null, $node->getLine());
        }
    }
361247
public function enterNode(Node $node)
    {
        if ($node instanceof Assign && $node->var instanceof Variable && $node->var->name === 'this') {
            throw new FatalErrorException('Cannot re-assign $this', 0, E_ERROR, null, $node->getLine());
        }
    }
1298484
public function enterNode(Node $node)
    {
        // @todo support MethodCall and StaticCall as well.
        if ($node instanceof FuncCall) {
            // if function name is an expression or a variable, give it a pass for now.
            if ($node->name instanceof Expr || $node->name instanceof Variable) {
                return;
            }

            $name = (string) $node->name;

            if ($name === 'array_multisort') {
                return $this->validateArrayMultisort($node);
            }

            try {
                $refl = new \ReflectionFunction($name);
            } catch (\ReflectionException $e) {
                // Well, we gave it a shot!
                return;
            }

            foreach ($refl->getParameters() as $key => $param) {
                if (\array_key_exists($key, $node->args)) {
                    $arg = $node->args[$key];
                    if ($param->isPassedByReference() && !$this->isPassableByReference($arg)) {
                        throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
                    }
                }
            }
        }
    }
543552
protected function compileBlock(Node $node)
    {

        $name = $node->name;

        if (!$name)
            return $this->createCode(
                '$__scope = \\Tale\\Jade\\Compiler\\create_scope(get_defined_vars()); '.
                'echo isset($__block) && $__block instanceof \Closure ? $__block($__scope) : \'\'; '.
                'unset($__scope);'
            );

        //At this point the code knows this block only, since handleBlock took care of the blocks previously
        return $this->compileChildren($node->children, false);
    }
977125
public function enterNode(Node $node)
    {
        if ($node instanceof DeclareDeclare && ($node->getLine() === 1 || $node->getLine() === 2)) {
            throw new StrictTypesException();
        }
    }
525709
protected function compileCode(Node $node)
    {

        if (!$node->block) {

            return $this->createCode($node->value)
                  .$this->newLine()
                  .$this->compileChildren($node->children, true, true);
        }

        return $this->createCode(trim($this->compileChildren($node->children, true, true)));
    }
720207
public function compile(Node $node) : string
    {
        $this->head = $this->body = '';
        $node->compile($this);
        return $this->getResult();
    }
935515
private function replaceNode(Node $node)
    {
        //Looking for parent block call
        if (!empty($inner = $node->findNode($this->name))) {
            //This construction allows child block use parent content
            $inner->nodes = $this->nodes;
        }

        $this->nodes = $node->nodes;
    }
9018
protected function wrapNode($node)
    {
        switch (get_class($node)) {
            case 'DOMElement':
                return new Element($node);

            case 'DOMText':
                return $node->data;

            case 'DOMComment':
                return new Element($node);

            case 'DOMCdataSection':
                return new Element($node);

            case 'DOMAttr':
                return $node->value;
        }

        throw new InvalidArgumentException(sprintf('Unknown node type "%s"', get_class($node)));
    }
1281445
public static function fromNode($node)
    {
        $p = new self();
        $p->setNid($node->id());
        $p->setPhpVersion('7.0');
        if ($node->hasField('field_pull_request_template') && !$node->get('field_pull_request_template')->isEmpty()) {
            $p->setCustomPrMessage($node->get('field_pull_request_template')->first()->getString());
        }
        if (!$p->getCustomPrMessage()) {
            // See if we have a default one on the user.
            $owner = $node->getOwner();
            if ($owner->hasField('field_user_pr_template') && !$owner->get('field_user_pr_template')->isEmpty()) {
                $p->setCustomPrMessage($owner->get('field_user_pr_template')->first()->getString());
            }
        }
        if ($node->hasField('field_php_version') && !$node->get('field_php_version')->isEmpty()) {
            $p->setPhpVersion($node->get('field_php_version')->first()->getString());
        }
        $owner = $node->getOwner();
        if ($owner) {
            $p->setRoles($owner->getRoles());
        }
        return $p;
    }
1122131
public function compileNode(NodeInterface $node, ElementInterface $parent = null)
    {
        $compiler = $this->getCompiler();
        $compiler->assert(
            $node instanceof ImportNode,
            'Unexpected '.get_class($node).' given to import compiler.',
            $node
        );

        /** @var ImportNode $node */
        $path = $node->getPath();
        $isAbsolutePath = mb_substr($path, 0, 1) === '/';

        $compiler->assert(
            !($isAbsolutePath && empty($compiler->getOption('paths'))),
            'Either the "basedir" or "paths" option is required'.
            ' to use includes and extends with "absolute" paths'
        );

        $paths = $isAbsolutePath
            ? null
            : [dirname($compiler->getPath()) ?: '.'];

        $path = $compiler->resolve($node->getPath(), $paths);
        $compiler->registerImportPath($path);

        /** @var FilterNode $filter */
        if ($filter = $node->getFilter()) {
            $text = new TextNode();
            $text->setValue($compiler->getFileContents($path));
            $filter->appendChild($text);
            $import = $filter->getImport();
            $filter->setImport(null);
            $element = $compiler->compileNode($filter, $parent);
            $filter->setImport($import);

            return $element;
        }

        if (!$this->isPugImport($path)) {
            return new TextElement($compiler->getFileContents($path), $node);
        }

        $subCompiler = clone $compiler;
        $subCompiler->setParentCompiler($compiler);
        $subCompiler->setImportNode($compiler->getImportNode() ?: $node);
        $element = $subCompiler->compileFileIntoElement($path);
        $compiler->importBlocks($subCompiler->getBlocks());
        $isIncludeImport = $node->getName() === 'include';

        if ($layout = $subCompiler->getLayout()) {
            $element = $layout->getDocument();
            $layoutCompiler = $layout->getCompiler();
            if ($isIncludeImport) {
                $layoutCompiler->compileBlocks();
            }
        }

        if (!$subCompiler->isImportNodeYielded()) {
            $yield = $element;
            while ($yield instanceof ElementInterface && $yield->hasChildren()) {
                $yield = $yield->getChildAt($yield->getChildCount() - 1);
            }
            while ($yield instanceof CodeElement ||
                $yield instanceof ExpressionElement ||
                $yield instanceof TextElement
            ) {
                if ($yield instanceof CodeElement &&
                    trim($yield->getValue(), '; ') === 'break' &&
                    $yield->getPreviousSibling()
                ) {
                    $yield = $yield->getPreviousSibling();

                    continue;
                }
                $yield = $yield->getParent();
            }
            if ($yield instanceof MarkupElement && in_array($yield->getName(), [
                'script',
                'link',
                'img',
                'input',
                'meta',
                'hr',
            ])) {
                $yield = $yield->getParent();
            }
            if ($compiler->getImportNode()) {
                $node->appendChild(new YieldNode());
            }
            // TODO: check answers on https://github.com/pugjs/pug/issues/2878
            $this->compileNodeChildren($node, $yield);
        }

        if ($isIncludeImport) {
            $parentLayout = $compiler->getLayout();
            if ($parentLayout) {
                $parentDocument = $parentLayout->getDocument();
                foreach ($element->getChildren() as $child) {
                    if ($child instanceof MixinElement) {
                        $parentDocument->appendChild(clone $child);
                    }
                }
            }

            return $element;
        }

        if ($node->getName() === 'extend') {
            $layout = new Layout($element, $subCompiler);
            $subDocument = $layout->getDocument();
            foreach ($node->getParent()->getChildren() as $child) {
                if ($child instanceof MixinNode) {
                    $mixinElement = $subCompiler->compileNode($child, $subDocument);
                    if ($mixinElement) {
                        $subDocument->appendChild($mixinElement);
                    }
                }
            }
            $compiler->setLayout($layout);
        }

        return null;
    }
538996
public function enterNode(Node $node)
    {
        if ($node instanceof ConstFetch || $node instanceof FuncCall) {
            $node->name = null;
        }

        if ($node instanceof FullyQualified) {
            $this->names[] = $node->toString();
        }

        return $node;
    }