|
|
@@ -20,6 +20,16 @@ class HandlebarMustache extends Mustache {
|
|
|
*/
|
|
|
protected $templateBase;
|
|
|
|
|
|
+ /**
|
|
|
+ * templateName.
|
|
|
+ *
|
|
|
+ * If none is specified, this will default to an underscorified version of the class name.
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ * @access protected
|
|
|
+ */
|
|
|
+ protected $templateName;
|
|
|
+
|
|
|
/**
|
|
|
* HandlebarMustache class constructor.
|
|
|
*
|
|
|
@@ -36,6 +46,11 @@ class HandlebarMustache extends Mustache {
|
|
|
if (!isset($this->templateBase)) {
|
|
|
$this->setTemplateBase(dirname(__FILE__));
|
|
|
}
|
|
|
+
|
|
|
+ // default template name is the underscorified class name.
|
|
|
+ if (!isset($this->templateName)) {
|
|
|
+ $this->templateName = strtolower(preg_replace('#(?<!^)([A-Z]+)#', '_\1', get_class($this)));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -52,6 +67,17 @@ class HandlebarMustache extends Mustache {
|
|
|
$this->templateBase = $dir;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Override the default templateName.
|
|
|
+ *
|
|
|
+ * @access public
|
|
|
+ * @param string $name
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function setTemplateName($name) {
|
|
|
+ $this->templateName = $name;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Load a template file. This file will be relative to $this->templateBase.
|
|
|
* A '.mustache' file extension is assumed if none is provided in $file.
|
|
|
@@ -108,4 +134,24 @@ class HandlebarMustache extends Mustache {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Render the given template and view object.
|
|
|
+ *
|
|
|
+ * Defaults to the template and view passed to the class constructor unless a new one is provided.
|
|
|
+ * Optionally, pass an associative array of partials as well.
|
|
|
+ *
|
|
|
+ * @access public
|
|
|
+ * @param string $template (default: null)
|
|
|
+ * @param mixed $view (default: null)
|
|
|
+ * @param array $partials (default: null)
|
|
|
+ * @return string Rendered Mustache template.
|
|
|
+ */
|
|
|
+ public function render($template = null, $view = null, $partials = null) {
|
|
|
+ if ($template === null && !isset($this->template)) {
|
|
|
+ $this->loadTemplate($this->templateName);
|
|
|
+ }
|
|
|
+
|
|
|
+ return parent::render($template, $view, $partials);
|
|
|
+ }
|
|
|
}
|