mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-08 03:22:29 +09:00
Convert include code into a method of Template class
This commit is contained in:
parent
012dbb9ab7
commit
e044e11c5f
4 changed files with 77 additions and 114 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<?php if (!defined("RX_VERSION")) exit(); ?><?php $this->config->version = 2; ?>
|
||||
|
||||
|
||||
<div><?php (function($__dir, $__path, $__vars = null) { $__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html"); if ($__vars) $__tpl->setVars($__vars); echo $__tpl->compile(); })("common/tpl", 'refresh.html'); ?></div>
|
||||
<div><?php echo $this->_v2_include('include', '^/common/tpl/refresh.html'); ?></div>
|
||||
<div><?php $this->_v2_loadResource('^/common/js/plugins/ckeditor/'); ?></div>
|
||||
<?php $this->_v2_loadResource('css/style.scss', 'print', '', []); ?>
|
||||
|
||||
|
|
@ -29,18 +29,18 @@
|
|||
</div>
|
||||
|
||||
<?php ob_start(); $__last_fragment_name = 'rhymix'; ?>
|
||||
<?php $__tmp_64b3371f38fea1 = Context::get('bar') ?? []; if($__tmp_64b3371f38fea1): $__loop_64b3371f38fea1 = $this->_v2_initLoopVar("64b3371f38fea1", $__tmp_64b3371f38fea1); foreach ($__tmp_64b3371f38fea1 as $__Context->k => $__Context->val): ?>
|
||||
<?php $__tmp_RANDOM_LOOP_ID = Context::get('bar') ?? []; if($__tmp_RANDOM_LOOP_ID): $__loop_RANDOM_LOOP_ID = $this->_v2_initLoopVar("RANDOM_LOOP_ID", $__tmp_RANDOM_LOOP_ID); foreach ($__tmp_RANDOM_LOOP_ID as $__Context->k => $__Context->val): ?>
|
||||
<div>
|
||||
<?php if (empty($__Context->nosuchvar)): ?>
|
||||
<img src="/rhymix/tests/_data/template/bar/rhymix.svg" alt="unit tests are cool" />
|
||||
<span <?php if ($__Context->k >= 2): ?>class="<?php echo htmlspecialchars($__Context->val ?? '', \ENT_QUOTES, 'UTF-8', false); ?>"<?php endif; ?>></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php $this->_v2_incrLoopVar($__loop_64b3371f38fea1); endforeach; $this->_v2_removeLoopVar($__loop_64b3371f38fea1); unset($__loop_64b3371f38fea1); else: ?><div>Nothing here...</div><?php endif; ?>
|
||||
<?php $this->_v2_incrLoopVar($__loop_RANDOM_LOOP_ID); endforeach; $this->_v2_removeLoopVar($__loop_RANDOM_LOOP_ID); unset($__loop_RANDOM_LOOP_ID); else: ?><div>Nothing here...</div><?php endif; ?>
|
||||
<?php $this->_fragments[$__last_fragment_name] = ob_get_flush(); ?>
|
||||
|
||||
<?php (function($__dir, $__path, $__vars, $__varname, $__empty = null) { if (!$__vars): $__vars = []; if ($__empty): $__path = $__empty; $__vars[] = ''; endif; endif; foreach ($__vars as $__var): $__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html"); $__tpl->setVars([(string)$__varname => $__var]); echo $__tpl->compile(); endforeach; })($this->relative_dirname, 'incl/eachtest', $__Context->bar, 'var'); ?>
|
||||
<?php (function($__dir, $__path, $__vars, $__varname, $__empty = null) { if (!$__vars): $__vars = []; if ($__empty): $__path = $__empty; $__vars[] = ''; endif; endif; foreach ($__vars as $__var): $__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html"); $__tpl->setVars([(string)$__varname => $__var]); echo $__tpl->compile(); endforeach; })($this->relative_dirname, 'incl/eachtest', [], 'anything', 'incl/empty'); ?>
|
||||
<?php (function($__filename, $__vars, $__varname, $__empty = null) { if (!$__vars): $__vars = []; if ($__empty): $__filename = $__empty; $__vars[] = ''; endif; endif; foreach ($__vars as $__var): echo $this->_v2_include("include", $__filename, [(string)$__varname => $__var]); endforeach; })('incl/eachtest', $__Context->bar, 'var'); ?>
|
||||
<?php (function($__filename, $__vars, $__varname, $__empty = null) { if (!$__vars): $__vars = []; if ($__empty): $__filename = $__empty; $__vars[] = ''; endif; endif; foreach ($__vars as $__var): echo $this->_v2_include("include", $__filename, [(string)$__varname => $__var]); endforeach; })('incl/eachtest', [], 'anything', 'incl/empty'); ?>
|
||||
|
||||
<?php if (!$__Context->m): ?>
|
||||
<p>The full class name is <?php echo htmlspecialchars(get_class(new Rhymix\Framework\Push), \ENT_QUOTES, 'UTF-8', true); ?>, <?php echo htmlspecialchars(Rhymix\Framework\Push::class, \ENT_QUOTES, 'UTF-8', false); ?> really.</p>
|
||||
|
|
|
|||
|
|
@ -90,67 +90,32 @@ class TemplateParserV2Test extends \Codeception\Test\Unit
|
|||
|
||||
// Blade-style @include
|
||||
$source = "@include ('foobar')";
|
||||
$target = implode(' ', [
|
||||
'<?php (function($__dir, $__path, $__vars = null) {',
|
||||
'$__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html");',
|
||||
'if ($__vars) $__tpl->setVars($__vars);',
|
||||
'echo $__tpl->compile(); })($this->relative_dirname, \'foobar\'); ?>'
|
||||
]);
|
||||
$target = "<?php echo \$this->_v2_include('include', 'foobar'); ?>";
|
||||
$this->assertEquals($target, $this->_parse($source));
|
||||
|
||||
// Blade-style @include with variable in filename
|
||||
$source = "@include(\$var)";
|
||||
$target = implode(' ', [
|
||||
'<?php (function($__dir, $__path, $__vars = null) {',
|
||||
'$__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html");',
|
||||
'if ($__vars) $__tpl->setVars($__vars);',
|
||||
'echo $__tpl->compile(); })($this->relative_dirname, $__Context->var); ?>'
|
||||
]);
|
||||
$target = "<?php echo \$this->_v2_include('include', \$__Context->var); ?>";
|
||||
$this->assertEquals($target, $this->_parse($source));
|
||||
|
||||
// Blade-style @include with path relative to Rhymix installation directory
|
||||
$source = '@include ("^/common/js/plugins/foobar/baz.blade.php")';
|
||||
$target = implode(' ', [
|
||||
'<?php (function($__dir, $__path, $__vars = null) {',
|
||||
'$__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html");',
|
||||
'if ($__vars) $__tpl->setVars($__vars);',
|
||||
'echo $__tpl->compile(); })("common/js/plugins/foobar", "baz.blade.php"); ?>'
|
||||
]);
|
||||
$target = '<?php echo $this->_v2_include(\'include\', "^/common/js/plugins/foobar/baz.blade.php"); ?>';
|
||||
$this->assertEquals($target, $this->_parse($source));
|
||||
|
||||
// Blade-style @includeIf with variables
|
||||
$source = "@includeIf('dir/foobar', \$vars)";
|
||||
$target = implode(' ', [
|
||||
'<?php (function($__dir, $__path, $__vars = null) {',
|
||||
'$__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html");',
|
||||
'if (!$__tpl->exists()) return;',
|
||||
'if ($__vars) $__tpl->setVars($__vars);',
|
||||
'echo $__tpl->compile(); })($this->relative_dirname, \'dir/foobar\', $__Context->vars); ?>'
|
||||
]);
|
||||
$target = "<?php echo \$this->_v2_include('includeIf', 'dir/foobar', \$__Context->vars); ?>";
|
||||
$this->assertEquals($target, $this->_parse($source));
|
||||
|
||||
// Blade-style @includeWhen
|
||||
$source = "@includeWhen(\$foo->isBar(), '../../foobar.html', \$vars)";
|
||||
$target = implode(' ', [
|
||||
'<?php (function($__type, $__dir, $__cond, $__path, $__vars = null) {',
|
||||
'if ($__type === "includeWhen" && !$__cond) return;',
|
||||
'if ($__type === "includeUnless" && $__cond) return;',
|
||||
'$__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html");',
|
||||
'if ($__vars) $__tpl->setVars($__vars);',
|
||||
'echo $__tpl->compile(); })("includeWhen", $this->relative_dirname, $__Context->foo->isBar(), \'../../foobar.html\', $__Context->vars); ?>'
|
||||
]);
|
||||
$target = "<?php echo \$this->_v2_include('includeWhen', \$__Context->foo->isBar(), '../../foobar.html', \$__Context->vars); ?>";
|
||||
$this->assertEquals($target, $this->_parse($source));
|
||||
|
||||
// Blade-style @includeUnless with path relative to Rhymix installation directory
|
||||
$source = "@includeUnless (false, '^common/tpl/foobar.html', \$vars)";
|
||||
$target = implode(' ', [
|
||||
'<?php (function($__type, $__dir, $__cond, $__path, $__vars = null) {',
|
||||
'if ($__type === "includeWhen" && !$__cond) return;',
|
||||
'if ($__type === "includeUnless" && $__cond) return;',
|
||||
'$__tpl = new \Rhymix\Framework\Template($__dir, $__path, "html");',
|
||||
'if ($__vars) $__tpl->setVars($__vars);',
|
||||
'echo $__tpl->compile(); })("includeUnless", "common/tpl", false, \'foobar.html\', $__Context->vars); ?>'
|
||||
]);
|
||||
$target = "<?php echo \$this->_v2_include('includeUnless', false, '^common/tpl/foobar.html', \$__Context->vars); ?>";
|
||||
$this->assertEquals($target, $this->_parse($source));
|
||||
|
||||
// Blade-style @each
|
||||
|
|
@ -160,7 +125,7 @@ class TemplateParserV2Test extends \Codeception\Test\Unit
|
|||
|
||||
// Blade-style @each with fallback template
|
||||
$source = "@each('incl/eachtest', \$jobs, 'job', 'incl/empty')";
|
||||
$target = 'if ($__empty): $__path = $__empty;';
|
||||
$target = 'echo $this->_v2_include("include"';
|
||||
$this->assertStringContainsString($target, $this->_parse($source));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue