Update new talk command
This commit is contained in:
parent
da4ef444d6
commit
6669c72648
|
@ -5,10 +5,11 @@ namespace WebsiteBundle\Command;
|
|||
use Sculpin\Core\Console\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Generate a new talk from a stub.
|
||||
*/
|
||||
class NewTalkCommand extends ContainerAwareCommand
|
||||
{
|
||||
/**
|
||||
|
@ -16,27 +17,9 @@ class NewTalkCommand extends ContainerAwareCommand
|
|||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('content:new:talk')
|
||||
$this->setName('content:new:talk')
|
||||
->setDescription('Create a new talk')
|
||||
->addArgument(
|
||||
'title',
|
||||
InputArgument::REQUIRED,
|
||||
'The title of the post'
|
||||
);
|
||||
// ->addOption(
|
||||
// 'filename',
|
||||
// null,
|
||||
// InputOption::VALUE_OPTIONAL,
|
||||
// 'The name of the file to generate'
|
||||
// )
|
||||
// ->addOption(
|
||||
// 'force',
|
||||
// 'f',
|
||||
// InputOption::VALUE_NONE,
|
||||
// 'Overwrite the file if it already exists'
|
||||
// )
|
||||
;
|
||||
->addArgument('title', InputArgument::REQUIRED, 'The title of the post');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,10 +29,29 @@ class NewTalkCommand extends ContainerAwareCommand
|
|||
{
|
||||
$title = $input->getArgument('title');
|
||||
|
||||
$contents = file_get_contents(__DIR__.'/../Resources/stubs/talk.md');
|
||||
$filename = string($title)->slugify() . '.php';
|
||||
|
||||
$contents = str_replace('{{ title }}', $title, $contents);
|
||||
if (file_exists($file = __DIR__ . "/../../../source/_talks/{$filename}")) {
|
||||
$output->writeln("<error>{$filename} already exists.</error>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
file_put_contents(__DIR__.'/../../../source/_talks/' . string($title)->slugify() .'.md', $contents);
|
||||
file_put_contents($file, $this->compileTemplate($title));
|
||||
|
||||
$output->writeln("<info>{$filename} was created.</info>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and compile the template with the correct data.
|
||||
*
|
||||
* @param string $title The title of the talk
|
||||
*
|
||||
* @return bool|mixed|string
|
||||
*/
|
||||
private function compileTemplate($title)
|
||||
{
|
||||
$contents = file_get_contents(__DIR__ . '/../Resources/stubs/talk.md');
|
||||
|
||||
return str_replace('{{ title }}', $title, $contents);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue