From 87a734e60c3b725d1f99c38a3442e7c85a03696e Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 13 May 2013 03:53:56 -0700 Subject: [PATCH] Update Compiler for new Parser output. --- src/Mustache/Compiler.php | 20 +++++++++----------- test/Mustache/Test/CompilerTest.php | 6 ++---- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Mustache/Compiler.php b/src/Mustache/Compiler.php index aa8978e..437ea2c 100644 --- a/src/Mustache/Compiler.php +++ b/src/Mustache/Compiler.php @@ -373,13 +373,11 @@ class Mustache_Compiler */ private function text($text, $level) { - if ($text === "\n") { - $this->indentNextLine = true; + $indentNextLine = (substr($text, -1) === "\n"); + $code = sprintf($this->prepare(self::TEXT, $level), $this->flushIndent(), var_export($text, true)); + $this->indentNextLine = $indentNextLine; - return $this->prepare(self::LINE, $level); - } else { - return sprintf($this->prepare(self::TEXT, $level), $this->flushIndent(), var_export($text, true)); - } + return $code; } /** @@ -467,12 +465,12 @@ class Mustache_Compiler */ private function flushIndent() { - if ($this->indentNextLine) { - $this->indentNextLine = false; - - return self::LINE_INDENT; - } else { + if (!$this->indentNextLine) { return ''; } + + $this->indentNextLine = false; + + return self::LINE_INDENT; } } diff --git a/test/Mustache/Test/CompilerTest.php b/test/Mustache/Test/CompilerTest.php index e429e73..a5a2bdf 100644 --- a/test/Mustache/Test/CompilerTest.php +++ b/test/Mustache/Test/CompilerTest.php @@ -105,8 +105,7 @@ class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase array( '', array( - $this->createTextToken('foo'), - $this->createTextToken("\n"), + $this->createTextToken("foo\n"), array( Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED, Mustache_Tokenizer::NAME => 'name', @@ -123,8 +122,7 @@ class Mustache_Test_CompilerTest extends PHPUnit_Framework_TestCase 'UTF-8', array( "\nclass Monkey extends Mustache_Template", - '$buffer .= $indent . \'foo\'', - '$buffer .= "\n"', + "\$buffer .= \$indent . 'foo\n';", '$value = $this->resolveValue($context->find(\'name\'), $context, $indent);', '$buffer .= htmlspecialchars($value, '.ENT_COMPAT.', \'UTF-8\');', '$value = $this->resolveValue($context->last(), $context, $indent);',