<commit_before><?php
namespace Grav\Plugin;

use Grav\Common\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use RocketTheme\Toolbox\Event\Event;

class SmartypantsPlugin extends Plugin
{
    /**
     * @var SmartypantsPlugin
     */

    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return [
            'onPluginsInitialized' => ['onPluginsInitialized', 0]
        ];
    }

    /**
     * Initialize configuration
     */
    public function onPluginsInitialized()
    {
        if ($this->isAdmin()) {
            $this->active = false;
            return;
        }

        require_once(__DIR__.'/vendor/Michelf/SmartyPants.php');
        $this->enable([
            'onPageProcessed' => ['onPageProcessed', 0],
            'onPageContentProcessed' => ['onPageContentProcessed', 0],
            'onTwigExtensions' => ['onTwigExtensions', 0]
        ]);
    }

    /**
     * Apply smartypants to title
     */
    public function onPageProcessed(Event $event)
    {
        $page = $event['page'];
        $this->mergeConfig($page);

        if ($this->config->get('plugins.smartypants.process_title')) {
            $page->title(\Michelf\SmartyPants::defaultTransform(
                $page->title(),
                $this->config->get('plugins.smartypants.options')
            ));
        }
    }

    /**
     * Apply smartypants to content
     */
    public function onPageContentProcessed(Event $event)
    {
        $page = $event['page'];
        $this->mergeConfig($page);

        if ($this->config->get('plugins.smartypants.process_content')) {
            $page->setRawContent(\Michelf\SmartyPants::defaultTransform(
                $page->getRawContent(),
                $this->config->get('plugins.smartypants.options')
            ));
        }
    }

    /**
     * Add Twig Extensions
     */
    public function onTwigExtensions()
    {
        if (!$this->config->get('plugins.smartypants.twig_filter')) {
            return;
        }

        require_once(__DIR__.'/twig/SmartyPantsTwigExtension.php');
        $this->grav['twig']->twig->addExtension(new SmartyPantsTwigExtension());
    }

    protected function mergeConfig(Page $page)
    {
        $defaults = (array) $this->config->get('plugins.smartypants');
        if (isset($page->header()->smartypants)) {
            $this->config->set('plugins.smartypants', array_merge($defaults, $page->header()->smartypants));
        }
    }
}<commit_msg>updated to take advantage of the new mergeConfig() method in the base Plugin class<commit_after><?php
namespace Grav\Plugin;

use Grav\Common\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use RocketTheme\Toolbox\Event\Event;

class SmartypantsPlugin extends Plugin
{
    /**
     * @var SmartypantsPlugin
     */

    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return [
            'onPluginsInitialized' => ['onPluginsInitialized', 0]
        ];
    }

    /**
     * Initialize configuration
     */
    public function onPluginsInitialized()
    {
        if ($this->isAdmin()) {
            $this->active = false;
            return;
        }

        require_once(__DIR__.'/vendor/Michelf/SmartyPants.php');
        $this->enable([
            'onTwigExtensions' => ['onTwigExtensions', 0],
            'onPageProcessed' => ['onPageProcessed', 0],
            'onPageContentProcessed' => ['onPageContentProcessed', 0]
        ]);
    }

    /**
     * Add Twig Extensions
     */
    public function onTwigExtensions()
    {
        if (!$this->config->get('plugins.smartypants.twig_filter')) {
            return;
        }

        require_once(__DIR__.'/twig/SmartyPantsTwigExtension.php');
        $this->grav['twig']->twig->addExtension(new SmartyPantsTwigExtension());
    }

    /**
     * Apply smartypants to title
     */
    public function onPageProcessed(Event $event)
    {
        $page = $event['page'];
        $config = $this->mergeConfig($page);

        if ($config->get('process_title')) {
            $page->title(\Michelf\SmartyPants::defaultTransform(
                $page->title(),
                $config->get('options')
            ));
        }
    }

    /**
     * Apply smartypants to content
     */
    public function onPageContentProcessed(Event $event)
    {
        $page = $event['page'];
        $config = $this->mergeConfig($page);

        if ($config->get('process_content')) {
            $page->setRawContent(\Michelf\SmartyPants::defaultTransform(
                $page->getRawContent(),
                $config->get('options')
            ));
        }
    }
}
{'fraction_non_alphanumeric': 0.145610278372591, 'fraction_numerical': 0.0017130620985010706, 'mean_word_length': 2.101593625498008, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '1496083', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1344, 'n_words': 211}