Parse symbols inside EchoNode #12
khalyomede
started this conversation in
Ideas
Replies: 1 comment
-
I'm not entirely opposed to the idea, but will need to do some thinking before pulling that in as a dependency (even though its fantastic). The The nodes are macroable, however, and this is something you could add to your current project: <?php
use Illuminate\Support\Str;
use PhpParser\ParserFactory;
use Stillat\BladeParser\Document\Document;
use Stillat\BladeParser\Nodes\EchoNode;
$template = <<<'BLADE'
@extends("layout")
@section("content")
{{ trans("List of books") }}
@endsection
BLADE;
EchoNode::macro('toAst', function () {
$php = '<?php '.Str::finish($this->innerContent, ';').' ?>';
return (new ParserFactory)->create(ParserFactory::PREFER_PHP7)->parse($php);
});
Document::fromText($template)->getEchoes()->each(function (EchoNode $node) {
$ast = $node->toAst();
dd($ast);
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My need is the following: I am (still) working on this Laravel package to pull languages strings from a blade file, and I want to support not only
@lang()
and@choice()
(working fine thanks to this package), but also{{ trans() }}
,{{ __() }}
and{{ trans_choice() }}
.For the moment, this is how the following blade content will be parsed
What I would have needed is the
childNodes
(?) to contain a list of all parsed nodes.Here is my proposal:
{{
and}}
In my experiment, here is how
trans('List of books');
rendersWilling to make a pull request if the idea appeals to you (might take some round trips between you and me untill it is polished as you wish).
Beta Was this translation helpful? Give feedback.
All reactions