2011-02-25 00:45:29 +02:00
|
|
|
<?php defined('SYSPATH') or die('No direct script access.');
|
2019-06-17 15:30:29 +03:00
|
|
|
require_once __DIR__.'/../../vendor/autoload.php';
|
2011-02-25 18:00:48 +02:00
|
|
|
/**
|
|
|
|
* Mustache templates for Kohana.
|
|
|
|
*
|
|
|
|
* @package Kostache
|
|
|
|
* @category Base
|
|
|
|
* @author Jeremy Bush <jeremy.bush@kohanaframework.org>
|
2014-05-08 17:51:49 +03:00
|
|
|
* @author Woody Gilk <woody.gilk@kohanaframework.org>
|
2012-01-09 03:12:53 +02:00
|
|
|
* @copyright (c) 2010-2012 Jeremy Bush
|
2014-05-08 17:51:49 +03:00
|
|
|
* @copyright (c) 2012-2014 Woody Gilk
|
2011-02-25 18:00:48 +02:00
|
|
|
* @license MIT
|
|
|
|
*/
|
2012-10-24 06:46:59 +03:00
|
|
|
class Kohana_Kostache {
|
2010-12-09 21:05:25 +02:00
|
|
|
|
2014-05-08 17:51:49 +03:00
|
|
|
const VERSION = '4.0.3';
|
2010-08-20 17:14:48 +03:00
|
|
|
|
2012-10-24 06:46:59 +03:00
|
|
|
protected $_engine;
|
|
|
|
|
2012-11-01 05:09:32 +02:00
|
|
|
public static function factory()
|
2010-07-15 02:13:55 +03:00
|
|
|
{
|
2012-10-24 02:17:02 +03:00
|
|
|
$m = new Mustache_Engine(
|
|
|
|
array(
|
|
|
|
'loader' => new Mustache_Loader_Kohana(),
|
|
|
|
'partials_loader' => new Mustache_Loader_Kohana('templates/partials'),
|
|
|
|
'escape' => function($value) {
|
2012-11-05 14:32:21 +02:00
|
|
|
return HTML::chars($value);
|
2012-10-24 02:17:02 +03:00
|
|
|
},
|
2014-04-05 18:38:48 +03:00
|
|
|
'cache' => Kohana::$cache_dir.DIRECTORY_SEPARATOR.'mustache',
|
2012-10-24 02:17:02 +03:00
|
|
|
)
|
|
|
|
);
|
2012-10-24 06:22:15 +03:00
|
|
|
|
2012-11-01 03:35:08 +02:00
|
|
|
$class = get_called_class();
|
|
|
|
return new $class($m);
|
2012-10-24 06:46:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function __construct($engine)
|
|
|
|
{
|
|
|
|
$this->_engine = $engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render($class, $template = NULL)
|
|
|
|
{
|
|
|
|
if ($template == NULL)
|
|
|
|
{
|
2013-03-16 01:24:02 +02:00
|
|
|
$template = $this->_detect_template_path($class);
|
2012-10-24 06:46:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_engine->loadTemplate($template)->render($class);
|
2011-02-25 00:45:29 +02:00
|
|
|
}
|
2013-03-16 01:24:02 +02:00
|
|
|
|
|
|
|
protected function _detect_template_path($class)
|
|
|
|
{
|
|
|
|
$path = explode('_', get_class($class));
|
|
|
|
array_shift($path);
|
|
|
|
|
|
|
|
return implode('/', $path);
|
|
|
|
}
|
|
|
|
|
2010-07-15 02:13:55 +03:00
|
|
|
}
|