<commit_before><?php

namespace Gregwar\Slidey;

/**
 * Builds the slidey project
 */
class Builder extends \Twig_Extension
{
    /**
     * Metas informations
     */
    protected $metas;

    /**
     * Functions available for Twig
     */
    protected $twigFunctions = array(
        'chapter', 'part', 'annex', 'annexLink', 'toc', 'summary'
    );

    /**
     * Target directory for the build
     */
    protected $targetDirectory;

    /**
     * Directory containing pages
     */
    protected $pagesDirectory;

    /**
     * The current meta
     */
    protected $meta;

    /**
     * Files that need to be copied
     */
    protected $copies = array();

    /**
     * Directories to create
     */
    protected $mkDirectories = array();

    /**
     * Pretty links to annexes
     */
    protected $annexLinks = array();

    /**
     * Template
     */
    public $template;

    /**
     * Explore queue
     */
    public $exploreQueue;

    /**
     * Already explored
     */
    public $explored;

    public function __construct()
    {
        $this->template = new Template($this);
        $this->template->addExtension($this);
    }

    public function getFunctions()
    {
        $functions = array();

        foreach ($this->twigFunctions as $name) {
            $functions[$name] = new \Twig_Function_Method($this, $name, array('is_safe' => array('html')));
        }

        return $functions;
    }

    public function getName()
    {
        return 'slidey';
    }

    /**
     * Gets the path of a target page
     */
    public function targetFilePath($file)
    {
	return $this->targetDirectory . '/' . $file;
    }

    /**
     * Gets the path of a target page
     */
    public function pagesFilePath($file)
    {
	return $this->pagesDirectory . '/' . $file;
    }

    /**
     * Run the builder 
     */
    public function build($targetDirectory = 'web', $pagesDirectory = 'pages')
    {
	$this->targetDirectory = $targetDirectory;
        $this->pagesDirectory = $pagesDirectory;

	if (isset($_SERVER['argv'])) {
	    $argv = $_SERVER['argv'];
	}

	if (isset($argv[1])) {
	    if ($argv[1] == 'redo' || $argv[1] == 'clean') {
		$this->cleanCache();
            }
	}

        if (!isset($argv[1]) || $argv[1] != 'clean') {
            $this->run();
        }
    }

    /**
     * Cleans the cache
     */
    public function cleanCache()
    {
	echo "* Clearing cache\n";
	system('rm -rf ' . $this->targetFilePath('*') ." \n");
    }

    /**
     * Gets the meta filename
     */
    protected function metaFilename()
    {
	return $this->targetFilePath('meta.php');
    }

    /**
     * Try to load meta
     */
    protected function loadMeta()
    {
        $this->metas = new Metas($this->metaFilename());
    }

    /**
     * Runs the cache builder
     */
    public function run()
    {
	$this->loadMeta();

        echo '* Crawling ' . $this->pagesDirectory . "\n";

        if (!is_dir($this->targetDirectory)) {
            echo '* Creating ' . $this->targetDirectory . "\n";
            mkdir($this->targetDirectory);
        }
        
        $this->template->setDirectories(getcwd() . '/' . $this->pagesDirectory, getcwd() . '/' . $this->targetDirectory);

	// Processing files
	$this->explore();

	// Generating layouts
	$this->generateLayouts();

	// Saving meta<commit_msg>Changing explore text<commit_after><?php

namespace Gregwar\Slidey;

/**
 * Builds the slidey project
 */
class Builder extends \Twig_Extension
{
    /**
     * Metas informations
     */
    protected $metas;

    /**
     * Functions available for Twig
     */
    protected $twigFunctions = array(
        'chapter', 'part', 'annex', 'annexLink', 'toc', 'summary'
    );

    /**
     * Target directory for the build
     */
    protected $targetDirectory;

    /**
     * Directory containing pages
     */
    protected $pagesDirectory;

    /**
     * The current meta
     */
    protected $meta;

    /**
     * Files that need to be copied
     */
    protected $copies = array();

    /**
     * Directories to create
     */
    protected $mkDirectories = array();

    /**
     * Pretty links to annexes
     */
    protected $annexLinks = array();

    /**
     * Template
     */
    public $template;

    /**
     * Explore queue
     */
    public $exploreQueue;

    /**
     * Already explored
     */
    public $explored;

    public function __construct()
    {
        $this->template = new Template($this);
        $this->template->addExtension($this);
    }

    public function getFunctions()
    {
        $functions = array();

        foreach ($this->twigFunctions as $name) {
            $functions[$name] = new \Twig_Function_Method($this, $name, array('is_safe' => array('html')));
        }

        return $functions;
    }

    public function getName()
    {
        return 'slidey';
    }

    /**
     * Gets the path of a target page
     */
    public function targetFilePath($file)
    {
	return $this->targetDirectory . '/' . $file;
    }

    /**
     * Gets the path of a target page
     */
    public function pagesFilePath($file)
    {
	return $this->pagesDirectory . '/' . $file;
    }

    /**
     * Run the builder 
     */
    public function build($targetDirectory = 'web', $pagesDirectory = 'pages')
    {
	$this->targetDirectory = $targetDirectory;
        $this->pagesDirectory = $pagesDirectory;

	if (isset($_SERVER['argv'])) {
	    $argv = $_SERVER['argv'];
	}

	if (isset($argv[1])) {
	    if ($argv[1] == 'redo' || $argv[1] == 'clean') {
		$this->cleanCache();
            }
	}

        if (!isset($argv[1]) || $argv[1] != 'clean') {
            $this->run();
        }
    }

    /**
     * Cleans the cache
     */
    public function cleanCache()
    {
	echo "* Clearing cache\n";
	system('rm -rf ' . $this->targetFilePath('*') ." \n");
    }

    /**
     * Gets the meta filename
     */
    protected function metaFilename()
    {
	return $this->targetFilePath('meta.php');
    }

    /**
     * Try to load meta
     */
    protected function loadMeta()
    {
        $this->metas = new Metas($this->metaFilename());
    }

    /**
     * Runs the cache builder
     */
    public function run()
    {
	$this->loadMeta();

        if (!is_dir($this->targetDirectory)) {
            echo '* Creating ' . $this->targetDirectory . "\n";
            mkdir($this->targetDirectory);
        }
        
        $this->template->setDirectories(getcwd() . '/' . $this->pagesDirectory, getcwd() . '/' . $this->targetDirectory);

        // Processing files
        echo "* Exploring\n";
	$this->explore();

	// Generating layouts
	$this->generateLayouts();

	// Saving meta
{'fraction_non_alphanumeric': 0.15795777811049558, 'fraction_numerical': 0.0014972301242701003, 'mean_word_length': 1.9466254962505514, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, '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': '3889763', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1979, 'n_words': 451}