diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 3476f18a5..7a72b2c44 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -7,6 +7,7 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE + [#2011](https://github.com/luyadev/luya/pull/2011) Update theme create command to work on Windows + [#2009](https://github.com/luyadev/luya/pull/2009) Improve the performance of mb_str_split, this will strongly improve the speed when working with LUYA crawler result previews. ++ [#2012](https://github.com/luyadev/luya/pull/2012) Extend the create theme cli command with assets. ## 1.2.1 (7. April 2020) diff --git a/core/console/commands/ThemeController.php b/core/console/commands/ThemeController.php index 73f1612ba..90196864a 100644 --- a/core/console/commands/ThemeController.php +++ b/core/console/commands/ThemeController.php @@ -33,7 +33,7 @@ class ThemeController extends \luya\console\Command public function actionCreate(string $themeName = null) { Console::clearScreenBeforeCursor(); - + $themeName = $this->prompt("Enter the name (lower case) of the theme you like to generate:", ['default' => $themeName]); $newName = preg_replace("/[^a-z]/", "", strtolower($themeName)); @@ -44,13 +44,13 @@ public function actionCreate(string $themeName = null) $themeName = $newName; } } - + $availableModules = implode(', ', array_column(Yii::$app->getFrontendModules(), 'id')); $themeLocation = $this->prompt("Enter the theme location where to generate (as path alias e.g. app, $availableModules):", ['default' => 'app']); $themeLocation = '@' . ltrim($themeLocation, '@'); - + preg_match("#^@[A-z]+#", $themeLocation, $newThemeLocation); - + if ($newThemeLocation[0] !== $themeLocation) { if (!$this->confirm("We have changed the name to '{$newThemeLocation[0]}'. Do you want to proceed with this name?")) { return $this->outputError('Abort by user.'); @@ -61,11 +61,11 @@ public function actionCreate(string $themeName = null) $basePath = $themeLocation . '/themes/' . $themeName; $themeFolder = Yii::getAlias($basePath); - + if (file_exists($themeFolder)) { return $this->outputError("The folder " . $themeFolder . " exists already."); } - + $this->outputInfo("Theme path alias: " . $basePath); $this->outputInfo("Theme real path: " . $themeFolder); if (!$this->confirm("Do you want continue?")) { @@ -79,13 +79,17 @@ public function actionCreate(string $themeName = null) 'views/layouts', 'views/cmslayouts', ]; - + foreach ($folders as $folder) { FileHelper::createDirectory($themeFolder . DIRECTORY_SEPARATOR . $folder); } $contents = [ $themeFolder. DIRECTORY_SEPARATOR . 'theme.json' => $this->renderJson($basePath, $themeName), + $themeFolder. DIRECTORY_SEPARATOR . ucfirst($themeName) . 'Asset.php' => $this->renderAssetClass($themeName), + $themeFolder. DIRECTORY_SEPARATOR . 'resources/'. $themeName .'-asset/style.css' => '', + $themeFolder. DIRECTORY_SEPARATOR . 'views/layouts/theme.php' => $this->renderLayout($themeName), + $themeFolder. DIRECTORY_SEPARATOR . 'views/cmslayouts/theme.php' => $this->renderCmsLayout($themeName), ]; foreach ($contents as $fileName => $content) { @@ -119,7 +123,13 @@ private function renderJson(string $basePath, string $themeName) return Json::encode($themeConfig->toArray(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } - + + /** + * @param $input + * @param $error + * + * @return bool + */ private function validateParentTheme($input, &$error) { if (!preg_match('/^@[a-z]+$/', $input)) { @@ -129,7 +139,78 @@ private function validateParentTheme($input, &$error) $error = 'The theme base path not exists!'; return false; } - + return true; } + + /** + * @param $themeName + * + * @return string + */ + private function renderAssetClass($themeName) + { + $className = ucfirst($themeName) . 'Asset'; + return "beginPage(); +?> + + + + <?= $this->title; ?> + + + + head() ?> + + + beginBody() ?> + +
+ +
+ + endBody() ?> + + +endPage() ?> +'; + } + + /** + * @return string + */ + private function renderCmsLayout() + { + return ''; + } }