Skip to content

Commit

Permalink
Allow specifying alternate suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 30, 2010
1 parent fcfa41e commit 95ec004
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions .project
Expand Up @@ -48,6 +48,7 @@ mustache=/home/matthew/git/phly_mustache CD=. filter="*.php *.html *.xml *.txt"
ViewWithTraversableObject.php
}
templates=templates filter="*.mustache" {
alternate-suffix.html
partial-template.mustache
renders-file-templates.mustache
template-with-aliased-partial.mustache
Expand Down
1 change: 0 additions & 1 deletion TODO
@@ -1,4 +1,3 @@
Allow specifying a template suffix
API documentation
Tests
for comments
Expand Down
27 changes: 26 additions & 1 deletion library/Phly/Mustache/Mustache.php
Expand Up @@ -26,6 +26,9 @@ class Mustache
/** @var Renderer */
protected $renderer;

/** @var string Suffix used when resolving templates */
protected $suffix = '.mustache';

/**
* Constructor
*
Expand Down Expand Up @@ -104,6 +107,28 @@ public function setTemplatePath($path)
return $this;
}

/**
* Set suffix used when resolving templates
*
* @param string $suffix
* @return Mustache
*/
public function setSuffix($suffix)
{
$this->suffix = '.' . ltrim($suffix, '.');
return $this;
}

/**
* Get template suffix
*
* @return string
*/
public function getSuffix()
{
return $this->suffix;
}

/**
* Render a template using a view, and optionally a list of partials
*
Expand Down Expand Up @@ -174,7 +199,7 @@ public function tokenize($template)
protected function fetchTemplate($template)
{
foreach ($this->templatePath as $path) {
$file = $path . DIRECTORY_SEPARATOR . $template . '.mustache';
$file = $path . DIRECTORY_SEPARATOR . $template . $this->getSuffix();
if (file_exists($file)) {
$content = file_get_contents($file);
$this->cachedTemplates[$template] = $content;
Expand Down
7 changes: 7 additions & 0 deletions tests/PhlyTest/Mustache/MustacheTest.php
Expand Up @@ -332,4 +332,11 @@ public function testHonorsImplicitIteratorPragma()
EOT;
$this->assertEquals($expected, $test);
}

public function testAllowsSettingAlternateTemplateSuffix()
{
$this->mustache->setSuffix('html');
$test = $this->mustache->render('alternate-suffix', array());
$this->assertContains('alternate template suffix', $test);
}
}
1 change: 1 addition & 0 deletions tests/PhlyTest/Mustache/templates/alternate-suffix.html
@@ -0,0 +1 @@
alternate template suffix

0 comments on commit 95ec004

Please sign in to comment.