From d8da5f1d9940fd06d90d8537693c78704489b4ec Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sat, 18 Jul 2015 01:12:21 -0700 Subject: [PATCH] Clean up compiled PHP coding style. --- src/Mustache/Compiler.php | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Mustache/Compiler.php b/src/Mustache/Compiler.php index 334fd55..076501e 100644 --- a/src/Mustache/Compiler.php +++ b/src/Mustache/Compiler.php @@ -240,8 +240,7 @@ class Mustache_Compiler $blockFunction = $context->findInBlock(%s); if (is_callable($blockFunction)) { $buffer .= call_user_func($blockFunction, $context); - } else { - %s + } else {%s } '; @@ -265,10 +264,7 @@ class Mustache_Compiler return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $this->walk($nodes, $level)); } - const BLOCK_ARG = ' - // %s block_arg - $newContext[%s] = array($this, \'block%s\'); - '; + const BLOCK_ARG = '$newContext[%s] = array($this, \'block%s\');'; /** * Generate Mustache Template inheritance block argument PHP source. @@ -289,33 +285,34 @@ class Mustache_Compiler $keystr = var_export($key, true); $id = var_export($id, true); - return sprintf($this->prepare(self::BLOCK_ARG, 1), $keystr, $id, $key); + return sprintf($this->prepare(self::BLOCK_ARG, 1), $id, $key); } - const BLOCK_FUNCTION = 'public function block%s($context) { - $indent = $buffer = \'\'; - - %s + const BLOCK_FUNCTION = ' + public function block%s($context) + { + $indent = $buffer = \'\';%s return $buffer; - }'; + } + '; /** * Generate Mustache Template inheritance block function PHP source. * - * @param array $nodes Array of child tokens + * @param array $nodes Array of child tokens * * @return string key of new block function */ private function block($nodes) { - $code = $this->walk($nodes, 1); - + $code = $this->walk($nodes, 0); $key = ucfirst(md5($code)); if (!isset($this->blocks[$key])) { - $this->blocks[$key] = sprintf($this->prepare(self::BLOCK_FUNCTION, 1), $key, $code); + $this->blocks[$key] = sprintf($this->prepare(self::BLOCK_FUNCTION, 0), $key, $code); } + return $key; } @@ -349,7 +346,8 @@ class Mustache_Compiler } return $buffer; - }'; + } + '; /** * Generate Mustache Template section PHP source. @@ -399,7 +397,8 @@ class Mustache_Compiler $value = $context->%s(%s);%s if (empty($value)) { %s - }'; + } + '; /** * Generate Mustache Template inverted section PHP source.