* zin: support to use raw content from buffer.

This commit is contained in:
sunhao
2023-06-20 20:49:07 +08:00
parent de215567ce
commit b85aa4f7d1
6 changed files with 49 additions and 23 deletions
+3 -7
View File
@@ -1011,14 +1011,10 @@ class baseControl
*/
extract(\zin\zin::$data);
include $viewFile;
/*
extract((array)$this->view);
ob_start();
if(isset($hookFiles)) foreach($hookFiles as $hookFile) if(file_exists($hookFile)) include $hookFile;
$this->output .= ob_get_contents();
ob_end_clean();
*/
include $viewFile;
ob_end_flush();
echo $output;
/**
* 渲染完毕后,再切换回之前的路径。
+9 -2
View File
@@ -156,6 +156,10 @@ class wg
if(isset($app->zinErrors)) $zinDebug['errors'] = $app->zinErrors;
}
$rawContent = ob_get_contents();
if(!is_string($rawContent)) $rawContent = '';
ob_end_clean();
if(is_object($result))
{
if($zinDebug && isset($result['zinDebug'])) $result['zinDebug'] = $zinDebug;
@@ -167,8 +171,10 @@ class wg
{
if(!isset($item['type']) || $item['type'] !== 'html') continue;
$item['data'] = str_replace('/*{{ZIN_PAGE_CSS}}*/', $css, $item['data']);
$item['data'] = str_replace('/*{{ZIN_PAGE_JS}}*/', $js, $item['data']);
$item['data'] = str_replace('/*{{ZIN_PAGE_CSS}}*/', $css, $item['data']);
$item['data'] = str_replace('/*{{ZIN_PAGE_JS}}*/', $js, $item['data']);
$item['data'] = str_replace('<!-- {{RAW_CONTENT}} -->', $rawContent, $item['data']);
$result[$name]['data'] = $item['data'];
}
if($zinDebug && isset($result['zinDebug'])) $result['zinDebug'] = $zinDebug;
@@ -179,6 +185,7 @@ class wg
if($zinDebug) $js .= h::createJsVarCode('window.zinDebug', $zinDebug);
$result = str_replace('/*{{ZIN_PAGE_CSS}}*/', $css, $result);
$result = str_replace('/*{{ZIN_PAGE_JS}}*/', $js, $result);
$result = str_replace('<!-- {{RAW_CONTENT}} -->', $rawContent, $result);
}
echo $result;
+10
View File
@@ -280,3 +280,13 @@ function groupWgInList(wg|array $items, string|array $types): array
$groups[] = $restList;
return $groups;
}
/**
* Create raw content placeholder.
*
* @return directive
*/
function rawContent(): directive
{
return h::comment('{{RAW_CONTENT}}');
}
+9 -2
View File
@@ -3,15 +3,22 @@ namespace zin;
class fragment extends wg
{
static $defineProps = array
(
'rawContent?: bool=true'
);
protected function build()
{
$css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/');
$js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS'));
$css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/');
$js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS'));
$rawContent = $this->prop('rawContent');
return array
(
h::css($css, setClass('zin-page-css')),
$this->children(),
$rawContent ? rawContent() : null,
h::js($js, setClass('zin-page-js'))
);
}
+5 -2
View File
@@ -14,6 +14,7 @@ class modalDialog extends wg
'footerActions?: array',
'footerClass?: string',
'footerProps?: array',
'rawContent?: bool=true'
);
static $defineBlocks = array(
@@ -81,10 +82,12 @@ class modalDialog extends wg
protected function buildBody()
{
$rawContent = $this->prop('rawContent');
return div
(
setClass('modal-body'),
$this->children()
$this->children(),
$rawContent ? rawContent() : null,
);
}
@@ -93,7 +96,7 @@ class modalDialog extends wg
return div
(
setClass('modal-dialog'),
set($this->props->skip(array_keys(static::getDefinedProps()))),
set($this->getRestProps()),
div
(
setClass('modal-content'),
+13 -10
View File
@@ -13,7 +13,8 @@ class pageBase extends wg
'bodyClass?: array|string',
'zui?: bool',
'lang?: string',
'display?: bool'
'display?: bool',
'rawContent?: bool=true'
);
static $defaultProps = array
@@ -48,15 +49,16 @@ class pageBase extends wg
$head = $this->buildHead();
$body = $this->buildBody();
$jsConfig = \js::getJSConfigVars();
$bodyProps = $this->prop('bodyProps');
$bodyClass = $this->prop('bodyClass');
$metas = $this->prop('metas');
$title = $this->props->get('title', data('title')) . " - $lang->zentaoPMS";
$attrs = $this->props->skip(array_keys(static::getDefinedProps()));
$css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/');
$js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS'));
$imports = context::current()->getImportList();
$jsConfig = \js::getJSConfigVars();
$bodyProps = $this->prop('bodyProps');
$bodyClass = $this->prop('bodyClass');
$metas = $this->prop('metas');
$rawContent = $this->prop('rawContent');
$title = $this->props->get('title', data('title')) . " - $lang->zentaoPMS";
$attrs = $this->props->skip(array_keys(static::getDefinedProps()));
$css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/');
$js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS'));
$imports = context::current()->getImportList();
$jsConfig->zin = true;
if($config->debug)
@@ -95,6 +97,7 @@ class pageBase extends wg
empty($imports) ? null : h::import($imports),
h::css($css, setClass('zin-page-css')),
$body,
$rawContent ? rawContent() : null,
h::js($js, setClass('zin-page-js'))
)
);