<?php namespace TightenCo\Jigsaw;

class PageVariable extends IterableObject
{
    public function addVariables($variables)
    {
        $this->items = collect($this->items)->merge($this->makeIterable($variables))->all();
    }

    public function __call($method, $args)
    {
        $helper = $this->get($method);

        if (! $helper && starts_with($method, 'get')) {
            return $this->_meta->get(camel_case(substr($method, 3)), function () use ($method) {
                throw new \Exception($this->missingHelperError($method));
            });
        }

        if (is_callable($helper)) {
            return $helper->__invoke($this, ...$args);
        } else {
            throw new \Exception($this->missingHelperError($method));
        }
    }

    public function getPath($key = null)
    {
        if (($key || $this->_meta->extending) && $this->_meta->path instanceof IterableObject) {
            return $this->_meta->path->get($key ?: $this->getExtending());
        }
    }

    public function getUrl($key = null)
    {
        if (($key || $this->_meta->extending) && $this->_meta->path instanceof IterableObject) {
            return $this->_meta->url->get($key ?: $this->getExtending());
        }
    }

    protected function missingHelperError($functionName)
    {
        return 'No function named "' . $functionName . '" was found in the file "config.php".';
    }
}

<?php namespace TightenCo\Jigsaw;

class PageVariable extends IterableObject
{
    public function addVariables($variables)
    {
        $this->items = collect($this->items)->merge($this->makeIterable($variables))->all();
    }

    public function __call($method, $args)
    {
        $helper = $this->get($method);

        if (! $helper && starts_with($method, 'get')) {
            return $this->_meta->get(camel_case(substr($method, 3)), function () use ($method) {
                throw new \Exception($this->missingHelperError($method));
            });
        }

        if (is_callable($helper)) {
            return $helper->__invoke($this, ...$args);
        } else {
            throw new \Exception($this->missingHelperError($method));
        }
    }

    public function getPath($key = null)
    {
        if (($key || $this->_meta->extending) && $this->_meta->path instanceof IterableObject) {
            return $this->_meta->path->get($key ?: $this->getExtending());
        }

        return $this->_meta->path;
    }

    public function getUrl($key = null)
    {
        if (($key || $this->_meta->extending) && $this->_meta->path instanceof IterableObject) {
            return $this->_meta->url->get($key ?: $this->getExtending());
        }

        return $this->_meta->url;
    }

    protected function missingHelperError($functionName)
    {
        return 'No function named "' . $functionName . '" was found in the file "config.php".';
    }
}

Fix getPath and getUrl for markdown pages that extend multiple templates
Fix getPath and getUrl for markdown pages that extend multiple templates
