<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;

/**
 * Action bar Template Helper
 *
 * @author  <NAME> <https://github.com/johanjanssens>
 * @package Kodekit\Library\Template\Helper
 */
class TemplateHelperActionbar extends TemplateHelperAbstract
{
    /**
     * Render the action bar
     *
     * @param 	array 	$config An optional array with configuration options
     * @return  string  Html
     */
    public function render($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'toolbar' => null,
            'attribs' => array('class' => array('koowa-toolbar'))
        ));

        $html = '';
        if(isset($config->toolbar))
        {
            //Force the id
            $config->attribs['id'] = 'toolbar-'.$config->toolbar->getType();

            $html  = '<div '.$this->buildAttributes($config->attribs).'>';
            $html .= '<div class="button__group">';
            foreach ($config->toolbar as $command)
            {
                $name = $command->getName();

                if(method_exists($this, $name)) {
                    $html .= $this->$name(array('command' => $command));
                } else {
                    $html .= $this->command(array('command' => $command));
                }
            }
            $html .= '</div>';
            $html .= '</div>';
        }

        return $html;
    }

    /**
     * Render a action bar command
     *
     * @param 	array 	$config An optional array with configuration options
     * @return  string  Html
     */
    public function command($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'command' => array('attribs' => array('class' => array('button', 'toolbar')))
        ));

        $translator = $this->getObject('translator');
        $command = $config->command;

        if ($command->allowed === false)
        {
            $command->attribs->title = $translator->translate('You are not allowed to perform this action');
            $command->attribs->class->append(array('disabled', 'unauthorized'));
        }

        //Create the id
        $command->attribs['id'] = 'command-'.$command->id;

        //Add a disabled class if the command is disabled
        if($command->disabled) {
            $command->attribs->class->append(array('nolink'));
        }

        //Create the href
        $command->attribs->append(array('href' => '#'));
        if(!empty($command->href)) {
            $command->attribs['href'] = $this->getTemplate()->route($command->href);
        }

        $html  = '<a '.$this->buildAttributes($command->attribs).'>';
        $html .= ucfirst($translator->translate($command->label));
        $html .= '</a>';

        return $html;
    }

    /**
     * Render a separator
     *
     * @param 	array 	$config An optional array with configuration options
     * @return  string  Html
     */
    public function separator($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'command' => array('attribs' => array('class' => array('button__group')))
        ));

        $command = $config->command;

        $html = '</div><div '.$this->buildAttributes($command->attribs).'>';

        return $html;
    }

    /**
     * Render a dialog button
     *
     * @param 	array 	$config An optional array with configuration options
     * @return  string  Html
     */
    public function dialog($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'command' => NULL
        ));

        $html  = $this->getTemplate()->helper('behavior.modal');
        $html .= $this->command($config);

        return $html;
    }
}
<commit_msg>Issue 51: Inject data into attribs<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;

/**
 * Action bar Template Helper
 *
 * @author  <NAME> <https://github.com/johanjanssens>
 * @package Kodekit\Library\Template\Helper
 */
class TemplateHelperActionbar extends TemplateHelperAbstract
{
    /**
     * Render the action bar
     *
     * @param 	array 	$config An optional array with configuration options
     * @return  string  Html
     */
    public function render($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'toolbar' => null,
            'attribs' => array('class' => array('koowa-toolbar'))
        ));

        $html = '';
        if(isset($config->toolbar))
        {
            //Force the id
            $config->attribs['id'] = 'toolbar-'.$config->toolbar->getType();

            $html  = '<div '.$this->buildAttributes($config->attribs).'>';
            $html .= '<div class="button__group">';
            foreach ($config->toolbar as $command)
            {
                $name = $command->getName();

                if(method_exists($this, $name)) {
                    $html .= $this->$name(ObjectConfig::unbox($command));
                } else {
                    $html .= $this->command(ObjectConfig::unbox($command));
                }
            }
            $html .= '</div>';
            $html .= '</div>';
        }

        return $html;
    }

    /**
     * Render a action bar command
     *
     * @param 	array 	$config An optional array with configuration options
     * @return  string  Html
     */
    public function command($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'id'      => '',
            'href'    => '',
            'allowed' => true,
            'disabled'=> false,
            'data'    => array(),
            'attribs' => array(
                'href'  => '#',
                'class' => array('button', 'toolbar')
            )
        ));

        $translator = $this->getObject('translator');

        if ($config->allowed === false)
        {
            $config->attribs->title = $translator->translate('You are not allowed to perform this action');
            $config->attribs->class->append(array('disabled', 'unauthorized'));
        }

        //Create the id
        $config->attribs['id'] = 'command-'.$config->id;

        //Add a disabled class if the command is disabled
        if($config->disabled) {
            $config->attribs->class->append(array('nolink'));
        }

        //Add the data attributes
        foreach($config->data as $key => $value) {
            $config->attribs['data-'.$key] = (string) $value;
        }

        //Create the href
        if(!empty($config->href)) {
            $config->attribs['href'] = $this->getTemplate()->route($config->href);
        }

        $html  = '<a '.$this->buildAttributes($config->attribs).'>';
        $html .= ucfirst($translator->translate($config->label));
        $html .= '</a>';

        return $html;
    }

    /**
     * Render a separator
     *
     * @param 	array 	$config An optional array with configuration options
     * @return  string  Html
     */
    public function separator($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'attribs' => array('class' => array('button__group'))
        ));

        $html = '</div><div '.$this->buildAttributes($config->attribs).'>';

        return $html;
    }

    /**
     * Render a dialog button
     *
     * @param 	array 	$config An optional array with configuration options
     * @return  string  Html
     */
    public function dialog($config = array())
    {
        $html  = $this->getTemplate()->helper('behavior.modal');
        $html .= $this->command($config);

        return $html;
    }
}

{'fraction_non_alphanumeric': 0.16410564225690277, 'fraction_numerical': 0.00312124849939976, 'mean_word_length': 1.945898161244696, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 143, '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': '4208731', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2341, 'n_words': 507}