From 947d8379b901511d0183482eab6bbb489bfb877c Mon Sep 17 00:00:00 2001 From: Jeremy Bush Date: Fri, 20 Aug 2010 09:14:48 -0500 Subject: [PATCH] Fixing #3 --- classes/kohana/kostache.php | 48 ++++++++++++++++++++++--------------- vendor/mustache | 2 +- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/classes/kohana/kostache.php b/classes/kohana/kostache.php index 649e0ab..c005023 100644 --- a/classes/kohana/kostache.php +++ b/classes/kohana/kostache.php @@ -2,6 +2,8 @@ class Kohana_Kostache extends Mustache { + protected $_partials_processed = FALSE; + /** * KOstache class factory constructor. * @@ -119,32 +121,40 @@ class Kohana_Kostache extends Mustache public function render($template = null, $view = null, $partials = null) { - // Override the template location to match kohana's conventions - if ( ! $this->_template) + if (NULL === $template) { - $foo = explode('_', get_class($this)); - array_shift($foo); - $view_location = strtolower(implode('/', $foo)); + // Override the template location to match kohana's conventions + if ( ! $this->_template) + { + $foo = explode('_', get_class($this)); + array_shift($foo); + $view_location = strtolower(implode('/', $foo)); + } + else + { + $view_location = $this->_template; + } + + $this->_template = Kohana::find_file('templates', $view_location, 'mustache'); + + if ( ! $this->_template AND ! $template) + throw new Kohana_Exception('Template file not found: templates/'.$view_location); + + $this->_template = file_get_contents($this->_template); } - else - { - $view_location = $this->_template; - } - - $this->_template = Kohana::find_file('templates', $view_location, 'mustache'); - - if ( ! $this->_template AND ! $template) - throw new Kohana_Exception('Template file not found: templates/'.$view_location); - - $this->_template = file_get_contents($this->_template); // Convert partials to expanded template strings - foreach ($this->_partials as $key => $partial_template) + if ( ! $this->_partials_processed) { - if ($location = Kohana::find_file('templates', $partial_template, 'mustache')) + foreach ($this->_partials as $key => $partial_template) { - $this->_partials[$key] = file_get_contents($location); + if ($location = Kohana::find_file('templates', $partial_template, 'mustache')) + { + $this->_partials[$key] = file_get_contents($location); + } } + + $this->_partials_processed = TRUE; } return parent::render($template, $view, $partials); diff --git a/vendor/mustache b/vendor/mustache index ec562fe..8b1c9c1 160000 --- a/vendor/mustache +++ b/vendor/mustache @@ -1 +1 @@ -Subproject commit ec562fea0916b8d8dedba516d748739a6c126ec0 +Subproject commit 8b1c9c113c4e189923e4874be6fca5be715239ac