Skip to content

1.5.0

Choose a tag to compare

@JohnathonKoster JohnathonKoster released this 12 Sep 23:26
· 53 commits to master since this release
10c2373

This release improves the built-in compiler's support for complicated PHP expressions within the @json directive.

Additionally, this release adds a new abstract node transformer. This transformer provides a simple way to iterate all nodes in a document and change the output, while skipping over nodes within the document.

For example, if we had the following node transformer implementation:

<?php

use Stillat\BladeParser\Compiler\Transformers\NodeTransformer;
use Stillat\BladeParser\Nodes\DirectiveNode;

class CustomTransformer extends NodeTransformer
{
    public function transformNode($node): ?string
    {
        if (! $node instanceof DirectiveNode || $node->content != 'custom') {
            return null;
        }

        $this->skipToNode($node->isClosedBy);

        return '@include("something-here")';
    }
}

we could transform a document like so:

<?php

use Stillat\BladeParser\Document\Document;
use Stillat\BladeParser\Document\DocumentOptions;

$doc = Document::fromText($template, documentOptions: new DocumentOptions(
            withCoreDirectives: false,
            customDirectives: ['custom', 'endcustom']
        ))->resolveStructures();

$result = (new CustomTransformer())->transformDocument($doc);

to produce the final result:

The beginning.

@include("something-here")

The end.