mirror of
https://github.com/there4/markdown-resume.git
synced 2024-12-03 08:59:35 -05:00
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:
parent
b403d712a1
commit
8f43dc5c29
@ -21,9 +21,10 @@ if (!defined("IN_PHAR")) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$templatePath = __DIR__ . '/templates';
|
$templatePath = __DIR__ . '/templates';
|
||||||
|
$consoleTemplatePath = __DIR__ . '/src/Resume/Templates';
|
||||||
|
|
||||||
// Init the app with these params
|
// Init the app with these params
|
||||||
$console->initialize($templatePath, $project);
|
$console->initialize($templatePath, $consoleTemplatePath, $project);
|
||||||
|
|
||||||
// Execute the console app.
|
// Execute the console app.
|
||||||
$console->run();
|
$console->run();
|
||||||
|
10
src/Resume/Cli/Converter.php
Normal file
10
src/Resume/Cli/Converter.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
namespace Resume\Cli;
|
||||||
|
|
||||||
|
|
||||||
|
class Converter
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of file Converter.php */
|
@ -16,13 +16,16 @@ class Resume extends Application
|
|||||||
|
|
||||||
public $recentCaseLimit = 10;
|
public $recentCaseLimit = 10;
|
||||||
|
|
||||||
public function initialize($templatePath, $project)
|
public function initialize($templatePath, $consoleTemplatePath, $project)
|
||||||
{
|
{
|
||||||
$runSetup = false;
|
$runSetup = false;
|
||||||
|
|
||||||
// Add the composer information for use in version info and such.
|
// Add the composer information for use in version info and such.
|
||||||
$this->project = $project;
|
$this->project = $project;
|
||||||
|
|
||||||
|
// The absolute path to the html output templates
|
||||||
|
$this->templatePath = $templatePath;
|
||||||
|
|
||||||
// https://github.com/symfony/Console/blob/master/Output/Output.php
|
// https://github.com/symfony/Console/blob/master/Output/Output.php
|
||||||
// the alternative is OutputInterface::OUTPUT_PLAIN;
|
// the alternative is OutputInterface::OUTPUT_PLAIN;
|
||||||
$this->outputFormat = OutputInterface::OUTPUT_NORMAL;
|
$this->outputFormat = OutputInterface::OUTPUT_NORMAL;
|
||||||
@ -32,11 +35,14 @@ class Resume extends Application
|
|||||||
$this->setVersion($this->project->version);
|
$this->setVersion($this->project->version);
|
||||||
|
|
||||||
// Load our commands into the application
|
// Load our commands into the application
|
||||||
|
$this->add(new Command\HtmlCommand());
|
||||||
|
$this->add(new Command\PdfCommand());
|
||||||
$this->add(new Command\SelfUpdateCommand());
|
$this->add(new Command\SelfUpdateCommand());
|
||||||
|
$this->add(new Command\TemplatesCommand());
|
||||||
$this->add(new Command\VersionCommand());
|
$this->add(new Command\VersionCommand());
|
||||||
|
|
||||||
// We'll use [Twig](http://twig.sensiolabs.org/) for template output
|
// We'll use [Twig](http://twig.sensiolabs.org/) for template output
|
||||||
$loader = new \Twig_Loader_Filesystem($templatePath);
|
$loader = new \Twig_Loader_Filesystem($consoleTemplatePath);
|
||||||
$this->twig = new \Twig_Environment(
|
$this->twig = new \Twig_Environment(
|
||||||
$loader,
|
$loader,
|
||||||
array(
|
array(
|
||||||
@ -47,8 +53,8 @@ class Resume extends Application
|
|||||||
);
|
);
|
||||||
|
|
||||||
// These are helpers that we use to format output on the cli: styling and padding and such
|
// These are helpers that we use to format output on the cli: styling and padding and such
|
||||||
$this->twig->addFilter('pad', new \Twig_Filter_Function("FogBugz\Cli\TwigFormatters::strpad"));
|
$this->twig->addFilter('pad', new \Twig_Filter_Function("Resume\Cli\TwigFormatters::strpad"));
|
||||||
$this->twig->addFilter('style', new \Twig_Filter_Function("FogBugz\Cli\TwigFormatters::style"));
|
$this->twig->addFilter('style', new \Twig_Filter_Function("Resume\Cli\TwigFormatters::style"));
|
||||||
$this->twig->addFilter('repeat', new \Twig_Filter_Function("str_repeat"));
|
$this->twig->addFilter('repeat', new \Twig_Filter_Function("str_repeat"));
|
||||||
$this->twig->addFilter('wrap', new \Twig_Filter_Function("wordwrap"));
|
$this->twig->addFilter('wrap', new \Twig_Filter_Function("wordwrap"));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace FogBugz\Cli;
|
namespace Resume\Cli;
|
||||||
|
|
||||||
class TwigFormatters
|
class TwigFormatters
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
namespace Resume\Command;
|
namespace Resume\Command;
|
||||||
|
|
||||||
use Symfony\Component\Console\Command\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\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
@ -9,9 +11,33 @@ class HtmlCommand extends Command
|
|||||||
{
|
{
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
|
// resume html source.md resume.html -template blockish -refresh
|
||||||
$this
|
$this
|
||||||
->setName('html')
|
->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)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
namespace Resume\Command;
|
namespace Resume\Command;
|
||||||
|
|
||||||
use Symfony\Component\Console\Command\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\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
@ -11,7 +13,23 @@ class PdfCommand extends Command
|
|||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('pdf')
|
->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)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
35
src/Resume/Command/TemplatesCommand.php
Normal file
35
src/Resume/Command/TemplatesCommand.php
Normal 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 */
|
9
src/Resume/Templates/templates.twig
Normal file
9
src/Resume/Templates/templates.twig
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
————————————————————————————————————————————————————————————————————————————————
|
||||||
|
<heading> Available Templates </heading>
|
||||||
|
————————————————————————————————————————————————————————————————————————————————
|
||||||
|
{% for template in templates %}
|
||||||
|
{{template.name|style("info")|pad(15, "left")}}{{template.description}}
|
||||||
|
{% endfor %}
|
||||||
|
{% if templates|length == 0%}
|
||||||
|
<notice>There are no templates available</notice>
|
||||||
|
{% endif %}
|
1
templates/blockish/description.txt
Normal file
1
templates/blockish/description.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Default template, serif fonts and pale grey
|
1
templates/modern/description.txt
Normal file
1
templates/modern/description.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Modern and clean
|
1
templates/unstyled/description.txt
Normal file
1
templates/unstyled/description.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Unstyled, useful as a base for your own templates
|
Loading…
x
Reference in New Issue
Block a user