diff --git a/composer.json b/composer.json index 83b2e76..b8e9599 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,6 @@ }, "minimum-stability": "dev", "require": { - }, - "require-dev": { "symfony/console": "v2.3.4", "symfony/config": "v2.3.4", "symfony/yaml": "v2.3.4", @@ -41,6 +39,12 @@ "twig/twig": "v1.13.2", "mustache/mustache": "2.5.1", "michelf/php-smartypants": "1.6.0-beta1", - "simple-html-dom/simple-html-dom": "1.5.0" + "simple-html-dom/simple-html-dom": "1.5.0", + "kriswallsmith/assetic": "1.1.2" + }, + "autoload": { + "classmap": [ + "vendor/simple-html-dom/simple-html-dom/" + ] } } diff --git a/composer.lock b/composer.lock index e28b552..5f0cddc 100644 --- a/composer.lock +++ b/composer.lock @@ -3,8 +3,171 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "7f8d3ab6c722a1dfa180e92c876ffc63", + "hash": "40e7ded8558afab5c3b481ec2d33dafe", "packages": [ + { + "name": "kriswallsmith/assetic", + "version": "v1.1.2", + "source": { + "type": "git", + "url": "https://github.com/kriswallsmith/assetic.git", + "reference": "735cffd3982c6e8cdebe292d5db39d077f65890f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kriswallsmith/assetic/zipball/735cffd3982c6e8cdebe292d5db39d077f65890f", + "reference": "735cffd3982c6e8cdebe292d5db39d077f65890f", + "shasum": "" + }, + "require": { + "php": ">=5.3.1", + "symfony/process": "~2.1" + }, + "require-dev": { + "cssmin/cssmin": "*", + "joliclic/javascript-packer": "*", + "kamicane/packager": "*", + "leafo/lessphp": "*", + "leafo/scssphp": "*", + "leafo/scssphp-compass": "*", + "mrclay/minify": "*", + "phpunit/phpunit": "~3.7", + "ptachoire/cssembed": "*", + "twig/twig": "~1.6" + }, + "suggest": { + "leafo/lessphp": "Assetic provides the integration with the lessphp LESS compiler", + "leafo/scssphp": "Assetic provides the integration with the scssphp SCSS compiler", + "leafo/scssphp-compass": "Assetic provides the integration with the SCSS compass plugin", + "ptachoire/cssembed": "Assetic provides the integration with phpcssembed to embed data uris", + "twig/twig": "Assetic provides the integration with the Twig templating engine" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-0": { + "Assetic": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kris Wallsmith", + "email": "kris.wallsmith@gmail.com", + "homepage": "http://kriswallsmith.net/" + } + ], + "description": "Asset Management for PHP", + "homepage": "https://github.com/kriswallsmith/assetic", + "keywords": [ + "assets", + "compression", + "minification" + ], + "time": "2013-07-19 00:03:27" + }, + { + "name": "leafo/lessphp", + "version": "v0.4.0", + "source": { + "type": "git", + "url": "https://github.com/leafo/lessphp.git", + "reference": "51f3f06f0fe78a722dabfd14578444bdd078d9de" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/leafo/lessphp/zipball/51f3f06f0fe78a722dabfd14578444bdd078d9de", + "reference": "51f3f06f0fe78a722dabfd14578444bdd078d9de", + "shasum": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.3-dev" + } + }, + "autoload": { + "classmap": [ + "lessc.inc.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT", + "GPL-3.0" + ], + "authors": [ + { + "name": "Leaf Corcoran", + "email": "leafot@gmail.com", + "homepage": "http://leafo.net" + } + ], + "description": "lessphp is a compiler for LESS written in PHP.", + "homepage": "http://leafo.net/lessphp/", + "time": "2013-08-09 17:09:19" + }, + { + "name": "michelf/php-markdown", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/michelf/php-markdown.git", + "reference": "96d8150406f67e683ef4acc09fef91785fef1266" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/michelf/php-markdown/zipball/96d8150406f67e683ef4acc09fef91785fef1266", + "reference": "96d8150406f67e683ef4acc09fef91785fef1266", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-lib": "1.4.x-dev" + } + }, + "autoload": { + "psr-0": { + "Michelf": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Michel Fortin", + "email": "michel.fortin@michelf.ca", + "homepage": "http://michelf.ca/", + "role": "Developer" + }, + { + "name": "John Gruber", + "homepage": "http://daringfireball.net/" + } + ], + "description": "PHP Markdown", + "homepage": "http://michelf.ca/projects/php-markdown/", + "keywords": [ + "markdown" + ], + "time": "2013-11-29 17:09:24" + }, { "name": "michelf/php-smartypants", "version": "1.6.0-beta1", @@ -133,100 +296,6 @@ ], "description": "A copy of the PHP Simple HTML DOM Parser project.", "time": "2013-05-14 22:27:35" - } - ], - "packages-dev": [ - { - "name": "leafo/lessphp", - "version": "v0.4.0", - "source": { - "type": "git", - "url": "https://github.com/leafo/lessphp.git", - "reference": "51f3f06f0fe78a722dabfd14578444bdd078d9de" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/leafo/lessphp/zipball/51f3f06f0fe78a722dabfd14578444bdd078d9de", - "reference": "51f3f06f0fe78a722dabfd14578444bdd078d9de", - "shasum": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.3-dev" - } - }, - "autoload": { - "classmap": [ - "lessc.inc.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT", - "GPL-3.0" - ], - "authors": [ - { - "name": "Leaf Corcoran", - "email": "leafot@gmail.com", - "homepage": "http://leafo.net" - } - ], - "description": "lessphp is a compiler for LESS written in PHP.", - "homepage": "http://leafo.net/lessphp/", - "time": "2013-08-09 17:09:19" - }, - { - "name": "michelf/php-markdown", - "version": "1.4.0", - "source": { - "type": "git", - "url": "https://github.com/michelf/php-markdown.git", - "reference": "96d8150406f67e683ef4acc09fef91785fef1266" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/michelf/php-markdown/zipball/96d8150406f67e683ef4acc09fef91785fef1266", - "reference": "96d8150406f67e683ef4acc09fef91785fef1266", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-lib": "1.4.x-dev" - } - }, - "autoload": { - "psr-0": { - "Michelf": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Michel Fortin", - "email": "michel.fortin@michelf.ca", - "homepage": "http://michelf.ca/", - "role": "Developer" - }, - { - "name": "John Gruber", - "homepage": "http://daringfireball.net/" - } - ], - "description": "PHP Markdown", - "homepage": "http://michelf.ca/projects/php-markdown/", - "keywords": [ - "markdown" - ], - "time": "2013-11-29 17:09:24" }, { "name": "symfony/config", @@ -376,6 +445,53 @@ "homepage": "http://symfony.com", "time": "2014-01-07 13:29:57" }, + { + "name": "symfony/process", + "version": "dev-master", + "target-dir": "Symfony/Component/Process", + "source": { + "type": "git", + "url": "https://github.com/symfony/Process.git", + "reference": "d4b086ca4d6e192d8c2c64fe011159c8bc4c9daa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Process/zipball/d4b086ca4d6e192d8c2c64fe011159c8bc4c9daa", + "reference": "d4b086ca4d6e192d8c2c64fe011159c8bc4c9daa", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Process\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "http://symfony.com", + "time": "2014-01-07 13:29:57" + }, { "name": "symfony/yaml", "version": "v2.3.4", @@ -472,6 +588,9 @@ ], "time": "2013-08-03 15:35:31" } + ], + "packages-dev": [ + ], "aliases": [ diff --git a/src/Resume/Command/HtmlCommand.php b/src/Resume/Command/HtmlCommand.php index 4a4c640..52ac9e4 100644 --- a/src/Resume/Command/HtmlCommand.php +++ b/src/Resume/Command/HtmlCommand.php @@ -6,6 +6,12 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Assetic\Asset\AssetCollection; +use Assetic\Asset\FileAsset; +use Assetic\Asset\GlobAsset; +use Assetic\Filter; +use Michelf\Markdown; +use Michelf\SmartyPants; class HtmlCommand extends Command { @@ -65,18 +71,69 @@ class HtmlCommand extends Command $template = $this->app->defaultTemplate; } $templatePath = join(DIRECTORY_SEPARATOR, array( - $this->app->templatePath, basename($template), '/index.html' + $this->app->templatePath, basename($template) )); - if (!file_exists($templatePath)) { + $templateIndexPath = join(DIRECTORY_SEPARATOR, array( + $templatePath, 'index.html' + )); + if (!file_exists($templateIndexPath)) { $output->writeln( sprintf( "Unable to open template file: %s", - $templatePath + $templateIndexPath ), $this->app->outputFormat ); return false; } + + // We build these into a single string so that we can deploy this resume as a + // single file. + $cssAssetSelector = join(DIRECTORY_SEPARATOR, array($templatePath, '/css/*.css')); + $css = new AssetCollection( + array(new GlobAsset($cssAssetSelector)), + array(new Filter\LessphpFilter()) + ); + $style = $css->dump(); + + $templateContent = file_get_contents($templateIndexPath); + $resumeContent = file_get_contents($source); + + // Process with Markdown, and then use SmartyPants to clean up punctuation. + $resumeHtml = Markdown::defaultTransform($resumeContent); + $resumeHtml = SmartyPants::defaultTransform($resumeHtml); + + // We'll construct the title for the html document from the h1 and h2 tags + $simpleDom = new \simple_html_dom(); + $simpleDom->load($resumeHtml); + $title = sprintf( + '%s | %s', + $simpleDom->find('h1', 0)->innertext, + $simpleDom->find('h2', 0)->innertext + ); + + // We'll now 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 + ) + ); + + // Save the fully rendered html to the final destination + file_put_contents($destination, $rendered); + $output->writeln( + sprintf( + "Wrote resume to: %s", + $destination + ), + $this->app->outputFormat + ); + } }