Skip to content
This repository
Browse code

Fix compiled templates' PSR-2 compliance.

  • Loading branch information...
commit c75b4c2e0b4831fbcc66e0fa61a6d477af62157d 1 parent d5e199b
Justin Hileman authored January 26, 2013

Showing 1 changed file with 8 additions and 4 deletions. Show diff stats Hide diff stats

  1. 12  src/Mustache/Compiler.php
12  src/Mustache/Compiler.php
@@ -148,7 +148,6 @@ public function renderInternal(Mustache_Context $context, $indent = \'\')
148 148
 
149 149
                 return $buffer;
150 150
             }
151  
-        %s
152 151
         }';
153 152
 
154 153
     /**
@@ -165,7 +164,7 @@ private function writeCode($tree, $name)
165 164
         $sections = implode("\n", $this->sections);
166 165
         $klass    = empty($this->sections) ? self::KLASS_NO_LAMBDAS : self::KLASS;
167 166
 
168  
-        return sprintf($this->prepare($klass, 0, false), $name, $code, $sections);
  167
+        return sprintf($this->prepare($klass, 0, false, true), $name, $code, $sections);
169 168
     }
170 169
 
171 170
     const SECTION_CALL = '
@@ -174,7 +173,8 @@ private function writeCode($tree, $name)
174 173
     ';
175 174
 
176 175
     const SECTION = '
177  
-        private function section%s(Mustache_Context $context, $indent, $value) {
  176
+        private function section%s(Mustache_Context $context, $indent, $value)
  177
+        {
178 178
             $buffer = \'\';
179 179
             if (!is_string($value) && is_callable($value)) {
180 180
                 $source = %s;
@@ -377,15 +377,19 @@ private function text($text, $level)
377 377
      * @param string  $text
378 378
      * @param int     $bonus          Additional indent level (default: 0)
379 379
      * @param boolean $prependNewline Prepend a newline to the snippet? (default: true)
  380
+     * @param boolean $appendNewline  Append a newline to the snippet? (default: false)
380 381
      *
381 382
      * @return string PHP source code snippet
382 383
      */
383  
-    private function prepare($text, $bonus = 0, $prependNewline = true)
  384
+    private function prepare($text, $bonus = 0, $prependNewline = true, $appendNewline = false)
384 385
     {
385 386
         $text = ($prependNewline ? "\n" : '').trim($text);
386 387
         if ($prependNewline) {
387 388
             $bonus++;
388 389
         }
  390
+        if ($appendNewline) {
  391
+            $text .= "\n";
  392
+        }
389 393
 
390 394
         return preg_replace("/\n( {8})?/", "\n".str_repeat(" ", $bonus * 4), $text);
391 395
     }

0 notes on commit c75b4c2

Please sign in to comment.
Something went wrong with that request. Please try again.