kostache/classes/Kohana/Kostache.php

61 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?php defined('SYSPATH') or die('No direct script access.');
2019-06-17 15:30:29 +03:00
require_once __DIR__.'/../../vendor/autoload.php';
/**
* 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
* @license MIT
*/
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
protected $_engine;
public static function factory()
{
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) {
return HTML::chars($value);
2012-10-24 02:17:02 +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);
}
public function __construct($engine)
{
$this->_engine = $engine;
}
public function render($class, $template = NULL)
{
if ($template == NULL)
{
$template = $this->_detect_template_path($class);
}
return $this->_engine->loadTemplate($template)->render($class);
}
protected function _detect_template_path($class)
{
$path = explode('_', get_class($class));
array_shift($path);
return implode('/', $path);
}
}