Skip to content

Commit

Permalink
template file extension now configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
dxprog committed Oct 28, 2015
1 parent 0938086 commit 19fb6ea
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Dust/Dust.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 19fb6ea

Please sign in to comment.