diff --git a/common/code/boost_simple_template.php b/common/code/boost_simple_template.php index b047bd9f..d077bd0a 100644 --- a/common/code/boost_simple_template.php +++ b/common/code/boost_simple_template.php @@ -7,7 +7,6 @@ require_once(__DIR__.'/boost.php'); * * Lambdas * Partials - * Set Delimiter * * Doesn't claim to be at all compatible with Mustache, just that it should be * easy to switch to a proper Mustache implementation in the future. @@ -23,25 +22,28 @@ class BoostSimpleTemplate { } static function parse_template($template) { - preg_match_all('@ - (?P^[ \t]*)? - (?P{{(?: - !.*?}} | - (?P[#/^&]?)\s*(?P[\w?!\/.-]*)\s*}} | - {\s*(?P[\w?!\/.-]+)\s*}}} | - (?P) - )) - (?P[ \t]*(?:\r?\n|\Z))? - @xsm', - $template, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); - $template_parts = array(); $operator_stack = array(); $scope_stack = array(); $template_stack = array(); $last_offset = 0; - foreach($matches as $match) { + $open_delim = '{{'; + $close_delim = '}}'; + + while(preg_match("@ + (?P^[ \\t]*)? + (?P{$open_delim}(?: + !.*?{$close_delim} | + (?P[#/^&]?)\\s*(?P[\\w?!/.-]*)\\s*{$close_delim} | + {\\s*(?P[\\w?!\\/.-]+)\\s*}{$close_delim} | + =\\s*(?P[^=\\s]+?)\\s*(?P[^=\\s]+?)\\s*={$close_delim} | + (?P) + )) + (?P[ \\t]*(?:\\r?\\n|\\Z))? + @xsm", + $template, $match, PREG_OFFSET_CAPTURE, $last_offset)) { + $operator = null; if (array_key_exists('error', $match) && $match['error'][1] != -1) { throw new BoostSimpleTemplateException("Invalid/unsupported tag", $match['tag'][1]); @@ -50,6 +52,10 @@ class BoostSimpleTemplate { $operator = '&'; $symbol = $match['unescaped'][0]; } + else if (!empty($match['open_delim'][0])) { + $operator = '='; + $symbol = null; + } else if(!empty($match['symbol'][0])) { $operator = $match['symbol_operator'][0] ?: '$'; $symbol = $match['symbol'][0]; @@ -99,6 +105,10 @@ class BoostSimpleTemplate { 'symbol' => $symbol, ); break; + case '=': + $open_delim = preg_quote($match['open_delim'][0], '@'); + $close_delim = preg_quote($match['close_delim'][0], '@'); + break; default: assert(false); exit(1); } diff --git a/common/code/test/simple-template.phpt b/common/code/test/simple-template.phpt index 25218bf5..d62a515d 100644 --- a/common/code/test/simple-template.phpt +++ b/common/code/test/simple-template.phpt @@ -13,8 +13,8 @@ function run_tests() { if ($test_name[0] === '~') { echo "*** Ignoring optional test: {$test_name}\n"; } - else if (in_array($test_name, array('delimiters', 'partials'))) { - echo "*** Checking for failure in supported test: {$test_name}\n"; + else if (in_array($test_name, array('partials'))) { + echo "*** Checking for failure in unsupported test: {$test_name}\n"; foreach($test_cases->tests as $test_case) { echo "{$test_case->name}\n"; @@ -27,6 +27,7 @@ function run_tests() { echo "*** Running tests from: {$test_name}\n"; foreach($test_cases->tests as $test_case) { + if (property_exists($test_case, 'partials')) { continue; } echo "{$test_case->name}\n"; Assert::same($test_case->expected, BoostSimpleTemplate::render_to_string(