Merge pull request #1 from there4/master

Merge changes from markdown-resume project into my forked version
This commit is contained in:
Erik Waibel 2014-03-24 08:43:40 -07:00
commit 38ab873c95
12 changed files with 50 additions and 45 deletions

View File

@ -24,7 +24,7 @@ at the [blog post for the project][blog].
## Help
```
Markdown Resume Generator version 2.0.1 by Craig Davis
Markdown Resume Generator version 2.0.4 by Craig Davis
Usage:
[options] command [arguments]
@ -85,10 +85,11 @@ The application is deployed as a compiled phar file. In order to add new
commands, you'll need to first install the dependencies:
* `composer install`
* [install pake][pake]
After that, you can run the `md2resume_dev.php` file from the command line.
Check out the pake tooling for more information about the build.
Check out the pake tooling for more information about the build. Pake will be
installed to `./vendor/bin/pake`. So for instance a complete phar file build
looks like `./vendor/bin/pake build`.
## Acknowledgments
@ -99,6 +100,9 @@ are a more comfortable with html than markdown, you should use it.
## Changelog
* __2.0.4__ : Fix path resolution problem with absolute paths to close #16
* __2.0.3__ : Add optional duration to the `--refresh` option to close #15
* __2.0.2__ : Add new dependency check for `mbstring` to close #20
* __2.0.1__ : Add new `swissen` template with Helvetica styling (@beautifulcode)
* __2.0.0__ : Complete rewrite with the [symfony console component][console].
Deployment is now done with a compiled phar file, and development dependencies

Binary file not shown.

View File

@ -8,7 +8,7 @@
"html5"
],
"license": "MIT",
"version": "2.0.1",
"version": "2.0.4",
"selfupdatepath": "://github.com/there4/markdown-resume/raw/master/bin/md2resume",
"selfupdateversion": "://github.com/there4/markdown-resume/raw/master/version",
"authors": [

View File

@ -16,7 +16,7 @@ $app->add('Resume', __DIR__ . '/src');
$console = new Resume\Cli\Resume();
// If we're running from phar, we get these values from the stub
if (!defined("IN_PHAR")) {
if (!defined('IN_PHAR')) {
$project = json_decode(file_get_contents(__DIR__ . '/composer.json'));
}

View File

@ -30,6 +30,9 @@ class Resume extends Application
// the alternative is OutputInterface::OUTPUT_PLAIN;
$this->outputFormat = OutputInterface::OUTPUT_NORMAL;
// Exits on missing dependencies
$this->checkDependencies();
// We do this now because we've loaded the project info from the composer file
$this->setName($this->project->description);
$this->setVersion($this->project->version);
@ -65,6 +68,19 @@ class Resume extends Application
return parent::getLongVersion().' by <comment>Craig Davis</comment>';
}
public function checkDependencies()
{
$output = new ConsoleOutput();
if (!extension_loaded('mbstring')) {
$output->writeln(
"\n<error>Missing Dependency: Please install the Multibyte String Functions.</error>\n" .
"More help: http://www.php.net/manual/en/mbstring.installation.php\n",
$this->outputFormat
);
exit(1);
}
}
public function registerStyles(&$output)
{
// https://github.com/symfony/Console/blob/master/Formatter/OutputFormatterStyle.php

View File

@ -39,9 +39,11 @@ class HtmlCommand extends Command
->addOption(
'refresh',
'r',
InputOption::VALUE_NONE,
'If set, the html will include a meta command to refresh the ' .
'document every 5 seconds.'
InputOption::VALUE_OPTIONAL,
'Regenerate the html and include a meta command to refresh the ' .
'document every periodically. Measured in seconds. Defaults to' .
'5 seconds',
5
);
}
@ -49,7 +51,7 @@ class HtmlCommand extends Command
{
$this->app = $this->getApplication();
$source = $input->getArgument('source');
$destination = trim($input->getArgument('destination'), DIRECTORY_SEPARATOR);
$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'));
@ -58,7 +60,7 @@ class HtmlCommand extends Command
file_put_contents($destFilename, $rendered);
$output->writeln(
sprintf(
"Wrote resume to: <info>%s</info>",
'Wrote resume to: <info>%s</info>',
$destFilename
),
$this->app->outputFormat
@ -71,15 +73,7 @@ class HtmlCommand extends Command
{
// Check that the source file is sane
if (!file_exists($source)) {
$output->writeln(
sprintf(
"<error>Unable to open source file: %s</error>",
$source
),
$this->app->outputFormat
);
return false;
throw new \Exception("Unable to open source file: $source");
}
// Check that our template is sane, or set to the default one
@ -88,16 +82,9 @@ class HtmlCommand extends Command
}
$templatePath = join(DIRECTORY_SEPARATOR, array($this->app->templatePath, basename($template)));
$templateIndexPath = join(DIRECTORY_SEPARATOR, array($templatePath, 'index.html'));
if (!file_exists($templateIndexPath)) {
$output->writeln(
sprintf(
"<error>Unable to open template file: %s</error>",
$templateIndexPath
),
$this->app->outputFormat
);
return false;
if (!file_exists($templateIndexPath)) {
throw new \Exception("Unable to open template file: $templateIndexPath");
}
// We build these into a single string so that we can deploy this resume as a
@ -127,7 +114,7 @@ class HtmlCommand extends Command
$resumeHtml = MarkdownExtra::defaultTransform($resumeContent);
$resumeHtml = SmartyPants::defaultTransform($resumeHtml);
// We'll construct the title for the html document from the h1 and h2 tags
// Construct the title for the html document from the h1 and h2 tags
$simpleDom = new \simple_html_dom();
$simpleDom->load($resumeHtml);
$title = sprintf(
@ -136,17 +123,15 @@ class HtmlCommand extends Command
$simpleDom->find('h2', 0)->innertext
);
// We'll now render the Markdown into an html file with Mustache Templates
// Render the Markdown into an html file with Mustache Templates
$m = new \Mustache_Engine;
$rendered = $m->render(
$templateContent,
array(
'title' => $title,
'style' => $style,
'resume' => $resumeHtml,
'reload' => $refresh
)
);
$rendered = $m->render($templateContent, array(
'title' => $title,
'style' => $style,
'resume' => $resumeHtml,
'reload' => (bool) $refresh,
'refresh_rate' => $refresh
));
return $rendered;
}

View File

@ -36,7 +36,7 @@ class PdfCommand extends HtmlCommand
{
$this->app = $this->getApplication();
$source = $input->getArgument('source');
$destination = trim($input->getArgument('destination'), DIRECTORY_SEPARATOR);
$destination = rtrim($input->getArgument('destination'), DIRECTORY_SEPARATOR);
$template = $input->getOption('template');
$pdfSource = join(DIRECTORY_SEPARATOR, array($destination, '.tmp_pdf_source.html'));
$destFilename = join(DIRECTORY_SEPARATOR, array($destination, pathinfo($source, PATHINFO_FILENAME) . '.pdf'));

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
{{#reload}}
<meta http-equiv="refresh" content="2">
<meta http-equiv="refresh" content="{{refresh_rate}}">
{{/reload}}
<title>{{title}}</title>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
{{#reload}}
<meta http-equiv="refresh" content="2">
<meta http-equiv="refresh" content="{{refresh_rate}}">
{{/reload}}
<title>{{title}}</title>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
{{#reload}}
<meta http-equiv="refresh" content="2">
<meta http-equiv="refresh" content="{{refresh_rate}}">
{{/reload}}
<title>{{title}}</title>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
{{#reload}}
<meta http-equiv="refresh" content="2">
<meta http-equiv="refresh" content="{{refresh_rate}}">
{{/reload}}
<title>{{title}}</title>

View File

@ -1 +1 @@
2.0.1
2.0.4