From 88153143d670ff57168e9ef4798a377a38452c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bjka?= Date: Tue, 5 Jul 2016 17:39:30 +0200 Subject: [PATCH 01/11] BlockMacros: fixed expandTokens in dynamic blocks (#125) --- src/Latte/Macros/BlockMacros.php | 2 +- tests/Latte/BlockMacros.dynamicblock.phpt | 2 +- tests/Latte/expected/BlockMacros.dynamicblock.phtml | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Latte/Macros/BlockMacros.php b/src/Latte/Macros/BlockMacros.php index 48d0f196d..ca10e0252 100644 --- a/src/Latte/Macros/BlockMacros.php +++ b/src/Latte/Macros/BlockMacros.php @@ -351,7 +351,7 @@ public function macroBlockEnd(MacroNode $node, PhpWriter $writer) $node->content = rtrim($node->content, " \t"); $this->getCompiler()->addMethod( $node->data->func, - "extract(\$_args);\n?>$node->contentgetCompiler()->expandTokens("extract(\$_args);\n?>$node->contentcontent = ''; diff --git a/tests/Latte/BlockMacros.dynamicblock.phpt b/tests/Latte/BlockMacros.dynamicblock.phpt index 364f429e2..a5b1a5b79 100644 --- a/tests/Latte/BlockMacros.dynamicblock.phpt +++ b/tests/Latte/BlockMacros.dynamicblock.phpt @@ -33,7 +33,7 @@ $template = <<<'EOD' {include #$name . '', var => 40} -{block word$name}{/block} +{block word$name}
{/block} {block "word$name"}{/block} EOD; diff --git a/tests/Latte/expected/BlockMacros.dynamicblock.phtml b/tests/Latte/expected/BlockMacros.dynamicblock.phtml index 4988aede1..56e04126a 100644 --- a/tests/Latte/expected/BlockMacros.dynamicblock.phtml +++ b/tests/Latte/expected/BlockMacros.dynamicblock.phtml @@ -88,6 +88,9 @@ class Template%a% extends Latte\Runtime\Template function blockWord_name($_args) { extract($_args); + if (false) { + ?>
Date: Thu, 14 Jul 2016 16:22:32 +0200 Subject: [PATCH 02/11] travis: added PHP 7.1 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index ec35dd332..e247a7f88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,12 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 - hhvm matrix: allow_failures: + - php: 7.1 - php: hhvm script: From 0e4ec1a126db736b1907e18be5a6568c879924a5 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 14 Jul 2016 18:56:32 +0200 Subject: [PATCH 03/11] Filter strip: changed implementation to prevent backtrace limit errors --- src/Latte/Runtime/Filters.php | 48 +++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Latte/Runtime/Filters.php b/src/Latte/Runtime/Filters.php index c4e1b3a49..1d795a18d 100644 --- a/src/Latte/Runtime/Filters.php +++ b/src/Latte/Runtime/Filters.php @@ -303,17 +303,43 @@ public static function safeUrl($s) public static function strip(FilterInfo $info, $s) { trigger_error('Filter |strip is deprecated, use macro {spaceless}', E_USER_DEPRECATED); - if (in_array($info->contentType, [Engine::CONTENT_HTML, Engine::CONTENT_XHTML], TRUE)) { - return preg_replace_callback( - '#(contentType, [Engine::CONTENT_HTML, Engine::CONTENT_XHTML], TRUE) + ? trim(self::spacelessHtml($s)) + : trim(self::spacelessText($s)); + } + + + /** + * Replaces all repeated white spaces with a single space. + * @param string HTML + * @return string HTML + */ + public static function spacelessHtml($s) + { + $strip = TRUE; + return preg_replace_callback( + '#[ \t\r\n]+|<(/)?(textarea|pre|script)(?=\W)#si', + function ($m) use (& $strip) { + if (empty($m[2])) { + return $strip ? ' ' : $m[0]; + } else { + $strip = !empty($m[1]); + return $m[0]; + } + }, + $s + ); + } + + + /** + * Replaces all repeated white spaces with a single space. + * @param string text + * @return string text + */ + public static function spacelessText($s) + { + return preg_replace('#[ \t\r\n]+#', ' ', $s); } From 6dab67cd597ccbc964578b37c209d5418fdfdf5d Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 15 Jul 2016 12:34:29 +0200 Subject: [PATCH 04/11] Revert "deprecated filter |strip" This reverts commit 63f16664a61d8c0ba8d1a915ef97b48864c2c76a. --- src/Latte/Runtime/Filters.php | 1 - tests/Latte/Filters.strip().phpt | 20 ++++++++--------- tests/Latte/expected/filters.general.html | 7 ++++++ tests/Latte/expected/filters.general.phtml | 24 ++++++++++++++++++--- tests/Latte/templates/filters.general.latte | 14 ++++++++++++ 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/Latte/Runtime/Filters.php b/src/Latte/Runtime/Filters.php index 1d795a18d..f0e09cad7 100644 --- a/src/Latte/Runtime/Filters.php +++ b/src/Latte/Runtime/Filters.php @@ -302,7 +302,6 @@ public static function safeUrl($s) */ public static function strip(FilterInfo $info, $s) { - trigger_error('Filter |strip is deprecated, use macro {spaceless}', E_USER_DEPRECATED); return in_array($info->contentType, [Engine::CONTENT_HTML, Engine::CONTENT_XHTML], TRUE) ? trim(self::spacelessHtml($s)) : trim(self::spacelessText($s)); diff --git a/tests/Latte/Filters.strip().phpt b/tests/Latte/Filters.strip().phpt index 32a36a775..2fa9dd8bb 100644 --- a/tests/Latte/Filters.strip().phpt +++ b/tests/Latte/Filters.strip().phpt @@ -15,19 +15,19 @@ require __DIR__ . '/../bootstrap.php'; test(function () { $info = new FilterInfo(Engine::CONTENT_TEXT); - Assert::same('', @Filters::strip($info, '')); // @ is deprecated - Assert::same('', @Filters::strip($info, "\r\n ")); - Assert::same('A B', @Filters::strip($info, "A\r\t\n B")); - Assert::same('

Hello

', @Filters::strip($info, "

Hello

\r\n ")); - Assert::same("
 
", @Filters::strip($info, "
  \r\n 
\r\n ")); + Assert::same('', Filters::strip($info, '')); + Assert::same('', Filters::strip($info, "\r\n ")); + Assert::same('A B', Filters::strip($info, "A\r\t\n B")); + Assert::same('

Hello

', Filters::strip($info, "

Hello

\r\n ")); + Assert::same("
 
", Filters::strip($info, "
  \r\n 
\r\n ")); }); test(function () { $info = new FilterInfo(Engine::CONTENT_HTML); - Assert::same('', @Filters::strip($info, '')); - Assert::same('', @Filters::strip($info, "\r\n ")); - Assert::same('A B', @Filters::strip($info, "A\r\t\n B")); - Assert::same('

Hello

', @Filters::strip($info, "

Hello

\r\n ")); - Assert::same("
  \r\n 
", @Filters::strip($info, "
  \r\n 
\r\n ")); + Assert::same('', Filters::strip($info, '')); + Assert::same('', Filters::strip($info, "\r\n ")); + Assert::same('A B', Filters::strip($info, "A\r\t\n B")); + Assert::same('

Hello

', Filters::strip($info, "

Hello

\r\n ")); + Assert::same("
  \r\n 
", Filters::strip($info, "
  \r\n 
\r\n ")); }); diff --git a/tests/Latte/expected/filters.general.html b/tests/Latte/expected/filters.general.html index ee2d12e13..2b29ad998 100644 --- a/tests/Latte/expected/filters.general.html +++ b/tests/Latte/expected/filters.general.html @@ -30,6 +30,13 @@ + test A   A + + +

Captured:

    diff --git a/tests/Latte/expected/filters.general.phtml b/tests/Latte/expected/filters.general.phtml index ea8b34aef..7a9469b2f 100644 --- a/tests/Latte/expected/filters.general.phtml +++ b/tests/Latte/expected/filters.general.phtml @@ -44,9 +44,27 @@ class Template%a% extends Latte\Runtime\Template + test +A   A + + +filters->filterContent('strip', $_fi, ob_get_clean())); +?> + + + +
      -
    • lower: filters->lower, $hello)) /* line 35 */ ?>
    • +
    • lower: filters->lower, $hello)) /* line 49 */ ?>

    -Captured: +Captured:

    @@ -67,7 +85,7 @@ Hello ?>

    -Captured with modifier: +Captured with modifier:

    diff --git a/tests/Latte/templates/filters.general.latte b/tests/Latte/templates/filters.general.latte index ad248ffb1..7ebebe3ba 100644 --- a/tests/Latte/templates/filters.general.latte +++ b/tests/Latte/templates/filters.general.latte @@ -30,6 +30,20 @@ +{block |strip} test +A   A + + +{/block} + + + {capture$capture}
    • lower: {$hello |lower}
    • From 620c867fefebeb14ee58f31bf5b77618897e2c4e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 15 Jul 2016 13:07:00 +0200 Subject: [PATCH 05/11] CoreMacros: {spaceless} works the same way as |strip and strips output in chunks --- src/Latte/Macros/CoreMacros.php | 19 ++++--------------- src/Latte/Runtime/Filters.php | 11 +++++++++-- tests/Latte/CoreMacros.spaceless.phpt | 22 ++++++++++++++++++---- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/Latte/Macros/CoreMacros.php b/src/Latte/Macros/CoreMacros.php index 9d8290267..f2aecf44d 100644 --- a/src/Latte/Macros/CoreMacros.php +++ b/src/Latte/Macros/CoreMacros.php @@ -290,21 +290,10 @@ public function macroSpaceless(MacroNode $node, PhpWriter $writer) if ($node->modifiers || $node->args) { throw new CompileException('Modifiers and arguments are not allowed in ' . $node->getNotation()); } - if (!$node->closing) { - return; - } elseif ($node->prefix) { // preserve trailing whitespaces - preg_match('#^(\s*)(.*?)(\s*)\z#s', $node->content, $parts); - $node->content = $parts[2]; - } - - $node->content = preg_replace('#[ \t\r\n]+#', ' ', $node->content); - - if (in_array($node->context[0], [Engine::CONTENT_HTML, Engine::CONTENT_XHTML], TRUE)) { - $node->content = preg_replace('#(?<=>) | (?=<)#', '', $node->content); - if ($node->prefix) { - $node->content = $parts[1] . $node->content . $parts[3]; - } - } + $node->openingCode = in_array($node->context[0], [Engine::CONTENT_HTML, Engine::CONTENT_XHTML], TRUE) + ? '' + : ""; + $node->closingCode = ''; } diff --git a/src/Latte/Runtime/Filters.php b/src/Latte/Runtime/Filters.php index f0e09cad7..b7333c3d9 100644 --- a/src/Latte/Runtime/Filters.php +++ b/src/Latte/Runtime/Filters.php @@ -311,11 +311,18 @@ public static function strip(FilterInfo $info, $s) /** * Replaces all repeated white spaces with a single space. * @param string HTML + * @param int output buffering phase + * @param bool stripping mode * @return string HTML */ - public static function spacelessHtml($s) + public static function spacelessHtml($s, $phase = NULL, & $strip = TRUE) { - $strip = TRUE; + if ($phase & PHP_OUTPUT_HANDLER_START) { + $s = ltrim($s); + } + if ($phase & PHP_OUTPUT_HANDLER_FINAL) { + $s = rtrim($s); + } return preg_replace_callback( '#[ \t\r\n]+|<(/)?(textarea|pre|script)(?=\W)#si', function ($m) use (& $strip) { diff --git a/tests/Latte/CoreMacros.spaceless.phpt b/tests/Latte/CoreMacros.spaceless.phpt index f6ef7ecb1..497282d32 100644 --- a/tests/Latte/CoreMacros.spaceless.phpt +++ b/tests/Latte/CoreMacros.spaceless.phpt @@ -15,8 +15,7 @@ $latte->setLoader(new Latte\Loaders\StringLoader); Assert::match( '
      -

      Text

      block
      -
      ', +

      Text

      block

      ', $latte->renderToString(<< @@ -36,8 +35,7 @@ EOD Assert::match( '
      -

      Text

      -
      ', +

      Text


      ', $latte->renderToString(<< @@ -49,3 +47,19 @@ Assert::match(
      EOD )); + + +Assert::match( + "

      \n\n\n"
      +	. str_repeat('x', 10000)
      +	. "\n\n\n

      ", + + $latte->renderToString( + "{spaceless}

      \n\n\n

      " + . "
      \n\n\n"
      +		. str_repeat('x', 5000)
      +		. "{if true}{/if}"
      +		. str_repeat('x', 5000)
      +		. "\n\n\n

      \n\n\n

      {/spaceless}" + ) +); From 885b3f56fef30efc5c3abf6b9f5e1fdcb1db855e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 21 Jul 2016 13:47:21 +0200 Subject: [PATCH 06/11] fixed compatibility with PHP 7.1 https://wiki.php.net/rfc/invalid_strings_in_arithmetic --- src/Latte/Compiler/PhpWriter.php | 2 +- tests/Latte/expected/filters.general.phtml | 6 +++--- tests/Latte/templates/filters.general.latte | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Latte/Compiler/PhpWriter.php b/src/Latte/Compiler/PhpWriter.php index 048f6ae97..f651dba02 100644 --- a/src/Latte/Compiler/PhpWriter.php +++ b/src/Latte/Compiler/PhpWriter.php @@ -70,7 +70,7 @@ function ($m) use ($word, & $args) { case '': $arg = next($args); break; default: - $arg = $args[$source + 1]; break; + $arg = $args[(int) $source + 1]; break; } switch ($format) { diff --git a/tests/Latte/expected/filters.general.phtml b/tests/Latte/expected/filters.general.phtml index 7a9469b2f..b0062a53f 100644 --- a/tests/Latte/expected/filters.general.phtml +++ b/tests/Latte/expected/filters.general.phtml @@ -12,7 +12,7 @@ class Template%a% extends Latte\Runtime\Template
    • upper: filters->upper, $hello)) /* line 3 */ ?>
    • lower & capitalize: filters->capitalize, call_user_func($this->filters->lower, $hello))) /* line 4 */ ?>
    • breaklines: filters->breaklines, $hello)) /* line 5 */ ?>
    • -
    • truncate: filters->lower, call_user_func($this->filters->truncate, $hello, "10 "))) /* line 6 */ ?>
    • +
    • truncate: filters->lower, call_user_func($this->filters->truncate, $hello, "10"))) /* line 6 */ ?>
    • date: filters->date, $date, '%d.%m.%Y %H:%M:%S')) /* line 7 */ ?>
    • translated: filters->truncate, call_user_func($this->filters->translate, $hello), 3)) ?>
    • Translated HTML: ahoj
        -
      • filters->types, $hello*0, 0, 0.0, "0")) /* line 24 */ ?>
      • -
      • filters->types, $hello*1, 1, "1")) /* line 25 */ ?>
      • +
      • filters->types, (int)$hello*0, 0, 0.0, "0")) /* line 24 */ ?>
      • +
      • filters->types, (int)$hello*1, 1, "1")) /* line 25 */ ?>
      • filters->types, $hello, true, null, false)) /* line 26 */ ?>
      • filters->types, $hello, TRUE, NULL, FALSE)) /* line 27 */ ?>
      • filters->types, $hello, '', "", "$hello")) /* line 28 */ ?>
      • diff --git a/tests/Latte/templates/filters.general.latte b/tests/Latte/templates/filters.general.latte index 7ebebe3ba..670a5f954 100644 --- a/tests/Latte/templates/filters.general.latte +++ b/tests/Latte/templates/filters.general.latte @@ -3,7 +3,7 @@
      • upper: {$hello |upper}
      • lower & capitalize: {$hello |lower|capitalize}
      • breaklines: {$hello |breakLines}
      • -
      • truncate: {$hello |truncate:"10 "|lower}
      • +
      • truncate: {$hello |truncate:"10"|lower}
      • date: {$date|date:'%d.%m.%Y %H:%M:%S'}
      • translated: {_$hello|truncate:3}
      • Translated HTML: {_}ahoj{/_}
      • @@ -21,8 +21,8 @@
        -
      • {$hello*0 |types:0,0.0,"0"}
      • -
      • {$hello*1 |types:1:"1"}
      • +
      • {(int)$hello*0 |types:0,0.0,"0"}
      • +
      • {(int)$hello*1 |types:1:"1"}
      • {$hello |types:true,null,false}
      • {$hello |types:TRUE,NULL,FALSE}
      • {$hello |types:'',"","$hello"}
      • From 2e6ef07120201a6277bef2cb6d2e5d172cdae559 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 27 Jul 2016 14:16:26 +0200 Subject: [PATCH 07/11] PhpWriter: fixed handling of uppercase class name --- src/Latte/Compiler/PhpWriter.php | 2 +- tests/Latte/PhpWriter.formatArgs().phpt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Latte/Compiler/PhpWriter.php b/src/Latte/Compiler/PhpWriter.php index f651dba02..e83a2b9ef 100644 --- a/src/Latte/Compiler/PhpWriter.php +++ b/src/Latte/Compiler/PhpWriter.php @@ -185,7 +185,7 @@ public function validateTokens(MacroTokens $tokens) trigger_error("Variable {$tokens->currentValue()} is deprecated.", E_USER_DEPRECATED); } elseif ($tokens->isCurrent($tokens::T_SYMBOL) - && !$tokens->isPrev('::') && !$tokens->isPrev('->') + && !$tokens->isPrev('::') && !$tokens->isNext('::') && !$tokens->isPrev('->') && preg_match('#^[A-Z0-9]{3,}$#', $val = $tokens->currentValue()) ) { trigger_error("Replace literal $val with constant('$val')", E_USER_DEPRECATED); diff --git a/tests/Latte/PhpWriter.formatArgs().phpt b/tests/Latte/PhpWriter.formatArgs().phpt index f4f5f319b..c517bc361 100644 --- a/tests/Latte/PhpWriter.formatArgs().phpt +++ b/tests/Latte/PhpWriter.formatArgs().phpt @@ -71,6 +71,7 @@ test(function () { // special Assert::same("'symbol' => NOTCONST", @formatArgs('symbol => NOTCONST')); // @ not contant Assert::same("'symbol' => M_PI, NAN, INF ", formatArgs('symbol => M_PI, NAN, INF ')); Assert::same("'symbol' => Class::CONST, ", formatArgs('symbol => Class::CONST, ')); + Assert::same("'symbol' => CLASS::CONST, ", formatArgs('symbol => CLASS::CONST, ')); Assert::same("'symbol' => Class::method(), ", formatArgs('symbol => Class::method(), ')); Assert::same("'symbol' => Namespace\\Class::method()", formatArgs('symbol => Namespace\Class::method()')); Assert::same("'symbol' => Namespace \\ Class :: method ()", formatArgs('symbol => Namespace \ Class :: method ()')); From 645246e18197be4c4651ab7551bfbb3c228ffe66 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 30 Jul 2016 17:55:27 +0200 Subject: [PATCH 08/11] composer: requires PHP extension json, suggests xml --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f13a746d3..79bd1a712 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ ], "require": { "php": ">=5.4.4", + "ext-json": "*", "ext-tokenizer": "*" }, "require-dev": { @@ -24,7 +25,8 @@ }, "suggest": { "ext-mbstring": "to use filters like lower, upper, capitalize, ...", - "ext-fileinfo": "to use filter |datastream" + "ext-fileinfo": "to use filter |datastream", + "ext-xml": "to use filters like length, substring, ..." }, "conflict": { "nette/application": "<2.4" From 5f36af69c5faabf8ced1456711c090f5a07d9a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bjka?= Date: Sat, 30 Jul 2016 18:03:23 +0200 Subject: [PATCH 09/11] Snippets: disable snippet mode when rendering snippets [BC break - interface changed] (#127) --- composer.json | 2 +- src/Latte/Runtime/ISnippetBridge.php | 7 +++++++ src/Latte/Runtime/SnippetDriver.php | 6 ++++-- tests/Latte/mocks/SnippetBridge.php | 6 ++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 79bd1a712..384f9b4d5 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "ext-xml": "to use filters like length, substring, ..." }, "conflict": { - "nette/application": "<2.4" + "nette/application": "<2.4.1" }, "autoload": { "classmap": ["src/"] diff --git a/src/Latte/Runtime/ISnippetBridge.php b/src/Latte/Runtime/ISnippetBridge.php index 4ed2e8892..2be52ea75 100644 --- a/src/Latte/Runtime/ISnippetBridge.php +++ b/src/Latte/Runtime/ISnippetBridge.php @@ -21,6 +21,13 @@ interface ISnippetBridge function isSnippetMode(); + /** + * @param bool + * @return void + */ + function setSnippetMode($snippetMode); + + /** * @param string * @return bool diff --git a/src/Latte/Runtime/SnippetDriver.php b/src/Latte/Runtime/SnippetDriver.php index 2c312fb66..c443c6b11 100644 --- a/src/Latte/Runtime/SnippetDriver.php +++ b/src/Latte/Runtime/SnippetDriver.php @@ -43,7 +43,7 @@ public function __construct(ISnippetBridge $bridge) public function enter($name, $type) { - if (!$this->bridge->isSnippetMode()) { + if (!$this->renderingSnippets) { return; } $obStarted = FALSE; @@ -63,7 +63,7 @@ public function enter($name, $type) public function leave() { - if (!$this->bridge->isSnippetMode()) { + if (!$this->renderingSnippets) { return; } list($name, $obStarted) = array_pop($this->stack); @@ -88,6 +88,7 @@ public function renderSnippets(array $blocks, array $params) return FALSE; } $this->renderingSnippets = TRUE; + $this->bridge->setSnippetMode(FALSE); foreach ($blocks as $name => $function) { if ($name[0] !== '_' || !$this->bridge->needsRedraw(substr($name, 1))) { continue; @@ -95,6 +96,7 @@ public function renderSnippets(array $blocks, array $params) $function = reset($function); $function($params); } + $this->bridge->setSnippetMode(TRUE); $this->bridge->renderChildren(); return TRUE; } diff --git a/tests/Latte/mocks/SnippetBridge.php b/tests/Latte/mocks/SnippetBridge.php index 7f70f5f6f..53f24bd23 100644 --- a/tests/Latte/mocks/SnippetBridge.php +++ b/tests/Latte/mocks/SnippetBridge.php @@ -17,6 +17,12 @@ public function isSnippetMode() } + public function setSnippetMode($snippetMode) + { + $this->snippetMode = $snippetMode; + } + + public function needsRedraw($name) { return $this->invalid === TRUE || isset($this->invalid[$name]); From 8739c67957bf31b4752f094de41ffb51773ac499 Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Tue, 28 Jun 2016 16:52:23 +0200 Subject: [PATCH 10/11] CoreMacros: translate macro does not use output buffer when possible [Closes #124] --- src/Latte/Macros/CoreMacros.php | 13 +++++-- tests/Latte/expected/filters.general.html | 1 + tests/Latte/expected/filters.general.phtml | 41 ++++++++++++--------- tests/Latte/templates/filters.general.latte | 1 + 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/Latte/Macros/CoreMacros.php b/src/Latte/Macros/CoreMacros.php index f2aecf44d..ef92e594d 100644 --- a/src/Latte/Macros/CoreMacros.php +++ b/src/Latte/Macros/CoreMacros.php @@ -207,13 +207,18 @@ public function macroEndIfContent(MacroNode $node, PhpWriter $writer) public function macroTranslate(MacroNode $node, PhpWriter $writer) { if ($node->closing) { - return $writer->write('$_fi = new LR\FilterInfo(%var); echo %modifyContent($this->filters->filterContent("translate", $_fi, ob_get_clean()))', $node->context[0]); + if (strpos($node->content, 'content, TRUE); + $node->content = ''; + } else { + $node->openingCode = '' . $node->openingCode; + $value = 'ob_get_clean()'; + } + + return $writer->write('$_fi = new LR\FilterInfo(%var); echo %modifyContent($this->filters->filterContent("translate", $_fi, %raw))', $node->context[0], $value); } elseif ($node->empty = ($node->args !== '')) { return $writer->write('echo %modify(call_user_func($this->filters->translate, %node.args))'); - - } else { - return 'ob_start(function () {})'; } } diff --git a/tests/Latte/expected/filters.general.html b/tests/Latte/expected/filters.general.html index 2b29ad998..f06918b2e 100644 --- a/tests/Latte/expected/filters.general.html +++ b/tests/Latte/expected/filters.general.html @@ -6,6 +6,7 @@
      • truncate: hello…
      • date: 02.01.2008 00:00:00
      • translated: dl…
      • +
      • Translated HTML: dlroW olleH
      • Translated HTML: joha
      • Translated HTML: joha
      • Translated HTML: johajohajohajoha|joha
      • diff --git a/tests/Latte/expected/filters.general.phtml b/tests/Latte/expected/filters.general.phtml index b0062a53f..efcaf7148 100644 --- a/tests/Latte/expected/filters.general.phtml +++ b/tests/Latte/expected/filters.general.phtml @@ -15,31 +15,36 @@ class Template%a% extends Latte\Runtime\Template
      • truncate: filters->lower, call_user_func($this->filters->truncate, $hello, "10"))) /* line 6 */ ?>
      • date: filters->date, $date, '%d.%m.%Y %H:%M:%S')) /* line 7 */ ?>
      • translated: filters->truncate, call_user_func($this->filters->translate, $hello), 3)) ?>
      • -
      • Translated HTML: ahojTranslated HTML: filters->filterContent("translate", $_fi, ob_get_clean())) ?>
      • -
      • Translated HTML: ahojTranslated HTML: filters->filterContent("translate", $_fi, ob_get_clean())) ?>
      • + echo LR\Filters::convertTo($_fi, 'html', $this->filters->filterContent("translate", $_fi, 'ahoj')) ?> +
      • Translated HTML: filters->filterContent("translate", $_fi, 'ahoj')) ?>
      • Translated HTML: filters->translate, 'ahoj|ahojahojahojahoj')) ?>
      • -
      • spaces: filters->types, $hello , '' , "" , "$hello" )) /* line 12 */ ?>
      • -
      • dynamic: filters->dynamic, $hello)) /* line 13 */ ?> filters->dynamic2, $hello)) /* line 13 */ ?>
      • +
      • spaces: filters->types, $hello , '' , "" , "$hello" )) /* line 13 */ ?>
      • +
      • dynamic: filters->dynamic, $hello)) /* line 14 */ ?> filters->dynamic2, $hello)) /* line 14 */ ?>
        -
      • filters->h2, call_user_func($this->filters->h1, $hello))) /* line 17 */ ?>
      • -
      • filters->h2, call_user_func($this->filters->h1, $hello)) /* line 18 */ ?>
      • -
      • filters->h1, call_user_func($this->filters->h2, $hello))) /* line 19 */ ?>
      • -
      • filters->h1, call_user_func($this->filters->h2, $hello)) /* line 20 */ ?>
      • +
      • filters->h2, call_user_func($this->filters->h1, $hello))) /* line 18 */ ?>
      • +
      • filters->h2, call_user_func($this->filters->h1, $hello)) /* line 19 */ ?>
      • +
      • filters->h1, call_user_func($this->filters->h2, $hello))) /* line 20 */ ?>
      • +
      • filters->h1, call_user_func($this->filters->h2, $hello)) /* line 21 */ ?>
        -
      • filters->types, (int)$hello*0, 0, 0.0, "0")) /* line 24 */ ?>
      • -
      • filters->types, (int)$hello*1, 1, "1")) /* line 25 */ ?>
      • -
      • filters->types, $hello, true, null, false)) /* line 26 */ ?>
      • -
      • filters->types, $hello, TRUE, NULL, FALSE)) /* line 27 */ ?>
      • -
      • filters->types, $hello, '', "", "$hello")) /* line 28 */ ?>
      • +
      • filters->types, (int)$hello*0, 0, 0.0, "0")) /* line 25 */ ?>
      • +
      • filters->types, (int)$hello*1, 1, "1")) /* line 26 */ ?>
      • +
      • filters->types, $hello, true, null, false)) /* line 27 */ ?>
      • +
      • filters->types, $hello, TRUE, NULL, FALSE)) /* line 28 */ ?>
      • +
      • filters->types, $hello, '', "", "$hello")) /* line 29 */ ?>
      @@ -64,7 +69,7 @@ alert();
        -
      • lower: filters->lower, $hello)) /* line 49 */ ?>
      • +
      • lower: filters->lower, $hello)) /* line 50 */ ?>

      -Captured: +Captured:

      @@ -85,7 +90,7 @@ Hello ?>

      -Captured with modifier: +Captured with modifier:

      diff --git a/tests/Latte/templates/filters.general.latte b/tests/Latte/templates/filters.general.latte index 670a5f954..84111a655 100644 --- a/tests/Latte/templates/filters.general.latte +++ b/tests/Latte/templates/filters.general.latte @@ -6,6 +6,7 @@
    • truncate: {$hello |truncate:"10"|lower}
    • date: {$date|date:'%d.%m.%Y %H:%M:%S'}
    • translated: {_$hello|truncate:3}
    • +
    • Translated HTML: {_}{$hello}{/_}
    • Translated HTML: {_}ahoj{/_}
    • Translated HTML: {_}ahoj{/}
    • Translated HTML: {_'ahoj|ahojahojahojahoj'}
    • From 08efb9414d847643848932ef8163d5b66d6d0380 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 31 Jul 2016 13:41:46 +0200 Subject: [PATCH 11/11] Released version 2.4.1 --- src/Latte/Engine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Latte/Engine.php b/src/Latte/Engine.php index de904546f..30a1256e0 100644 --- a/src/Latte/Engine.php +++ b/src/Latte/Engine.php @@ -15,7 +15,7 @@ class Engine { use Strict; - const VERSION = '2.4.0'; + const VERSION = '2.4.1'; /** Content types */ const CONTENT_HTML = 'html',