feat: Концепция css модулей в компонентах
This commit is contained in:
parent
d692538163
commit
c94204a506
4 changed files with 45 additions and 19 deletions
|
|
@ -103,13 +103,15 @@ class Component
|
|||
$default = $config->get('site', 'template');
|
||||
$template = ($this->template) ? $this->template : $this->getTemplateName($config);
|
||||
|
||||
// Определение пути к шаблону
|
||||
$selected = null;
|
||||
$tpl = null;
|
||||
foreach ($this->viewPath as $index => $viewPath) {
|
||||
// Загружать шаблон по умолчанию если не найден текущий
|
||||
$dir = Path::join($this->viewPath[$index], 'templates', $template);
|
||||
if(is_dir($dir)) {
|
||||
$tpl = new PHPTAL(Path::join($this->viewPath[$index], 'templates', $template, $name));
|
||||
$source = Path::join($this->viewPath[$index], 'templates', $template, $name);
|
||||
$tpl = new PHPTAL($source);
|
||||
$tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
|
||||
$selected = $index;
|
||||
break;
|
||||
|
|
@ -119,7 +121,8 @@ class Component
|
|||
if ($selected === null) {
|
||||
// Последний вариант viewPath, путь к папке компонента
|
||||
$selected = count($this->viewPath) - 1;
|
||||
$tpl = new PHPTAL(Path::join($this->viewPath[$selected], 'templates', 'modern', $name));
|
||||
$source = Path::join($this->viewPath[$selected], 'templates', 'modern', $name);
|
||||
$tpl = new PHPTAL($source);
|
||||
$tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION);
|
||||
$template = 'modern';
|
||||
}
|
||||
|
|
@ -136,6 +139,7 @@ class Component
|
|||
}
|
||||
$tpl->set('base', $this->config->get('site', 'web'));
|
||||
|
||||
$tpl->set('source__', $source);
|
||||
$tpl->set('component_base', $this->webPath[$selected]);
|
||||
$tpl->set('component', Path::join($this->webPath[$selected], 'templates', $template));
|
||||
$tpl->set('component_id', $this->component_id);
|
||||
|
|
|
|||
|
|
@ -46,10 +46,11 @@ class Database extends PDO
|
|||
static function getConnection(array $dsn)
|
||||
{
|
||||
|
||||
/** @var Database|null */
|
||||
$connection = null;
|
||||
if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') {
|
||||
$port = (isset($dsn['port'])) ? "port={$dsn['port']};" : "";
|
||||
$connection/*: Database*/ = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
|
||||
$connection = new self("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']);
|
||||
if ($dsn['phptype'] == 'pgsql') {
|
||||
$connection->query('SET client_encoding="UTF-8"');
|
||||
}
|
||||
|
|
@ -57,9 +58,11 @@ class Database extends PDO
|
|||
if (isset($dsn['schema'])) {
|
||||
$connection->query('SET search_path TO ' . $dsn['schema']);
|
||||
}
|
||||
}
|
||||
if ($dsn['phptype'] == 'sqlite') {
|
||||
$connection/*: Database*/ = new self("{$dsn['phptype']}:{$dsn['database']}");
|
||||
} elseif ($dsn['phptype'] == 'sqlite::memory') {
|
||||
$connection = new self("{$dsn['phptype']}:");
|
||||
$connection->sqliteCreateFunction('LOWER', 'sqliteLower', 1);
|
||||
} elseif ($dsn['phptype'] == 'sqlite') {
|
||||
$connection = new self("{$dsn['phptype']}:{$dsn['database']}");
|
||||
$connection->setAttribute(PDO::ATTR_TIMEOUT, 5);
|
||||
$mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL';
|
||||
$connection->query("PRAGMA journal_mode=$mode");
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ class Path
|
|||
}
|
||||
|
||||
/**
|
||||
* Находит путь относительно текущего путя
|
||||
* Находит путь относительно текущего пути
|
||||
*
|
||||
* @param string $name Полный путь к файлу
|
||||
*
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use PHPTAL_Php_TalesInternal,
|
|||
PHPTAL_Tales,
|
||||
PHPTAL_TalesRegistry;
|
||||
|
||||
class Tales_DateTime implements PHPTAL_Tales
|
||||
class Tales_Inline implements PHPTAL_Tales
|
||||
{
|
||||
static public function date($expression, $nothrow = false) {
|
||||
return "ctiso\\Tales::phptal_date(".PHPTAL_Php_TalesInternal::path($expression).")";
|
||||
|
|
@ -20,24 +20,24 @@ class Tales_DateTime implements PHPTAL_Tales
|
|||
static public function time($expression, $nothrow = false) {
|
||||
return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path($expression).")";
|
||||
}
|
||||
}
|
||||
|
||||
class Tales_Component implements PHPTAL_Tales
|
||||
{
|
||||
static public function component($expression, $nothrow = false)
|
||||
{
|
||||
$s = PHPTAL_Php_TalesInternal::string($expression);
|
||||
return "ctiso\\Tales::phptal_component(" . $s . ")";
|
||||
}
|
||||
}
|
||||
|
||||
class Tales_Assets implements PHPTAL_Tales
|
||||
{
|
||||
|
||||
static public function assets($expression, $nothrow = false)
|
||||
{
|
||||
$s = PHPTAL_Php_TalesInternal::string($expression);
|
||||
return "ctiso\\Tales::phptal_asset(" . $s . ")";
|
||||
}
|
||||
|
||||
static public function module($expression, $nothrow = false)
|
||||
{
|
||||
$s = PHPTAL_Php_TalesInternal::string($expression);
|
||||
return "ctiso\\Tales::phptal_module(" . $s . ", \$ctx)";
|
||||
}
|
||||
}
|
||||
|
||||
class Tales {
|
||||
|
|
@ -56,6 +56,24 @@ class Tales {
|
|||
return "";
|
||||
}
|
||||
|
||||
static function phptal_module($s, $ctx) {
|
||||
$dir = dirname($ctx->source__);
|
||||
$web = $ctx->component;
|
||||
$file = \realpath($dir . '/' . $s);
|
||||
error_log($web);
|
||||
// Для модулей использовать только локальный путь
|
||||
// Преобразовать в url
|
||||
self::$site->addStyleSheet(Path::join($web, $s));
|
||||
// Получить карту с ассоциациями для модуля
|
||||
// file_get_contents($file);
|
||||
// Присвоить значения
|
||||
// <tal:block tal:define="" />
|
||||
$data = file_get_contents(strtr($file, ['.css' => '.json']));
|
||||
error_log($data);
|
||||
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Функция подключения компонента
|
||||
*/
|
||||
|
|
@ -77,9 +95,10 @@ class Tales {
|
|||
|
||||
/* Регистрация нового префикса для подключения компонента */
|
||||
$tales = PHPTAL_TalesRegistry::getInstance();
|
||||
$tales->registerPrefix('component', ['ctiso\\Tales_Component', 'component']);
|
||||
$tales->registerPrefix('date', ['ctiso\\Tales_DateTime', 'date']);
|
||||
$tales->registerPrefix('time', ['ctiso\\Tales_DateTime', 'time']);
|
||||
$tales->registerPrefix('assets', ['ctiso\\Tales_Assets', 'assets']);
|
||||
$tales->registerPrefix('component', ['ctiso\\Tales_Inline', 'component']);
|
||||
$tales->registerPrefix('date', ['ctiso\\Tales_Inline', 'date']);
|
||||
$tales->registerPrefix('time', ['ctiso\\Tales_Inline', 'time']);
|
||||
$tales->registerPrefix('assets', ['ctiso\\Tales_Inline', 'assets']);
|
||||
$tales->registerPrefix('module', ['ctiso\\Tales_Inline', 'module']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue