Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create theme command #2012

Merged
merged 46 commits into from
Apr 13, 2020
Merged
Changes from 45 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
debf3ca
Translation helper controler
boehsermoe Sep 2, 2018
dd0711c
PHPdoc
boehsermoe Sep 2, 2018
a6bfca3
Merge branch 'master' of https://github.com/luyadev/luya
boehsermoe Oct 12, 2018
95730f0
Merge branch 'master' of https://github.com/luyadev/luya
boehsermoe Nov 14, 2018
67b3f8d
Correct parameter order for help
boehsermoe Nov 14, 2018
8b213cc
Merge branch 'master' of https://github.com/luyadev/luya
boehsermoe Nov 19, 2018
c9b7bd2
Merge branch 'master' of https://github.com/luyadev/luya
boehsermoe Nov 22, 2018
b7b9ed2
Merge branch 'master' of https://github.com/luyadev/luya
boehsermoe Nov 23, 2018
49eac4a
Merge branch 'master' of https://github.com/luyadev/luya
boehsermoe Nov 23, 2018
5ca6a29
Documentation for block preview luyadev/luya-module-cms#83
boehsermoe Nov 23, 2018
871d714
Revert PHP doc
boehsermoe Nov 23, 2018
c3910b3
Merge branch 'master' of https://github.com/luyadev/luya
boehsermoe May 30, 2019
e3774d9
Merge branch 'master' of github.com:boehsermoe/luya
boehsermoe Jul 26, 2019
aa24193
Travis mysql connection failed
boehsermoe Jul 27, 2019
76f6a93
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Aug 22, 2019
201ddd6
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Aug 27, 2019
dd43f71
config with env scope
boehsermoe Aug 27, 2019
d66f45d
used call_user_func for callback
boehsermoe Aug 28, 2019
bdb7e22
Update Config.php
nadar Aug 28, 2019
d7ca041
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Sep 8, 2019
7e74c47
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Sep 21, 2019
51a0eca
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Oct 23, 2019
5e43e3e
theme load without exception as default
boehsermoe Oct 25, 2019
d9edc6a
theme load without exception as default
boehsermoe Oct 26, 2019
8495329
theme load without exception as default
boehsermoe Oct 26, 2019
9ceb642
Update ThemeManager.php
boehsermoe Oct 26, 2019
bf9fad8
changelog #1969
boehsermoe Oct 27, 2019
a621db5
Merge branch 'master' of github.com:boehsermoe/luya
boehsermoe Oct 27, 2019
9c40aa7
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Dec 4, 2019
0f01308
Update CHANGELOG.md
nadar Dec 9, 2019
3286b88
add php doc
nadar Dec 9, 2019
b19dd1a
Merge branch 'master' into master
nadar Dec 9, 2019
0b77b7c
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Dec 18, 2019
66220c3
theme management image for guide #1983
boehsermoe Dec 18, 2019
78f846c
Merge branch 'master' of github.com:boehsermoe/luya
boehsermoe Dec 18, 2019
b7f1783
Update app-themes.md
nadar Dec 27, 2019
c60771c
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Dec 30, 2019
4ace75e
Merge branch 'master' of github.com:boehsermoe/luya
boehsermoe Jan 26, 2020
1da04d5
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Feb 29, 2020
b0f92f7
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Mar 14, 2020
442b692
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Apr 4, 2020
6047913
Theme command
boehsermoe Apr 6, 2020
1edcbcd
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Apr 10, 2020
f07ff27
Create theme command
boehsermoe Apr 11, 2020
6bfb018
Merge branch 'master' of github.com:luyadev/luya
boehsermoe Apr 11, 2020
1170a44
Changelog
boehsermoe Apr 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 71 additions & 8 deletions core/console/commands/ThemeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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.');
Expand All @@ -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?")) {
Expand All @@ -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) {
Expand Down Expand Up @@ -119,7 +123,23 @@ private function renderJson(string $basePath, string $themeName)

return Json::encode($themeConfig->toArray(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}

private function renderAssetClass($themeName)
{
$className = ucfirst($themeName) . 'Asset';
return "<?php
namespace app\\themes\\{$themeName};

use luya\web\Asset;

class {$className} extends Asset
{
public \$css = [
\'{$themeName}.css\',
];
}";
}

private function validateParentTheme($input, &$error)
{
if (!preg_match('/^@[a-z]+$/', $input)) {
Expand All @@ -129,7 +149,50 @@ private function validateParentTheme($input, &$error)
$error = 'The theme base path not exists!';
return false;
}

return true;
}

private function renderLayout($themeName)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method renderLayout has 26 lines of code (exceeds 25 allowed). Consider refactoring.

{
$className = ucfirst($themeName) . 'Asset';

return '<?php
/**
* @var $this \luya\web\View
*/
use luya\themes\frontend\\'.$className.';

'.$className.'::register($this);

$this->beginPage();
?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->composition->language; ?>">
<head>
<title><?= $this->title; ?></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="author" content="boehsermoe">
<?php $this->head() ?>
</head>
<body class="homepage">
<?php $this->beginBody() ?>

<div id="wrapper">
<?php echo $content ?>
</div>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
';
}

private function renderCmsLayout()
{
return '<?= $placeholders[\'content\'] ?>';
}
}