<commit_before><?php

/*
 * This file is part of the Terrific Core Bundle.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Terrific\CoreBundle\Twig\Extension;

use Symfony\Component\HttpKernel\KernelInterface;
use Twig_Test_Method;
use Twig_Filter_Method;
use Symfony\Component\Finder\Finder;

class TerrificCoreExtension extends \Twig_Extension
{
    private $kernel;

    /**
     * Constructor.
     *
     * @param KernelInterface $kernel The kernel is used to get the root dir
     */
    public function __construct(KernelInterface $kernel)
    {
        $this->kernel = $kernel;
    }

    /**
     * {@inheritdoc}
     */
    function initRuntime(\Twig_Environment $environment)
    {
        // extend the loader paths
        $currentLoader = $environment->getLoader();
        $dir =  $this->kernel->getRootDir().'/../src/Terrific/Composition/Resources/macros/';
        $currentLoader->setPaths(array_merge($currentLoader->getPaths(), array(__DIR__, $dir)));

        // load the core macros
        $environment->addGlobal('tc', $environment->loadTemplate('terrificcore.html.twig'));

        // load the composition macros
        if(file_exists($dir)) {
            $finder = new Finder();
            $finder->files()->in($dir)->depth('== 0');

            foreach ($finder as $file) {
               $filename = $file->getFilename();

               if(strpos($filename, 'html') !== false) {
                    $parts = explode('.', $file->getFilename());
                    $macro = $parts[0];
                    $environment->addGlobal($macro, $environment->loadTemplate($file->getFilename()));
               }
            }
        }
    }

    /**
     * {@inheritdoc}
     */
    public function getFilters()
    {
        return array(
            'dash' => new Twig_Filter_Method($this, 'dash'),
        );
    }

    public static function dash($value) {
        return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1-\\2', '\\1-\\2'), strtr($value, '-', '.')));
    }

    /**
     * {@inheritdoc}
     */
    public function getTests()
    {
        return array(
            'containing' => new Twig_Test_Method($this, 'containing')
        );
    }

    public static function containing($value, $needle)
    {
        return strpos($value, $needle) !== false;
    }



    /**
     * {@inheritdoc}
     */
    function getName()
    {
        return 'terrific_core';
    }
}



<commit_msg>remove twig macro loading (moved to TerrificComposerBundle)<commit_after><?php

/*
 * This file is part of the Terrific Core Bundle.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Terrific\CoreBundle\Twig\Extension;

use Symfony\Component\HttpKernel\KernelInterface;
use Twig_Test_Method;
use Twig_Filter_Method;
use Symfony\Component\Finder\Finder;

class TerrificCoreExtension extends \Twig_Extension
{
    private $kernel;

    /**
     * Constructor.
     *
     * @param KernelInterface $kernel The kernel is used to get the root dir
     */
    public function __construct(KernelInterface $kernel)
    {
        $this->kernel = $kernel;
    }

    /**
     * {@inheritdoc}
     */
    function initRuntime(\Twig_Environment $environment)
    {
        // extend the loader paths
        $currentLoader = $environment->getLoader();
        $currentLoader->setPaths(array_merge($currentLoader->getPaths(), array(__DIR__)));

        // load the core macros
        $environment->addGlobal('tc', $environment->loadTemplate('terrificcore.html.twig'));
    }

    /**
     * {@inheritdoc}
     */
    public function getFilters()
    {
        return array(
            'dash' => new Twig_Filter_Method($this, 'dash'),
        );
    }

    public static function dash($value) {
        return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1-\\2', '\\1-\\2'), strtr($value, '-', '.')));
    }

    /**
     * {@inheritdoc}
     */
    public function getTests()
    {
        return array(
            'containing' => new Twig_Test_Method($this, 'containing')
        );
    }

    public static function containing($value, $needle)
    {
        return strpos($value, $needle) !== false;
    }



    /**
     * {@inheritdoc}
     */
    function getName()
    {
        return 'terrific_core';
    }
}




{'fraction_non_alphanumeric': 0.15377875136911281, 'fraction_numerical': 0.002190580503833516, 'mean_word_length': 2.3207272727272725, 'pattern_counts': {'":': 0, '<': 11, '<?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': '1445102', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1348, 'n_words': 293}