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
|
* @copyright (c) 2011-2012 Woody Gilk
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
abstract class Kohana_Kostache {
|
class Kohana_Kostache {
|
||||||
|
|
||||||
const VERSION = '4.0.0';
|
const VERSION = '4.0.0';
|
||||||
|
|
||||||
public static function engine($template_name)
|
protected $_engine;
|
||||||
|
|
||||||
|
public static function factory()
|
||||||
{
|
{
|
||||||
$m = new Mustache_Engine(
|
$m = new Mustache_Engine(
|
||||||
array(
|
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.');
|
<?php defined('SYSPATH') or die('No direct script access.');
|
||||||
|
|
||||||
abstract class Kostache extends Kohana_Kostache { }
|
class Kostache extends Kohana_Kostache { }
|
||||||
|
|
Loading…
Reference in a new issue