From 19fb6eac2195fa1a93cab26633c6a9fe86a558d8 Mon Sep 17 00:00:00 2001 From: Matt Hackmann Date: Tue, 27 Oct 2015 20:00:28 -0700 Subject: [PATCH] template file extension now configurable --- src/Dust/Dust.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/Dust/Dust.php diff --git a/src/Dust/Dust.php b/src/Dust/Dust.php old mode 100644 new mode 100755 index a051b55..92b7279 --- a/src/Dust/Dust.php +++ b/src/Dust/Dust.php @@ -18,7 +18,10 @@ class Dust implements \Serializable { public $autoloaderOverride; - public function __construct($parser = null, $evaluator = null) { + // Default template extension + private $_extension = 'dust'; + + public function __construct($parser = null, $evaluator = null, $options = null) { if ($parser === null) $parser = new Parse\Parser(); if ($evaluator === null) $evaluator = new Evaluate\Evaluator($this); $this->parser = $parser; @@ -47,6 +50,14 @@ public function __construct($parser = null, $evaluator = null) { "contextDump" => new Helper\ContextDump() ]; $this->automaticFilters = [$this->filters['h']]; + + if (is_array($options)) { + if (isset($options['extension'])) { + $extension = $options['extension']; + $this->_extension = $extension{0} === '.' ? substr($extension, 1) : $extension; + } + } + } public function compile($source, $name = null) { @@ -62,7 +73,10 @@ public function compileFn($source, $name = null) { public function resolveAbsoluteDustFilePath($path, $basePath = null) { //add extension if necessary - if (substr_compare($path, '.dust', -5, 5) !== 0) $path .= '.dust'; + $ext = explode('.', $path); + if (end($ext) !== $this->_extension) { + $path .= '.' . $this->_extension; + } if ($basePath != null) { $possible = realpath($basePath . '/' . $path); if ($possible !== false) return $possible;