Add factory method to layout class, lets you pass a custom layout into the class

This commit is contained in:
Jeremy Bush 2012-10-31 22:09:32 -05:00
parent b8c530249f
commit 4748c07be2
2 changed files with 10 additions and 5 deletions

View file

@ -14,7 +14,7 @@ class Kohana_Kostache {
protected $_engine; protected $_engine;
public static function factory($cache = FALSE) public static function factory()
{ {
$m = new Mustache_Engine( $m = new Mustache_Engine(
array( array(
@ -23,7 +23,7 @@ class Kohana_Kostache {
'escape' => function($value) { 'escape' => function($value) {
return html::chars($value); return html::chars($value);
}, },
'cache' => $cache ? APPPATH.'cache/mustache' : NULL, 'cache' => APPPATH.'cache/mustache',
) )
); );

View file

@ -20,11 +20,16 @@ class Kohana_Kostache_Layout extends Kohana_Kostache {
*/ */
protected $_layout = 'layout'; protected $_layout = 'layout';
public function __construct($engine, $layout = 'layout') public static function factory($layout = 'layout')
{ {
$this->_layout = $layout; $k = parent::factory();
$k->set_layout($layout);
return $k;
}
parent::__construct($engine); public function set_layout($layout)
{
$this->_layout = (string) $layout;
} }
public function render($class, $template = NULL) public function render($class, $template = NULL)