Sha256: 7ca377b27e6150573309e84178b12256c3caaebfc1c29d776b9118e331e3485e

Contents?: true

Size: 875 Bytes

Versions: 10

Compression:

Stored size: 875 Bytes

Contents

<?php

namespace MtHaml\NodeVisitor;

use MtHaml\Node\Run;

class Midblock extends NodeVisitorAbstract
{
    protected $midblockRegex;

    public function __construct($midblockRegex)
    {
        $this->midblockRegex = $midblockRegex;
        $this->skip = new \SplObjectStorage;
    }

    public function enterRun(Run $node)
    {
        do {
            if (null === $prev = $node->getPreviousSibling()) {
                break;
            }
            if (!$prev instanceof Run) {
                break;
            }
            if (!preg_match($this->midblockRegex, $node->getContent())) {
                break;
            }

            $node->getParent()->removeChild($node);
            while (null !== $prev->getMidblock()) {
                $prev = $prev->getMidblock();
            }
            $prev->setMidblock($node);
        } while (false);
    }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
guard-mthaml-0.4.0 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php
guard-mthaml-0.3.1 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php
guard-mthaml-0.3.0 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php
guard-mthaml-0.2.5 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php
guard-mthaml-0.2.4 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php
guard-mthaml-0.2.3 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php
guard-mthaml-0.2.2 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php
guard-mthaml-0.2.1 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php
guard-mthaml-0.2.0 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php
guard-mthaml-0.1.0 vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php