<commit_before><?php

namespace attitude\Mustache;

use \Mustache_Loader_FilesystemLoader;
use \attitude\Elements\HTTPException;

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

/**
 * Mustache Atomic Template filesystem Loader implementation.
 *
 * A FilesystemLoader instance loads Mustache Template source from the filesystem by name:
 *
 *     $loader = new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views');
 *     $tpl = $loader->load('foo-bar'); // equivalent to `file_get_contents(dirname(__FILE__).'/views/foo/bar/template.mustache');
 *
 */
class AtomicLoader_FilesystemLoader extends Mustache_Loader_FilesystemLoader
{
    protected $baseDir;

    protected $publicDir = null;
    protected $publicURL = '';

    /**
     * @var array     Array of assets, where assets item is defined as an
     *                `array('glob' => (string) 'relative glob() expression', 'template' => (string) 'sprintf() template')`.
     */
    protected $assets = array();

    /**
     * @var array      Hashes of assets that have been already loaded within this loader.
     */
    protected $assetsIndex = array();

    protected $basename = 'template';
    protected $extension = '.mustache';
    protected $templates = array();

    protected $enableFiltersPragma = true;
    protected $expandTranslationMarkup = true;

    /**
     * Mustache filesystem Loader constructor (Change: Added basename option).
     *
     * @see https://github.com/bobthecow/mustache.php/blob/master/src/Mustache/Loader/FilesystemLoader.php
     *
     */
    public function __construct($baseDir, array $options = array())
    {
        $this->baseDir = $baseDir;

        if (strpos($this->baseDir, '://') === -1) {
            $this->baseDir = realpath($this->baseDir);
        }

        if (!is_dir($this->baseDir)) {
            throw new \Mustache_Exception_RuntimeException(sprintf('FilesystemLoader baseDir must be a directory: %s', $baseDir));
        }

        foreach ($options as $key => $option) {
            switch ($key) {
                case 'extension':
                    if (empty($options['extension'])) {
                        $this->extension = '';
                    } else {
                        $this->extension = '.' . ltrim($options['extension'], '.');
                    }
                break;
                case 'publicDir':
                    $options['publicDir'] = trim($options['publicDir']);

                    if (strlen($options['publicDir']) > 0 && realpath($options['publicDir'])) {
                        $this->publicDir = realpath($options['publicDir']);<commit_msg>Be nice, try to create the directory<commit_after><?php

namespace attitude\Mustache;

use \Mustache_Loader_FilesystemLoader;
use \attitude\Elements\HTTPException;

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

/**
 * Mustache Atomic Template filesystem Loader implementation.
 *
 * A FilesystemLoader instance loads Mustache Template source from the filesystem by name:
 *
 *     $loader = new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views');
 *     $tpl = $loader->load('foo-bar'); // equivalent to `file_get_contents(dirname(__FILE__).'/views/foo/bar/template.mustache');
 *
 */
class AtomicLoader_FilesystemLoader extends Mustache_Loader_FilesystemLoader
{
    protected $baseDir;

    protected $publicDir = null;
    protected $publicURL = '';

    /**
     * @var array     Array of assets, where assets item is defined as an
     *                `array('glob' => (string) 'relative glob() expression', 'template' => (string) 'sprintf() template')`.
     */
    protected $assets = array();

    /**
     * @var array      Hashes of assets that have been already loaded within this loader.
     */
    protected $assetsIndex = array();

    protected $basename = 'template';
    protected $extension = '.mustache';
    protected $templates = array();

    protected $enableFiltersPragma = true;
    protected $expandTranslationMarkup = true;

    /**
     * Mustache filesystem Loader constructor (Change: Added basename option).
     *
     * @see https://github.com/bobthecow/mustache.php/blob/master/src/Mustache/Loader/FilesystemLoader.php
     *
     */
    public function __construct($baseDir, array $options = array())
    {
        $this->baseDir = $baseDir;

        if (strpos($this->baseDir, '://') === -1) {
            $this->baseDir = realpath($this->baseDir);
        }

        if (!is_dir($this->baseDir)) {
            // A little help: try to create if subdirectory is missing
            if (!mkdir($this->baseDir, 0755, true)) {
                throw new \Mustache_Exception_RuntimeException(sprintf('Failed to create deep structure. FilesystemLoader baseDir must be a directory: %s', $baseDir));
            }

            // Test again
            if (!is_dir($this->baseDir)) {
                throw new \Mustache_Exception_RuntimeException(sprintf('FilesystemLoader baseDir must be a directory: %s', $baseDir));
            }
        }

        foreach ($options as $key => $option) {
            switch ($key) {
                case 'extension':
                    if (empty($options['extension'])) {
                        $this->extension = '';
                    } else {
                        $this->extension = '.' . ltrim($options['extension'], '.');
                    }
                break;
                case 'publicDir':
                    $options['publicDir'] = trim($options['publicDir']);

                    if (strlen($options['publicDir']) > 0 && realpath($options['publicDir'])) {
                        $this->publicDir = realpath($options['publicDir']);
{'fraction_non_alphanumeric': 0.13003355704697986, 'fraction_numerical': 0.0026845637583892616, 'mean_word_length': 2.4160458452722064, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, 'https://': 2, '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': '1735755', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1551, 'n_words': 416}