FileSystemLoader accepts option for a file prefix

This makes it easy to use the convention of prefixing partials with underscores.
This commit is contained in:
Joey Baker 2013-02-26 11:22:54 -08:00
parent 3d8685f179
commit eba64322c5

View File

@ -31,6 +31,7 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader
{ {
private $_baseDir; private $_baseDir;
private $_extension = '.handlebars'; private $_extension = '.handlebars';
private $_prefix = '';
private $_templates = array(); private $_templates = array();
/** /**
@ -59,6 +60,10 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader
if (isset($options['extension'])) { if (isset($options['extension'])) {
$this->_extension = '.' . ltrim($options['extension'], '.'); $this->_extension = '.' . ltrim($options['extension'], '.');
} }
if (isset($options['prefix'])) {
$this->_prefix = $options['prefix'];
}
} }
/** /**
@ -108,7 +113,14 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader
*/ */
protected function getFileName($name) protected function getFileName($name)
{ {
$fileName = $this->_baseDir . '/' . $name; $fileName = $this->_baseDir . '/';
if (substr($name, strlen($this->_prefix)) !== $this->_prefix){
$fileName .= $this->_prefix;
}
$fileName .= $name;
if (substr($fileName, 0 - strlen($this->_extension)) !== $this->_extension) { if (substr($fileName, 0 - strlen($this->_extension)) !== $this->_extension) {
$fileName .= $this->_extension; $fileName .= $this->_extension;
} }