Add templates command as warmup for other commands

* Add descriptions to the templates
* Update twig formatters and fix some output bugs
This commit is contained in:
Craig Davis
2014-01-12 08:57:39 -07:00
parent b403d712a1
commit 8f43dc5c29
11 changed files with 116 additions and 8 deletions

View File

@@ -2,6 +2,8 @@
namespace Resume\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -9,9 +11,33 @@ class HtmlCommand extends Command
{
protected function configure()
{
// resume html source.md resume.html -template blockish -refresh
$this
->setName('html')
->setDescription('Generate an HTML resume from a markdown file');
->setDescription('Generate an HTML resume from a markdown file')
->addArgument(
'source',
InputArgument::REQUIRED,
'Source markdown document'
)
->addArgument(
'output',
InputArgument::REQUIRED,
'Output html document'
)
->addOption(
'template',
't',
InputOption::VALUE_NONE,
'Which of the templates to use'
)
->addOption(
'refresh',
'r',
InputOption::VALUE_NONE,
'If set, the html will include a meta command to refresh the ' .
'document every 5 seconds.'
);
}
protected function execute(InputInterface $input, OutputInterface $output)

View File

@@ -2,6 +2,8 @@
namespace Resume\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -11,7 +13,23 @@ class PdfCommand extends Command
{
$this
->setName('pdf')
->setDescription('Generate a PDF from a markdown file');
->setDescription('Generate a PDF from a markdown file')
->addArgument(
'source',
InputArgument::REQUIRED,
'Source markdown document'
)
->addArgument(
'output',
InputArgument::REQUIRED,
'Output html document'
)
->addOption(
'template',
't',
InputOption::VALUE_NONE,
'Which of the templates to use'
);
}
protected function execute(InputInterface $input, OutputInterface $output)

View File

@@ -0,0 +1,35 @@
<?php
namespace Resume\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class TemplatesCommand extends Command
{
protected function configure()
{
$this
->setName('templates')
->setDescription('List available templates');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->app = $this->getApplication();
$tplData = array('templates' => array());
foreach(glob($this->app->templatePath . '/*', GLOB_ONLYDIR) as $dir) {
$tplData['templates'][] = (object) array(
'name' => basename($dir),
'description' => file_exists($dir . '/description.txt')
? trim(file_get_contents($dir . '/description.txt'))
: 'No description available'
);
}
$template = $this->app->twig->loadTemplate('templates.twig');
$view = $template->render($tplData);
$output->write($view, true, $this->app->outputFormat);
}
}
/* End of file TemplatesCommand.php */