• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dg / texy / 22262497275

21 Feb 2026 07:01PM UTC coverage: 93.057% (+0.7%) from 92.367%
22262497275

push

github

dg
added CLAUDE.md

2426 of 2607 relevant lines covered (93.06%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.59
/src/Bridges/Latte/TexyNode.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Texy! (https://texy.nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Texy\Bridges\Latte;
9

10
use Latte;
11
use Latte\Compiler\NodeHelpers;
12
use Latte\Compiler\Nodes\AreaNode;
13
use Latte\Compiler\Nodes\Php\Expression\ArrayNode;
14
use Latte\Compiler\Nodes\Php\IdentifierNode;
15
use Latte\Compiler\Nodes\StatementNode;
16
use Latte\Compiler\PrintContext;
17
use Latte\Compiler\Tag;
18
use Latte\Compiler\TemplateParser;
19

20

21
/**
22
 * AST node for {texy} tag in Latte templates.
23
 */
24
class TexyNode extends StatementNode
25
{
26
        public AreaNode $content;
27
        public ArrayNode $args;
28

29

30
        /**
31
         * @param  \Closure(string, mixed...): string  $processor
32
         * @return \Generator<int, ?array{list<string>}, array{AreaNode, ?Tag}, static|Latte\Compiler\Nodes\TextNode>
33
         */
34
        public static function create(Tag $tag, TemplateParser $parser, \Closure $processor): \Generator
1✔
35
        {
36
                if ($tag->isNAttribute()) {
1✔
37
                        throw new \LogicException('The n:texy is not supported');
×
38
                }
39

40
                $lexer = $parser->getLexer();
1✔
41
                $savedC = $parser->getContentType();
1✔
42
                $syntax = false;
1✔
43

44
                $node = new static;
1✔
45
                $node->args = $tag->parser->parseArguments();
1✔
46

47
                foreach ($node->args->items as $i => $arg) {
1✔
48
                        if ($arg->key instanceof IdentifierNode && $arg->key->name === 'syntax') {
1✔
49
                                array_splice($node->args->items, $i, 1);
1✔
50
                                $lexer->setSyntax(NodeHelpers::toValue($arg->value), $tag->name);
1✔
51
                                $syntax = true;
1✔
52
                                break;
1✔
53
                        }
54
                }
55

56
                $parser->setContentType(Latte\ContentType::Text);
1✔
57

58
                [$node->content] = yield;
1✔
59

60
                $parser->setContentType($savedC);
1✔
61
                if ($syntax) {
1✔
62
                        $lexer->popSyntax();
1✔
63
                }
64

65
                $text = NodeHelpers::toText($node->content);
1✔
66
                if ($text !== null) {
1✔
67
                        try {
68
                                $text = $processor($text, ...NodeHelpers::toValue($node->args));
1✔
69
                                return new Latte\Compiler\Nodes\TextNode($text);
1✔
70
                        } catch (\Throwable) {
×
71
                        }
72
                }
73

74
                return $node;
1✔
75
        }
76

77

78
        public function print(PrintContext $context): string
1✔
79
        {
80
                $context->beginEscape()->enterContentType(Latte\ContentType::Text);
1✔
81
                $res = $context->format(
1✔
82
                        <<<'XX'
83
                                ob_start(fn() => '') %line;
1✔
84
                                try {
85
                                        %node
86
                                } finally {
87
                                        $ʟ_tmp = ob_get_clean();
88
                                }
89
                                echo ($this->global->texy)($ʟ_tmp, ...%node);
90

91

92
                                XX,
93
                        $this->position,
1✔
94
                        $this->content,
1✔
95
                        $this->args,
1✔
96
                );
97
                $context->restoreEscape();
1✔
98
                return $res;
1✔
99
        }
100

101

102
        public function &getIterator(): \Generator
1✔
103
        {
104
                yield $this->content;
1✔
105
        }
1✔
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc