diff --git a/classes/Kohana/Kostache.php b/classes/Kohana/Kostache.php index 41f7cee..dba10d9 100644 --- a/classes/Kohana/Kostache.php +++ b/classes/Kohana/Kostache.php @@ -5,9 +5,7 @@ * @package Kostache * @category Base * @author Jeremy Bush - * @author Woody Gilk * @copyright (c) 2010-2012 Jeremy Bush - * @copyright (c) 2011-2012 Woody Gilk * @license MIT */ class Kohana_Kostache { @@ -29,7 +27,8 @@ class Kohana_Kostache { ) ); - return new self($m); + $class = get_called_class(); + return new $class($m); } public function __construct($engine) diff --git a/classes/Kohana/Kostache/Layout.php b/classes/Kohana/Kostache/Layout.php index 1b8a7d2..cf67bec 100644 --- a/classes/Kohana/Kostache/Layout.php +++ b/classes/Kohana/Kostache/Layout.php @@ -5,12 +5,10 @@ * @package Kostache * @category Base * @author Jeremy Bush - * @author Woody Gilk * @copyright (c) 2010-2012 Jeremy Bush - * @copyright (c) 2011-2012 Woody Gilk * @license MIT */ -abstract class Kohana_Kostache_Layout extends Kostache { +class Kohana_Kostache_Layout extends Kohana_Kostache { /** * @var string partial name for content @@ -27,20 +25,20 @@ abstract class Kohana_Kostache_Layout extends Kostache { */ protected $_layout = 'layout'; - public function render() + public function render($class, $template = NULL) { if ( ! $this->render_layout) { return parent::render(); } - $partials = $this->_partials; + $this->_engine->setPartials( + array( + Kostache_Layout::CONTENT_PARTIAL => parent::render($class, $template) + ) + ); - $partials[Kostache_Layout::CONTENT_PARTIAL] = $this->_template; - - $template = $this->_load($this->_layout); - - return $this->_stash($template, $this, $partials)->render(); + return $this->_engine->loadTemplate($this->_layout)->render($class); } } diff --git a/classes/Kostache/Layout.php b/classes/Kostache/Layout.php index 7feeb1d..93df875 100644 --- a/classes/Kostache/Layout.php +++ b/classes/Kostache/Layout.php @@ -1,3 +1,3 @@ _base_dir, $name, $this->_extension); return file_get_contents($filename); } + + /** + * Set an associative array of Template sources for this loader. + * + * @param array $templates + */ + public function setTemplates(array $templates) + { + $this->_templates = array_merge($this->_templates, $templates); + } + + /** + * Set a Template source by name. + * + * @param string $name + * @param string $template Mustache Template source + */ + public function setTemplate($name, $template) + { + $this->_templates[$name] = $template; + } }