Add Kostache_Layout class

This commit is contained in:
Jeremy Bush 2012-10-31 20:35:08 -05:00
parent 559e60b928
commit b61870b811
4 changed files with 33 additions and 15 deletions

View file

@ -5,9 +5,7 @@
* @package Kostache
* @category Base
* @author Jeremy Bush <jeremy.bush@kohanaframework.org>
* @author Woody Gilk <woody.gilk@kohanaframework.org>
* @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)

View file

@ -5,12 +5,10 @@
* @package Kostache
* @category Base
* @author Jeremy Bush <jeremy.bush@kohanaframework.org>
* @author Woody Gilk <woody.gilk@kohanaframework.org>
* @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);
}
}

View file

@ -1,3 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
abstract class Kostache_Layout extends Kohana_Kostache_Layout { }
class Kostache_Layout extends Kohana_Kostache_Layout { }

View file

@ -1,6 +1,6 @@
<?php
class Mustache_Loader_Kohana implements Mustache_Loader
class Mustache_Loader_Kohana implements Mustache_Loader, Mustache_Loader_MutableLoader
{
private $_base_dir = 'templates';
private $_extension = 'mustache';
@ -32,4 +32,25 @@ class Mustache_Loader_Kohana implements Mustache_Loader
$filename = Kohana::find_file($this->_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;
}
}