Skip to content

Commit

Permalink
added optional argument to override output filename
Browse files Browse the repository at this point in the history
  • Loading branch information
oflannabhra committed Jan 21, 2015
1 parent a34b85e commit 5b817f3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Binary file modified bin/md2resume
Binary file not shown.
22 changes: 21 additions & 1 deletion src/Resume/Command/HtmlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,31 @@ protected function configure()
InputOption::VALUE_REQUIRED,
'Regenerate the html and include a meta command to refresh the ' .
'document every periodically. Measured in seconds.'
)
->addOption(
'output',
'o',
InputOption::VALUE_REQUIRED,
'The optional override of default filename to output to'
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->app = $this->getApplication();
$source = $input->getArgument('source');
$sourceName = pathinfo($source, PATHINFO_FILENAME);
$destination = rtrim($input->getArgument('destination'), DIRECTORY_SEPARATOR);
$template = $input->getOption('template');
$refresh = $input->getOption('refresh');
$destFilename = join(DIRECTORY_SEPARATOR, array($destination, pathinfo($source, PATHINFO_FILENAME) . '.html'));
$optFilename = $input->getOption('output');
$destFilename = "";

if ($optFilename) {
$destFilename = $destination . DIRECTORY_SEPARATOR . $optFilename . '.html';
} else {
$destFilename = $destination . DIRECTORY_SEPARATOR . $sourceName . '.html';
}

$rendered = $this->generateHtml($source, $template, $refresh);
file_put_contents($destFilename, $rendered);
Expand Down Expand Up @@ -151,6 +165,12 @@ protected function generateHtml($source, $template, $refresh)

return $rendered;
}

protected function determineOutfile($outputFilename)
{
return join(DIRECTORY_SEPARATOR, array($destination, pathinfo($source, PATHINFO_FILENAME) . '.html'));

}
}

/* End of file HtmlCommand.php */
14 changes: 14 additions & 0 deletions src/Resume/Command/PdfCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,32 @@ protected function configure()
't',
InputOption::VALUE_REQUIRED,
'Which of the templates to use'
)
->addOption(
'output',
'o',
InputOption::VALUE_REQUIRED,
'The optional override of default filename to output to'
);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->app = $this->getApplication();
$source = $input->getArgument('source');
$sourceName = pathinfo($source, PATHINFO_FILENAME);
$destination = rtrim($input->getArgument('destination'), DIRECTORY_SEPARATOR);
$template = $input->getOption('template');
$pdfSource = join(DIRECTORY_SEPARATOR, array($destination, '.tmp_pdf_source.html'));
$optFilename = $input->getOption('output');

$destFilename = join(DIRECTORY_SEPARATOR, array($destination, pathinfo($source, PATHINFO_FILENAME) . '.pdf'));

if ($optFilename) {
$destFilename = $destination . DIRECTORY_SEPARATOR . $optFilename . '.pdf';
} else {
$destFilename = $destination . DIRECTORY_SEPARATOR . $sourceName . '.pdf';
}
// Make sure we've got out converter available
exec('wkhtmltopdf -V', $results, $returnVal);
if ($returnVal) {
Expand Down

0 comments on commit 5b817f3

Please sign in to comment.