Refactor main class to not require template explicitly
This commit is contained in:
parent
d01a2b3ff5
commit
b6e1c6e7d8
|
@ -10,11 +10,13 @@
|
|||
* @copyright (c) 2011-2012 Woody Gilk
|
||||
* @license MIT
|
||||
*/
|
||||
abstract class Kohana_Kostache {
|
||||
class Kohana_Kostache {
|
||||
|
||||
const VERSION = '4.0.0';
|
||||
|
||||
public static function engine($template_name)
|
||||
protected $_engine;
|
||||
|
||||
public static function factory()
|
||||
{
|
||||
$m = new Mustache_Engine(
|
||||
array(
|
||||
|
@ -26,6 +28,23 @@ abstract class Kohana_Kostache {
|
|||
)
|
||||
);
|
||||
|
||||
return $m->loadTemplate($template_name);
|
||||
return new self($m);
|
||||
}
|
||||
|
||||
public function __construct($engine)
|
||||
{
|
||||
$this->_engine = $engine;
|
||||
}
|
||||
|
||||
public function render($class, $template = NULL)
|
||||
{
|
||||
if ($template == NULL)
|
||||
{
|
||||
$template = explode('_', get_class($class));
|
||||
array_shift($template);
|
||||
$template = implode('/', $template);
|
||||
}
|
||||
|
||||
return $this->_engine->loadTemplate($template)->render($class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
abstract class Kostache extends Kohana_Kostache { }
|
||||
class Kostache extends Kohana_Kostache { }
|
||||
|
|
Loading…
Reference in New Issue