<commit_before><?php namespace TightenCo\Jigsaw\Handlers;

use Illuminate\View\Factory;
use TightenCo\Jigsaw\FrontMatterParser;
use TightenCo\Jigsaw\OutputFile;
use TightenCo\Jigsaw\ViewData;

class PaginatedPageHandler
{
    private $paginator;
    private $viewFactory;
    private $parser;
    private $temporaryFilesystem;

    public function __construct($paginator, Factory $viewFactory, FrontMatterParser $parser, $temporaryFilesystem)
    {
        $this->paginator = $paginator;
        $this->viewFactory = $viewFactory;
        $this->parser = $parser;
        $this->temporaryFilesystem = $temporaryFilesystem;
    }

    public function shouldHandle($file)
    {
        if (! ends_with($file->getFilename(), '.blade.php')) {
            return false;
        }
        $content = $this->parser->parse($file->getContents());

        return isset($content->frontMatter['pagination']);
    }

    public function handle($file, $data)
    {
        $content = $this->parser->parse($file->getContents());
        $items = $data[array_get($content->frontMatter, 'pagination.collection')];
        $perPage = array_get($content->frontMatter, 'pagination.perPage', 10);
        $pages = $this->paginator->paginate($file, $items, $perPage);

        return $pages->map(function ($page) use ($file, $data, $content) {
            return new OutputFile(
                $file->getRelativePath(),
                $file->getBasename('.blade.php'),
                'html',
                $this->render(
                    $content->content,
                    new ViewData($data->put('pagination', $page))
                ),
                $data,
                $page['currentPage']
            );
        })->all();
    }

    private function render($bladeContent, $data)
    {
        return $this->temporaryFilesystem->put($bladeContent, function ($path) use ($data) {
            return $this->viewFactory->file($path, ['jigsaw' => $data])->render();
        }, '.blade.php');
    }
}
<commit_msg>Store metadata `link` value in PaginatedPageHandler<commit_after><?php namespace TightenCo\Jigsaw\Handlers;

use Illuminate\View\Factory;
use TightenCo\Jigsaw\FrontMatterParser;
use TightenCo\Jigsaw\OutputFile;
use TightenCo\Jigsaw\ViewData;

class PaginatedPageHandler
{
    private $paginator;
    private $viewFactory;
    private $parser;
    private $temporaryFilesystem;

    public function __construct($paginator, Factory $viewFactory, FrontMatterParser $parser, $temporaryFilesystem)
    {
        $this->paginator = $paginator;
        $this->viewFactory = $viewFactory;
        $this->parser = $parser;
        $this->temporaryFilesystem = $temporaryFilesystem;
    }

    public function shouldHandle($file)
    {
        if (! ends_with($file->getFilename(), '.blade.php')) {
            return false;
        }
        $content = $this->parser->parse($file->getContents());

        return isset($content->frontMatter['pagination']);
    }

    public function handle($file, $data)
    {
        $content = $this->parser->parse($file->getContents());
        $items = $data[array_get($content->frontMatter, 'pagination.collection')];
        $perPage = array_get($content->frontMatter, 'pagination.perPage', 10);
        $pages = $this->paginator->paginate($file, $items, $perPage);

        return $pages->map(function ($page) use ($file, $data, $content) {
            return new OutputFile(
                $file->getRelativePath(),
                $file->getFilenameWithoutExtension(),
                'html',
                $this->render(
                    $content->content,
                    new ViewData(
                        $data->put('pagination', $page)
                        ->put('link', $page['pages'][$page['currentPage']])
                    )
                ),
                $data,
                $page['currentPage']
            );
        })->all();
    }

    private function render($bladeContent, $data)
    {
        return $this->temporaryFilesystem->put($bladeContent, function ($path) use ($data) {
            return $this->viewFactory->file($path, ['jigsaw' => $data])->render();
        }, '.blade.php');
    }
}

{'fraction_non_alphanumeric': 0.14808612440191388, 'fraction_numerical': 0.0009569377990430622, 'mean_word_length': 2.401952807160293, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, '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': '1543233', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1185, 'n_words': 212}