Permalink
Browse files

Fix compiled templates' PSR-2 compliance.

  • Loading branch information...
1 parent d5e199b commit c75b4c2e0b4831fbcc66e0fa61a6d477af62157d @bobthecow committed Jan 27, 2013
Showing with 8 additions and 4 deletions.
  1. +8 −4 src/Mustache/Compiler.php
View
12 src/Mustache/Compiler.php
@@ -148,7 +148,6 @@ public function renderInternal(Mustache_Context $context, $indent = \'\')
return $buffer;
}
- %s
}';
/**
@@ -165,7 +164,7 @@ private function writeCode($tree, $name)
$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 @@ private function writeCode($tree, $name)
';
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 @@ private function text($text, $level)
* @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);
}

0 comments on commit c75b4c2

Please sign in to comment.