From a5c13d0c43956bf74b64aa6be368c84bdb442f6e Mon Sep 17 00:00:00 2001 From: Craig Davis Date: Sun, 12 Jan 2014 13:41:44 -0700 Subject: [PATCH] Add initial phar file, bin/md2resume * Update output to be a folder name instead of a filename * Add improved error checking for paths * Move the examples from /resume to /examples --- bin/resume.php | 129 --------------------- {output => examples/output}/EMPTY | 0 {resume => examples/source}/sample.md | 0 {resume => examples/source}/sample_long.md | 0 {resume => examples/source}/zhsample.md | 0 resume2.php => md2resume_dev.php | 0 6 files changed, 129 deletions(-) delete mode 100755 bin/resume.php rename {output => examples/output}/EMPTY (100%) rename {resume => examples/source}/sample.md (100%) rename {resume => examples/source}/sample_long.md (100%) rename {resume => examples/source}/zhsample.md (100%) rename resume2.php => md2resume_dev.php (100%) diff --git a/bin/resume.php b/bin/resume.php deleted file mode 100755 index ae0030c..0000000 --- a/bin/resume.php +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env php - "", - "output" => "./output", - "template" => "modern", - "refresh" => false, - "pdf" => false -); - -// Command line arguments to populate the config -$opts = array( - "s:" => "source:", // source - "o:" => "output:", // output - "t:" => "template:", // template - "r" => "refresh", // refresh - "p" => "pdf" // pdf output -); - -// Fetch the options from the command line arguments -$options = getopt(implode("", array_keys($opts)), array_values($opts)); - -// Consolidate the short and long options into the config array -// Make sure that boolean options are set appropriately. -foreach ($opts as $short => $long) { - $isBool = (substr($short, -1, 1) !== ":"); - $short = trim($short, ":"); - $long = trim($long, ":"); - - if (isset($options[$short])) { - $config->$long = $isBool ? true : $options[$short]; - } - else if (isset($options[$long])) { - $config->$long = $isBool ? true : $options[$long]; - } -} - -if (empty($config->source)) { - exit("Please specify a source document: bin/resume.php -s resume/resume.pdf\n"); -} - -$basename = pathinfo($config->source, PATHINFO_FILENAME); -$template_path = realpath(__DIR__ . '/../templates/' . $config->template); -$pdf_source = $config->output . '/' . $basename . '-pdf.html'; -$output = $config->output . '/' . $basename . '.html'; -$pdf_output = $config->output . '/' . $basename . '.pdf'; - -if (!file_exists($config->source)) { - exit("Please specify a valid source file.\n"); -} - -if (!file_exists($template_path)) { - // TODO: List templates - exit("Please specify a valid template.\n"); -} - -// We build these into a single string so that we can deploy this resume as a -// single file. -$css = new AssetCollection( - array(new GlobAsset($template_path . '/css/*.css')), - array(new Filter\LessphpFilter()) -); -$style = $css->dump(); - -$template = file_get_contents($template_path . '/index.html'); -$resume = file_get_contents($config->source); - -// Process with Markdown, and then use SmartyPants to clean up punctuation. -$resume = SmartyPants(Markdown($resume)); - -// We'll construct the title for the html document from the h1 and h2 tags -$html = str_get_html($resume); -$title = sprintf( - '%s | %s', - $html->find('h1', 0)->innertext, - $html->find('h2', 0)->innertext -); - -// We'll now render the Markdown into an html file with Mustache Templates -$m = new Mustache; -$rendered = $m->render( - $template, - array( - 'title' => $title, - 'style' => $style, - 'resume' => $resume, - 'reload' => $config->refresh - ) -); - -// Save the fully rendered html to the final destination -file_put_contents($output, $rendered); -echo "Wrote html to $output\n"; - -// If the user wants to make a pdf file, we'll use wkhtmltopdf to convert -// the html document into a nice looking pdf. -if ($config->pdf) { - - // The pdf needs some extra css rules, and so we'll add them here - // to our html document - $pdf_classed = str_replace('body class=""', 'body class="pdf"', $rendered); - - // Save the new pdf-ready html to a temp destination - file_put_contents($pdf_source, $pdf_classed ); - - // Process the document with wkhtmltopdf - exec('wkhtmltopdf ' . $pdf_source .' ' . $pdf_output); - - // Unlink the temporary file - unlink($pdf_source); - echo "Wrote pdf to $pdf_output\n"; -} - -/* End of file resume.php */ diff --git a/output/EMPTY b/examples/output/EMPTY similarity index 100% rename from output/EMPTY rename to examples/output/EMPTY diff --git a/resume/sample.md b/examples/source/sample.md similarity index 100% rename from resume/sample.md rename to examples/source/sample.md diff --git a/resume/sample_long.md b/examples/source/sample_long.md similarity index 100% rename from resume/sample_long.md rename to examples/source/sample_long.md diff --git a/resume/zhsample.md b/examples/source/zhsample.md similarity index 100% rename from resume/zhsample.md rename to examples/source/zhsample.md diff --git a/resume2.php b/md2resume_dev.php similarity index 100% rename from resume2.php rename to md2resume_dev.php