<commit_before><?php namespace Dtkahl\FormBuilder;

use Dtkahl\FormBuilder\FieldSet;

class TwigRenderableExtension extends \Twig_Extension
{
    private $twig_environment;

    public function __construct(\Twig_Environment $twig_environment)
    {
        $this->twig_environment = $twig_environment;
    }

    public function getName()
    {
        return 'renderable-extension';
    }

    public function getFunctions()
    {
        return [new \Twig_Function("render", function (TwigRenderableInterface $object) { // TODO as custom Tag instead? because of raw problem..
            return $this->twig_environment->loadTemplate($object->getTemplate())->render($object->getRenderData());
        })];
    }
}<commit_msg>* update twig extension (custom tag instead of function)<commit_after><?php namespace Dtkahl\FormBuilder;

use Dtkahl\FormBuilder\FieldSet;
use Twig_Token;

class TwigRenderableExtension extends \Twig_Extension
{
    private $twig_environment;

    public function __construct(\Twig_Environment $twig_environment)
    {
        $this->twig_environment = $twig_environment;
    }

    public function getName()
    {
        return 'renderable-extension';
    }

    public function getTokenParsers()
    {
        return [new class extends \Twig_TokenParser {
            public function getTag() {
                return 'render';
            }
            public function parse(Twig_Token $token) {
                $stream = $this->parser->getStream();
                $expr = $this->parser->getExpressionParser()->parseExpression();
                $stream->expect(Twig_Token::BLOCK_END_TYPE);

                return new class($expr, $token->getLine(), $this->getTag()) extends \Twig_Node {
                    public function __construct($expr, $lineno = 0, $tag = null) {
                        parent::__construct(["expr" => $expr], [], $lineno, $tag);
                    }
                    public function compile(\Twig_Compiler $compiler) {
                        $compiler
                            ->addDebugInfo($this)
                            ->raw("(function (\$renderable) {\n")
                            ->raw("if (!\$renderable instanceof \Dtkahl\FormBuilder\TwigRenderableInterface) {\n")
                            ->raw("throw new \InvalidArgumentException(\"Must implement RenderableInterface.\");\n")
                            ->raw("}\n")
                            ->raw("\$this")
                            ->raw("->loadTemplate(\$renderable->getTemplate())")
                            ->raw("->display(\$renderable->getRenderData());\n")
                            ->raw("})(")
                            ->subcompile($this->getNode('expr'))
                            ->raw(");\n")
                        ;
                    }
                };
            }
        }];
    }
}
{'fraction_non_alphanumeric': 0.12561231630510847, 'fraction_numerical': 0.0003498950314905528, 'mean_word_length': 1.8056918547595682, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2340091', 'n_tokens_mistral': 740, 'n_tokens_neox': 717, 'n_words': 140}