From cf6c1b00519f55a74007a7de6e4fbf7feff4de6d Mon Sep 17 00:00:00 2001 From: Ahmad Nazir Raja Date: Thu, 15 May 2014 23:45:12 +0200 Subject: [PATCH] Refactored the code so that any type of asset can be grouped and rendered. --- src/Resume/Command/HtmlCommand.php | 51 +++++++++++++++++++----------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/Resume/Command/HtmlCommand.php b/src/Resume/Command/HtmlCommand.php index b64cc74..d0b4158 100644 --- a/src/Resume/Command/HtmlCommand.php +++ b/src/Resume/Command/HtmlCommand.php @@ -67,6 +67,37 @@ class HtmlCommand extends Command return true; } + protected function generateContent($templatePath, $contentType) { + // We build these into a single string so that we can deploy this resume as a + // single file. + $assetPath = join(DIRECTORY_SEPARATOR, array($templatePath, $contentType)); + + if (!file_exists($assetPath)) { + return ''; + } + + $assets = array(); + + // Our PHAR deployment can't handle the GlobAsset typically used here + foreach (new \DirectoryIterator($assetPath) as $fileInfo) { + if ($fileInfo->isDot() || !$fileInfo->isFile()) { + continue; + } + array_push($assets, new FileAsset($fileInfo->getPathname())); + } + + $collection = new AssetCollection( + $assets + ); + + switch($contentType) { + case 'css': + $collection->ensureFilter(new Filter\LessphpFilter()); + break; + } + return $collection->dump(); + } + protected function generateHtml($source, $template, $refresh) { // Check that the source file is sane @@ -85,25 +116,7 @@ class HtmlCommand extends Command 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 - // single file. - $cssAssetPath = join(DIRECTORY_SEPARATOR, array($templatePath, '/css')); - $cssAssets = array(); - - // Our PHAR deployment can't handle the GlobAsset typically used here - foreach (new \DirectoryIterator($cssAssetPath) as $fileInfo) { - if ($fileInfo->isDot() || !$fileInfo->isFile()) { - continue; - } - array_push($cssAssets, new FileAsset($fileInfo->getPathname())); - } - - $css = new AssetCollection( - $cssAssets, - array(new Filter\LessphpFilter()) - ); - - $style = $css->dump(); + $style = $this->generateContent($templatePath, 'css'); $templateContent = file_get_contents($templateIndexPath); $resumeContent = file_get_contents($source);