protected function compileMixins()
    {

        if (count($this->mixins) < 1)
            return '';

        $phtml = '';
        $phtml .= $this->createCode('$__mixins = [];').$this->newLine();

        foreach ($this->mixins as $name => $mixin) {

            //Don't compile the mixin if we dont use it (opt-out)
            if (!$this->options['compile_uncalled_mixins'] && !in_array($name, $this->calledMixins, true))
                continue; //Skip compilation

            //Put the arguments together
            $args = [];
            $i = 0;
            $variadicIndex = null;
            $variadicName = null;
            foreach ($mixin['node']->attributes as $attr) {

                $attrName = $attr->name;
                if (strncmp('...', $attrName, 3) === 0) {

                    $variadicIndex = $i;
                    $attrName = substr($attrName, 3);
                    $variadicName = $attrName;
                }
                $args[$attrName] = $attr->value;
                $i++;
            }

            if ($variadicIndex !== null) {

                $args[$variadicName] = "array_slice(\$__arguments, $variadicIndex)";
            }

            $phtml .= $this->createCode(
                    '$__mixins[\''.$name.'\'] = function(array $__arguments, array $__scope) {'.
                        '$__defaults = '.$this->exportArray($args).'; '.
                        'if (is_numeric(key($__arguments))) extract(array_replace($__scope, array_combine('.
                            'array_keys($__defaults), array_replace(array_values($__defaults)'.
                            ', array_values($__arguments)))));'.
                        'else extract(array_replace($__scope, array_replace($__defaults, $__arguments)));
                    '
                ).$this->newLine();

            $phtml .= $mixin['phtml'].$this->newLine();
            $phtml .= $this->createCode('};').$this->newLine();
        }

        return $phtml;
    }