Parcourir la source

Merge branch 'release/2.4.1'

Justin Hileman il y a 12 ans
Parent
commit
14bc3b4f6a

+ 0 - 0
CONTRIBUTING.markdown → CONTRIBUTING.md


+ 0 - 0
README.markdown → README.md


+ 3 - 0
composer.json

@@ -15,6 +15,9 @@
     "require": {
         "php": ">=5.2.4"
     },
+    "require-dev": {
+        "phpunit/phpunit": "*"
+    },
     "autoload": {
         "psr-0": { "Mustache": "src/" }
     }

+ 8 - 2
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;
         }
     }
 

+ 1 - 1
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) {

+ 1 - 1
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';

+ 59 - 0
test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php

@@ -0,0 +1,59 @@
+<?php
+
+/*
+ * This file is part of Mustache.php.
+ *
+ * (c) 2013 Justin Hileman
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * @group lambdas
+ * @group functional
+ */
+class Mustache_Test_FiveThree_Functional_PartialLambdaIndentTest extends PHPUnit_Framework_TestCase
+{
+
+    public function testLambdasInsidePartialsAreIndentedProperly()
+    {
+        $src = <<<EOS
+<fieldset>
+  {{> input }}
+</fieldset>
+
+EOS;
+        $partial = <<<EOS
+<input placeholder="{{# _t }}Enter your name{{/ _t }}">
+
+EOS;
+
+        $expected = <<<EOS
+<fieldset>
+  <input placeholder="ENTER YOUR NAME">
+</fieldset>
+
+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);
+        };
+    }
+}

+ 9 - 0
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');