From c75b4c2e0b4831fbcc66e0fa61a6d477af62157d Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 26 Jan 2013 16:34:16 -0800 Subject: [PATCH] Fix compiled templates' PSR-2 compliance. --- src/Mustache/Compiler.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Mustache/Compiler.php b/src/Mustache/Compiler.php index 27f02f0..d6c448d 100644 --- a/src/Mustache/Compiler.php +++ b/src/Mustache/Compiler.php @@ -148,7 +148,6 @@ class Mustache_Compiler return $buffer; } - %s }'; /** @@ -165,7 +164,7 @@ class Mustache_Compiler $sections = implode("\n", $this->sections); $klass = empty($this->sections) ? self::KLASS_NO_LAMBDAS : self::KLASS; - return sprintf($this->prepare($klass, 0, false), $name, $code, $sections); + return sprintf($this->prepare($klass, 0, false, true), $name, $code, $sections); } const SECTION_CALL = ' @@ -174,7 +173,8 @@ class Mustache_Compiler '; const SECTION = ' - private function section%s(Mustache_Context $context, $indent, $value) { + private function section%s(Mustache_Context $context, $indent, $value) + { $buffer = \'\'; if (!is_string($value) && is_callable($value)) { $source = %s; @@ -377,15 +377,19 @@ class Mustache_Compiler * @param string $text * @param int $bonus Additional indent level (default: 0) * @param boolean $prependNewline Prepend a newline to the snippet? (default: true) + * @param boolean $appendNewline Append a newline to the snippet? (default: false) * * @return string PHP source code snippet */ - private function prepare($text, $bonus = 0, $prependNewline = true) + private function prepare($text, $bonus = 0, $prependNewline = true, $appendNewline = false) { $text = ($prependNewline ? "\n" : '').trim($text); if ($prependNewline) { $bonus++; } + if ($appendNewline) { + $text .= "\n"; + } return preg_replace("/\n( {8})?/", "\n".str_repeat(" ", $bonus * 4), $text); }