<commit_before><?php
/**
 * Kodekit - http://timble.net/kodekit
 *
 * @copyright   Copyright (C) 2007 - 2016 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license     MPL v2.0 <https://www.mozilla.org/en-US/MPL/2.0>
 * @link        https://github.com/timble/kodekit for the canonical source repository
 */

namespace Kodekit\Library;

/**
 * Abstract Template View
 *
 * @author  <NAME> <https://github.com/johanjanssens>
 * @package Kodekit\Library\View
 */
abstract class ViewTemplate extends ViewAbstract  implements ViewTemplatable
{
    /**
     * Template identifier (com://APP/COMPONENT.template.NAME)
     *
     * @var string|object
     */
    protected $_template;

    /**
     * Layout name
     *
     * @var string
     */
    protected $_layout;

    /**
     * Auto assign
     *
     * @var boolean
     */
    protected $_auto_fetch;

    /**
     * Constructor
     *
     * @param   ObjectConfig $config Configuration options
     */
    public function __construct(ObjectConfig $config)
    {
        parent::__construct($config);

        //Set the auto fetch
        $this->_auto_fetch = $config->auto_fetch;

        //Set the layout
        $this->setLayout($config->layout);

        //Set the template object
        $this->setTemplate($config->template);
    }

    /**
     * Initializes the config for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   ObjectConfig $config Configuration options
     * @return  void
     */
    protected function _initialize(ObjectConfig $config)
    {
        $config->append(array(
            'auto_fetch'         => true,
            'layout'             => '',
            'template'           => 'default',
            'template_filters'   => array('asset'),
            'template_functions' => array(
                'route'    => array($this, 'getRoute'),
                'url'      => array($this, 'getUrl'),
                'title'    => array($this, 'getTitle'),
                'content'  => array($this, 'getContent'),
            ),
        ));

        parent::_initialize($config);
    }

    /**
     * Return the views output
     *
     * @param ViewContext  $context A view context object
     * @return string  The output of the view
     */
    protected function _actionRender(ViewContext $context)
    {
        $data   = ObjectConfig::unbox($context->data);
        $path   = $this->qualifyLayout($context->layout);

        //Render the template
        $this->_content = $this->getTemplate()
            ->loadFile($path)
            ->setParameters($context->parameters)
            ->render($data);

        return parent::_actionRender($context);
    }

    /**
     * Fetch the view data
     *
     * This function will always fetch the model state. Model data will only be fetched if the auto_fetch property is
     * set to TRUE.<commit_msg>Issue #62: Add 'language' template function<commit_after><?php
/**
 * Kodekit - http://timble.net/kodekit
 *
 * @copyright   Copyright (C) 2007 - 2016 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license     MPL v2.0 <https://www.mozilla.org/en-US/MPL/2.0>
 * @link        https://github.com/timble/kodekit for the canonical source repository
 */

namespace Kodekit\Library;

/**
 * Abstract Template View
 *
 * @author  <NAME> <https://github.com/johanjanssens>
 * @package Kodekit\Library\View
 */
abstract class ViewTemplate extends ViewAbstract  implements ViewTemplatable
{
    /**
     * Template identifier (com://APP/COMPONENT.template.NAME)
     *
     * @var string|object
     */
    protected $_template;

    /**
     * Layout name
     *
     * @var string
     */
    protected $_layout;

    /**
     * Auto assign
     *
     * @var boolean
     */
    protected $_auto_fetch;

    /**
     * Constructor
     *
     * @param   ObjectConfig $config Configuration options
     */
    public function __construct(ObjectConfig $config)
    {
        parent::__construct($config);

        //Set the auto fetch
        $this->_auto_fetch = $config->auto_fetch;

        //Set the layout
        $this->setLayout($config->layout);

        //Set the template object
        $this->setTemplate($config->template);
    }

    /**
     * Initializes the config for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param   ObjectConfig $config Configuration options
     * @return  void
     */
    protected function _initialize(ObjectConfig $config)
    {
        $config->append(array(
            'auto_fetch'         => true,
            'layout'             => '',
            'template'           => 'default',
            'template_filters'   => array('asset'),
            'template_functions' => array(
                'route'    => array($this, 'getRoute'),
                'url'      => array($this, 'getUrl'),
                'title'    => array($this, 'getTitle'),
                'content'  => array($this, 'getContent'),
                'language' => array($this, 'getLanguage')
            ),
        ));

        parent::_initialize($config);
    }

    /**
     * Return the views output
     *
     * @param ViewContext  $context A view context object
     * @return string  The output of the view
     */
    protected function _actionRender(ViewContext $context)
    {
        $data   = ObjectConfig::unbox($context->data);
        $path   = $this->qualifyLayout($context->layout);

        //Render the template
        $this->_content = $this->getTemplate()
            ->loadFile($path)
            ->setParameters($context->parameters)
            ->render($data);

        return parent::_actionRender($context);
    }

    /**
     * Fetch the view data
     *
     * This function will always fetch the model state. Model data will only be fetched if the auto_fetch property is
     * set to TRUE.
{'fraction_non_alphanumeric': 0.12926088423894702, 'fraction_numerical': 0.004387445156935539, 'mean_word_length': 1.9843907351460222, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 62, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, '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': '1320335', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1634, 'n_words': 405}