diff --git a/CONTRIBUTING.markdown b/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.markdown rename to CONTRIBUTING.md diff --git a/README.markdown b/README.md similarity index 100% rename from README.markdown rename to README.md diff --git a/composer.json b/composer.json index ebf9541..2969d03 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,9 @@ "require": { "php": ">=5.2.4" }, + "require-dev": { + "phpunit/phpunit": "*" + }, "autoload": { "psr-0": { "Mustache": "src/" } } diff --git a/src/Mustache/Autoloader.php b/src/Mustache/Autoloader.php index df48536..2a209dd 100644 --- a/src/Mustache/Autoloader.php +++ b/src/Mustache/Autoloader.php @@ -25,9 +25,15 @@ class Mustache_Autoloader public function __construct($baseDir = null) { if ($baseDir === null) { - $this->baseDir = dirname(__FILE__).'/..'; + $baseDir = dirname(__FILE__).'/..'; + } + + // realpath doesn't always work, for example, with stream URIs + $realDir = realpath($baseDir); + if (is_dir($realDir)) { + $this->baseDir = $realDir; } else { - $this->baseDir = rtrim($baseDir, '/'); + $this->baseDir = $baseDir; } } diff --git a/src/Mustache/Compiler.php b/src/Mustache/Compiler.php index 437ea2c..a30e6f5 100644 --- a/src/Mustache/Compiler.php +++ b/src/Mustache/Compiler.php @@ -189,7 +189,7 @@ class Mustache_Compiler $source = %s; $buffer .= $this->mustache ->loadLambda((string) call_user_func($value, $source, $this->lambdaHelper)%s) - ->renderInternal($context, $indent); + ->renderInternal($context); } elseif (!empty($value)) { $values = $this->isIterable($value) ? $value : array($value); foreach ($values as $value) { diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index 9869b98..5bf9c4d 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -23,7 +23,7 @@ */ class Mustache_Engine { - const VERSION = '2.4.0'; + const VERSION = '2.4.1'; const SPEC_VERSION = '1.1.2'; const PRAGMA_FILTERS = 'FILTERS'; diff --git a/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php b/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php new file mode 100644 index 0000000..647905f --- /dev/null +++ b/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php @@ -0,0 +1,59 @@ + + {{> input }} + + +EOS; + $partial = << + +EOS; + + $expected = << + + + +EOS; + + $m = new Mustache_Engine(array( + 'partials' => array('input' => $partial) + )); + + $tpl = $m->loadTemplate($src); + + + $data = new Mustache_Test_Functional_ClassWithLambda(); + $this->assertEquals($expected, $tpl->render($data)); + } +} + +class Mustache_Test_Functional_ClassWithLambda +{ + public function _t() + { + return function($val) { + return strtoupper($val); + }; + } +} diff --git a/test/Mustache/Test/Loader/FilesystemLoaderTest.php b/test/Mustache/Test/Loader/FilesystemLoaderTest.php index 3c7b2f4..3aa83fd 100644 --- a/test/Mustache/Test/Loader/FilesystemLoaderTest.php +++ b/test/Mustache/Test/Loader/FilesystemLoaderTest.php @@ -29,6 +29,15 @@ class Mustache_Test_Loader_FilesystemLoaderTest extends PHPUnit_Framework_TestCa $this->assertEquals('one contents', $loader->load('one')); } + public function testConstructorWithProtocol() + { + $baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates'); + + $loader = new Mustache_Loader_FilesystemLoader('file://' . $baseDir, array('extension' => '.ms')); + $this->assertEquals('alpha contents', $loader->load('alpha')); + $this->assertEquals('beta contents', $loader->load('beta.ms')); + } + public function testLoadTemplates() { $baseDir = realpath(dirname(__FILE__).'/../../../fixtures/templates');