Add Kostache_Layout class
This commit is contained in:
parent
559e60b928
commit
b61870b811
|
@ -5,9 +5,7 @@
|
||||||
* @package Kostache
|
* @package Kostache
|
||||||
* @category Base
|
* @category Base
|
||||||
* @author Jeremy Bush <jeremy.bush@kohanaframework.org>
|
* @author Jeremy Bush <jeremy.bush@kohanaframework.org>
|
||||||
* @author Woody Gilk <woody.gilk@kohanaframework.org>
|
|
||||||
* @copyright (c) 2010-2012 Jeremy Bush
|
* @copyright (c) 2010-2012 Jeremy Bush
|
||||||
* @copyright (c) 2011-2012 Woody Gilk
|
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
class Kohana_Kostache {
|
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)
|
public function __construct($engine)
|
||||||
|
|
|
@ -5,12 +5,10 @@
|
||||||
* @package Kostache
|
* @package Kostache
|
||||||
* @category Base
|
* @category Base
|
||||||
* @author Jeremy Bush <jeremy.bush@kohanaframework.org>
|
* @author Jeremy Bush <jeremy.bush@kohanaframework.org>
|
||||||
* @author Woody Gilk <woody.gilk@kohanaframework.org>
|
|
||||||
* @copyright (c) 2010-2012 Jeremy Bush
|
* @copyright (c) 2010-2012 Jeremy Bush
|
||||||
* @copyright (c) 2011-2012 Woody Gilk
|
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
abstract class Kohana_Kostache_Layout extends Kostache {
|
class Kohana_Kostache_Layout extends Kohana_Kostache {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string partial name for content
|
* @var string partial name for content
|
||||||
|
@ -27,20 +25,20 @@ abstract class Kohana_Kostache_Layout extends Kostache {
|
||||||
*/
|
*/
|
||||||
protected $_layout = 'layout';
|
protected $_layout = 'layout';
|
||||||
|
|
||||||
public function render()
|
public function render($class, $template = NULL)
|
||||||
{
|
{
|
||||||
if ( ! $this->render_layout)
|
if ( ! $this->render_layout)
|
||||||
{
|
{
|
||||||
return parent::render();
|
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;
|
return $this->_engine->loadTemplate($this->_layout)->render($class);
|
||||||
|
|
||||||
$template = $this->_load($this->_layout);
|
|
||||||
|
|
||||||
return $this->_stash($template, $this, $partials)->render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<?php defined('SYSPATH') or die('No direct script access.');
|
<?php defined('SYSPATH') or die('No direct script access.');
|
||||||
|
|
||||||
abstract class Kostache_Layout extends Kohana_Kostache_Layout { }
|
class Kostache_Layout extends Kohana_Kostache_Layout { }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Mustache_Loader_Kohana implements Mustache_Loader
|
class Mustache_Loader_Kohana implements Mustache_Loader, Mustache_Loader_MutableLoader
|
||||||
{
|
{
|
||||||
private $_base_dir = 'templates';
|
private $_base_dir = 'templates';
|
||||||
private $_extension = 'mustache';
|
private $_extension = 'mustache';
|
||||||
|
@ -32,4 +32,25 @@ class Mustache_Loader_Kohana implements Mustache_Loader
|
||||||
$filename = Kohana::find_file($this->_base_dir, $name, $this->_extension);
|
$filename = Kohana::find_file($this->_base_dir, $name, $this->_extension);
|
||||||
return file_get_contents($filename);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue