Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

178 wiersze
5.8 KiB

  1. <?php
  2. namespace Grav\Plugin\Console;
  3. use Symfony\Component\Console\Input\InputOption;
  4. use Symfony\Component\Console\Question\ChoiceQuestion;
  5. use Symfony\Component\Console\Question\Question;
  6. require_once(__DIR__ . '/../classes/DevToolsCommand.php');
  7. /**
  8. * Class NewThemeCommand
  9. * @package Grav\Console\Cli\DevTools
  10. */
  11. class NewThemeCommand extends DevToolsCommand
  12. {
  13. /**
  14. * @return void
  15. */
  16. protected function configure(): void
  17. {
  18. $this
  19. ->setName('new-theme')
  20. ->setAliases(['newtheme'])
  21. ->addOption(
  22. 'name',
  23. null,
  24. InputOption::VALUE_OPTIONAL,
  25. 'The name of your new Grav theme'
  26. )
  27. ->addOption(
  28. 'desc',
  29. null,
  30. InputOption::VALUE_OPTIONAL,
  31. 'A description of your new Grav theme'
  32. )
  33. ->addOption(
  34. 'dev',
  35. null,
  36. InputOption::VALUE_OPTIONAL,
  37. 'The name/username of the developer'
  38. )
  39. ->addOption(
  40. 'github',
  41. null,
  42. InputOption::VALUE_OPTIONAL,
  43. 'The developer\'s GitHub ID'
  44. )
  45. ->addOption(
  46. 'email',
  47. null,
  48. InputOption::VALUE_OPTIONAL,
  49. 'The developer\'s email'
  50. )
  51. ->addOption(
  52. 'offline',
  53. 'o',
  54. InputOption::VALUE_NONE,
  55. 'Skip online name collision check'
  56. )
  57. ->setDescription('Creates a new Grav theme with the basic required files')
  58. ->setHelp('The <info>new-theme</info> command creates a new Grav instance and performs the creation of a theme.');
  59. }
  60. /**
  61. * @return int
  62. */
  63. protected function serve(): int
  64. {
  65. $this->init();
  66. $input = $this->getInput();
  67. $io = $this->getIO();
  68. $this->component['type'] = 'theme';
  69. $this->component['template'] = 'blank';
  70. $this->component['version'] = '0.1.0';
  71. $this->options = [
  72. 'name' => $input->getOption('name'),
  73. 'description' => $input->getOption('desc'),
  74. 'author' => [
  75. 'name' => $input->getOption('dev'),
  76. 'email' => $input->getOption('email'),
  77. 'githubid' => $input->getOption('github'),
  78. ],
  79. 'offline' => $input->getOption('offline'),
  80. ];
  81. $this->validateOptions();
  82. $this->component = array_replace($this->component, $this->options);
  83. if (!$this->options['name']) {
  84. $question = new Question('Enter <yellow>Theme Name</yellow>');
  85. $question->setValidator(function ($value) {
  86. return $this->validate('name', $value);
  87. });
  88. $this->component['name'] = $io->askQuestion($question);
  89. }
  90. if (!$this->options['description']) {
  91. $question = new Question('Enter <yellow>Theme Description</yellow>');
  92. $question->setValidator(function ($value) {
  93. return $this->validate('description', $value);
  94. });
  95. $this->component['description'] = $io->askQuestion($question);
  96. }
  97. if (!$this->options['author']['name']) {
  98. $question = new Question('Enter <yellow>Developer Name</yellow>');
  99. $question->setValidator(function ($value) {
  100. return $this->validate('developer', $value);
  101. });
  102. $this->component['author']['name'] = $io->askQuestion($question);
  103. }
  104. if (!$this->options['author']['githubid']) {
  105. $question = new Question('Enter <yellow>GitHub ID</yellow> (can be blank)');
  106. $question->setValidator(function ($value) {
  107. return $this->validate('githubid', $value);
  108. });
  109. $this->component['author']['githubid'] = $io->askQuestion($question);
  110. }
  111. if (!$this->options['author']['email']) {
  112. $question = new Question('Enter <yellow>Developer Email</yellow>');
  113. $question->setValidator(function ($value) {
  114. return $this->validate('email', $value);
  115. });
  116. $this->component['author']['email'] = $io->askQuestion($question);
  117. }
  118. $question = new ChoiceQuestion(
  119. 'Please choose an option',
  120. [
  121. 'pure-blank' => 'Basic Theme using Pure.css',
  122. 'tailwind' => 'Basic Theme using tailwind.css and including Alpine.js',
  123. 'tailwind-mix' => 'Same as `tailwind` but more opinionated with Laravel Mix compiler',
  124. 'inheritance' => 'Inherit from another theme',
  125. 'copy' => 'Copy another theme'
  126. ]
  127. );
  128. $this->component['template'] = $io->askQuestion($question);
  129. if ($this->component['template'] === 'inheritance') {
  130. $themes = $this->gpm->getInstalledThemes();
  131. $installedThemes = [];
  132. foreach ($themes as $key => $theme) {
  133. $installedThemes[] = $key;
  134. }
  135. $question = new ChoiceQuestion('Please choose a theme to extend', $installedThemes);
  136. $this->component['extends'] = $io->askQuestion($question);
  137. } elseif ($this->component['template'] === 'copy') {
  138. $themes = $this->gpm->getInstalledThemes();
  139. $installedThemes = [];
  140. foreach ($themes as $key => $theme) {
  141. $installedThemes[] = $key;
  142. }
  143. $question = new ChoiceQuestion(
  144. 'Please choose a theme to copy',
  145. $installedThemes
  146. );
  147. $this->component['copy'] = $io->askQuestion($question);
  148. }
  149. $this->createComponent();
  150. return 0;
  151. }
  152. }