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 Sculpin\Core\Console\Command\ContainerAwareCommand;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a new talk from a stub.
|
||||||
|
*/
|
||||||
class NewTalkCommand extends ContainerAwareCommand
|
class NewTalkCommand extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -16,27 +17,9 @@ class NewTalkCommand extends ContainerAwareCommand
|
||||||
*/
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this->setName('content:new:talk')
|
||||||
->setName('content:new:talk')
|
|
||||||
->setDescription('Create a new talk')
|
->setDescription('Create a new talk')
|
||||||
->addArgument(
|
->addArgument('title', InputArgument::REQUIRED, 'The title of the post');
|
||||||
'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'
|
|
||||||
// )
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,10 +29,29 @@ class NewTalkCommand extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
$title = $input->getArgument('title');
|
$title = $input->getArgument('title');
|
||||||
|
|
||||||
|
$filename = string($title)->slugify() . '.php';
|
||||||
|
|
||||||
|
if (file_exists($file = __DIR__ . "/../../../source/_talks/{$filename}")) {
|
||||||
|
$output->writeln("<error>{$filename} already exists.</error>");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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');
|
$contents = file_get_contents(__DIR__ . '/../Resources/stubs/talk.md');
|
||||||
|
|
||||||
$contents = str_replace('{{ title }}', $title, $contents);
|
return str_replace('{{ title }}', $title, $contents);
|
||||||
|
|
||||||
file_put_contents(__DIR__.'/../../../source/_talks/' . string($title)->slugify() .'.md', $contents);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue