From 66980edab1ab0822bdef786da1ba55235341a30d Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 17 Oct 2023 03:06:40 +0900 Subject: [PATCH] Allow use, include, and load directives to appear anywhere in a line --- .../parsers/template/TemplateParser_v2.php | 22 ++++++++++--------- tests/_data/template/v2example.html | 6 ++--- tests/_data/template/v2result1.php | 6 ++--- tests/_data/template/v2result2.php | 4 +++- .../parsers/TemplateParserV2Test.php | 4 ++-- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/common/framework/parsers/template/TemplateParser_v2.php b/common/framework/parsers/template/TemplateParser_v2.php index f2d1269b3..9f00a3ac2 100644 --- a/common/framework/parsers/template/TemplateParser_v2.php +++ b/common/framework/parsers/template/TemplateParser_v2.php @@ -259,7 +259,7 @@ class TemplateParser_v2 protected function _convertClassAliases(string $content): string { // Find all alias directives. - $regexp = '#^[\x09\x20]*(?:|(?|(?)[\x09\x20]*$#m'; + $regexp = '#()#'; $content = preg_replace_callback($regexp, function($match) { // Convert the path if necessary. @@ -341,11 +341,12 @@ class TemplateParser_v2 }, $content); // Convert Blade-style include directives. - $regexp = '#^[\x09\x20]*(?template->extension === 'blade.php' ? 'blade.php' : 'html'; $dir = '$this->relative_dirname'; if ($match[1] === 'include' || $match[1] === 'includeIf') @@ -399,7 +400,7 @@ class TemplateParser_v2 // Handle the @each directive. $parentheses = self::_getRegexpForParentheses(1); - $regexp = '#(?:^[\x09\x20]*||[\x09\x20]*$)#sm'; + $regexp = '#(?)[\x09\x20]*$#m'; + $regexp = '#()#'; $content = preg_replace_callback($regexp, function($match) { $attrs = self::_getTagAttributes($match[1]); $attrs['src'] = $attrs['src'] ?? ($attrs['target'] ?? null); @@ -458,9 +459,10 @@ class TemplateParser_v2 }, $content); // Convert Blade-style load directives. - $regexp = '#^[\x09\x20]*(? %s="%s"', $condition, $match[1], $match[1]); }, $content); // Convert Blade-style @class and @style conditions. - $regexp = '#\s*(? @use('Rhymix\Framework\Push', 'Push') -@include('^/common/tpl/refresh.html') -@load('^/common/js/plugins/ckeditor/') -@load('css/style.css') +
@include('^/common/tpl/refresh.html')
+
@load('^/common/js/plugins/ckeditor/')
+ config->version = 2; ?> -setVars($__vars); echo $__tpl->compile(); })("common/tpl", 'refresh.html'); ?> - - +
setVars($__vars); echo $__tpl->compile(); })("common/tpl", 'refresh.html'); ?>
+
+ foo = 'FOOFOOFOO'; diff --git a/tests/_data/template/v2result2.php b/tests/_data/template/v2result2.php index 4ef77cc1d..cebb1b59f 100644 --- a/tests/_data/template/v2result2.php +++ b/tests/_data/template/v2result2.php @@ -1,8 +1,10 @@ - + +
{{ $foo }} diff --git a/tests/unit/framework/parsers/TemplateParserV2Test.php b/tests/unit/framework/parsers/TemplateParserV2Test.php index 22d236487..3351d45ca 100644 --- a/tests/unit/framework/parsers/TemplateParserV2Test.php +++ b/tests/unit/framework/parsers/TemplateParserV2Test.php @@ -1001,7 +1001,7 @@ class TemplateParserV2Test extends \Codeception\Test\Unit $compiled_output = $tmpl->compileDirect('./tests/_data/template', 'v2example.html'); $tmpvar = preg_match('/(\$__tmp_[0-9a-f]{14})/', $compiled_output, $m) ? $m[1] : ''; - Rhymix\Framework\Storage::write(\RX_BASEDIR . 'tests/_data/template/v2result1.php', $compiled_output); + //Rhymix\Framework\Storage::write(\RX_BASEDIR . 'tests/_data/template/v2result1.php', $compiled_output); $expected = file_get_contents(\RX_BASEDIR . 'tests/_data/template/v2result1.php'); $expected = preg_replace('/(\$__tmp_[0-9a-f]{14})/', $tmpvar, $expected); @@ -1010,7 +1010,7 @@ class TemplateParserV2Test extends \Codeception\Test\Unit $executed_output = $tmpl->compile(); $executed_output = preg_replace('/\n/', '', $executed_output); $tmpvar = preg_match('/(\$__tmp_[0-9a-f]{14})/', $executed_output, $m) ? $m[1] : ''; - Rhymix\Framework\Storage::write(\RX_BASEDIR . 'tests/_data/template/v2result2.php', $executed_output); + //Rhymix\Framework\Storage::write(\RX_BASEDIR . 'tests/_data/template/v2result2.php', $executed_output); $expected = file_get_contents(\RX_BASEDIR . 'tests/_data/template/v2result2.php'); $expected = preg_replace('/(\$__tmp_[0-9a-f]{14})/', $tmpvar, $expected);