1
0
Fork 0

Refactor main class to not require template explicitly

This commit is contained in:
Jeremy Bush 2012-10-23 22:46:59 -05:00
parent d01a2b3ff5
commit b6e1c6e7d8
2 changed files with 23 additions and 4 deletions

View File

@ -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);
}
}

View File

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