1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-25 12:35:55 +02:00

Merge remote-tracking branch 'EXreaction/ticket/11724' into develop

* EXreaction/ticket/11724:
  [ticket/11724] Handle ELSE IF separately
  [ticket/11724] Replace spaces with tabs
  [ticket/11724] Support "ELSE IF" and "ELSEIF" in the same way
This commit is contained in:
Joas Schilling
2013-08-30 19:53:54 +02:00
3 changed files with 15 additions and 3 deletions

View File

@ -219,6 +219,12 @@ class phpbb_template_twig_lexer extends Twig_Lexer
*/ */
protected function fix_if_tokens($code) protected function fix_if_tokens($code)
{ {
// Replace ELSE IF with ELSEIF
$code = preg_replace('#<!-- ELSE IF (.+?) -->#', '<!-- ELSEIF $1 -->', $code);
// Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces)
$code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code);
$callback = function($matches) $callback = function($matches)
{ {
$inner = $matches[2]; $inner = $matches[2];
@ -234,9 +240,6 @@ class phpbb_template_twig_lexer extends Twig_Lexer
return "<!-- {$matches[1]}IF{$inner}-->"; return "<!-- {$matches[1]}IF{$inner}-->";
}; };
// Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces)
$code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code);
return preg_replace_callback('#<!-- (ELSE)?IF((.*)[\s][\$|\.|!]([^\s]+)(.*))-->#', $callback, $code); return preg_replace_callback('#<!-- (ELSE)?IF((.*)[\s][\$|\.|!]([^\s]+)(.*))-->#', $callback, $code);
} }

View File

@ -62,6 +62,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(), array(),
'1!false', '1!false',
), ),
array(
'if.html',
array('S_OTHER_OTHER_VALUE' => true),
array(),
array(),
'|S_OTHER_OTHER_VALUE|!false',
),
array( array(
'if.html', 'if.html',
array('S_VALUE' => false, 'S_OTHER_VALUE' => true), array('S_VALUE' => false, 'S_OTHER_VALUE' => true),

View File

@ -2,6 +2,8 @@
1 1
<!-- ELSEIF S_OTHER_VALUE --> <!-- ELSEIF S_OTHER_VALUE -->
2 2
<!-- ELSE IF S_OTHER_OTHER_VALUE -->
|S_OTHER_OTHER_VALUE|
<!-- ELSE --> <!-- ELSE -->
03 03
<!-- ENDIF --> <!-- ENDIF -->