-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New Feature] Blueprint generation from CLI (#17)
* Initial Commit * test * feature is working * renamed variable * added blueprint template * removed unused options
- Loading branch information
1 parent
5cc6a66
commit e3c79da
Showing
4 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
namespace Grav\Plugin\Console; | ||
|
||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Helper\Helper; | ||
use Symfony\Component\Console\Question\ChoiceQuestion; | ||
use Symfony\Component\Console\Question\Question; | ||
|
||
require_once(__DIR__ . '/../classes/DevToolsCommand.php'); | ||
|
||
/** | ||
* Class NewThemeCommand | ||
* @package Grav\Console\Cli\DevTools | ||
*/ | ||
class NewBlueprintCommand extends DevToolsCommand | ||
{ | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $options = []; | ||
|
||
/** | ||
* | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('new-blueprint') | ||
->setAliases(['newblueprint','blueprint']) | ||
->addOption( | ||
'bpname', | ||
'bp', | ||
InputOption::VALUE_OPTIONAL, | ||
'The name of your new Grav theme' | ||
) | ||
->addOption( | ||
'name', | ||
'bn', | ||
InputOption::VALUE_OPTIONAL, | ||
'The name of your new Grav theme' | ||
) | ||
->addOption( | ||
'template', | ||
'tp', | ||
InputOption::VALUE_OPTIONAL, | ||
'The name/username of the developer' | ||
) | ||
->setDescription('Create a blueprint that extend the default.yaml blueprint files') | ||
->setHelp('The <info>new-blueprint</info> command creates a new blueprint file.'); | ||
} | ||
|
||
/** | ||
* @return int|null|void | ||
*/ | ||
protected function serve() | ||
{ | ||
$this->init(); | ||
|
||
/** | ||
* @var array DevToolsCommand $component | ||
*/ | ||
$this->component['type'] = 'blueprint'; | ||
$this->component['template'] = 'modular'; | ||
// $this->component['name'] = 'blueprints'; | ||
$this->component['version'] = '0.1.0'; | ||
$this->component['themename'] = 'bonjour'; | ||
|
||
|
||
$this->options = [ | ||
'name' => $this->input->getOption('name'), | ||
'bpname' => $this->input->getOption('bpname'), | ||
'template' => $this->input->getOption('template'), | ||
|
||
]; | ||
|
||
$this->validateOptions(); | ||
|
||
$this->component = array_replace($this->component, $this->options); | ||
|
||
$helper = $this->getHelper('question'); | ||
|
||
if (!$this->options['template']) { | ||
$question = new ChoiceQuestion( | ||
'Please choose a template type', | ||
array('newtab', 'append') | ||
); | ||
|
||
$this->component['template'] = $helper->ask($this->input, $this->output, $question); | ||
} | ||
if (!$this->options['bpname']) { | ||
$question = new Question('Enter <yellow>Blueprint Name</yellow>: '); | ||
|
||
|
||
$this->component['bpname'] = $helper->ask($this->input, $this->output, $question); | ||
} | ||
// $this->component['template'] = $helper->ask($this->input, $this->output, $question); | ||
|
||
$this->createComponent(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
title: {{ component.bpname }} | ||
'@extends': | ||
type: default | ||
context: blueprints://pages | ||
|
||
form: | ||
fields: | ||
tabs: | ||
type: tabs | ||
active: 1 | ||
|
||
fields: | ||
content: | ||
fields: | ||
header.an_example_text_field: | ||
type: text | ||
label: Add a number | ||
default: 5 | ||
validate: | ||
required: true | ||
type: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
title: Item | ||
'@extends': | ||
type: default | ||
context: blueprints://pages | ||
|
||
form: | ||
fields: | ||
tabs: | ||
fields: | ||
blog: | ||
type: tab | ||
title: {{ component.bpname }} | ||
|
||
fields: | ||
header.mytextfield: |