Skip to content

Commit

Permalink
Updating to bldr 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptiklemur committed Oct 12, 2014
1 parent ef6cf25 commit e8586f6
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 191 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"coffeescript/coffeescript": "~1.3.1"
},
"require-dev": {
"bldr-io/bldr": "~6.2@stable",
"bldr-io/bldr": "~7.0@stable",
"dflydev/embedded-composer": "dev-master",
"composer/composer": "dev-master"
},
Expand Down
114 changes: 0 additions & 114 deletions src/Call/LessCall.php

This file was deleted.

12 changes: 6 additions & 6 deletions src/FrontendBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class FrontendBlock extends AbstractBlock
*/
protected function assemble(array $config, SymfonyContainerBuilder $container)
{
$this->addCall('bldr_frontend.less', 'Bldr\Block\Frontend\Call\LessCall');
$this->addCall('bldr_frontend.sass', 'Bldr\Block\Frontend\Call\SassCall');
$this->addCall('bldr_frontend.coffee', 'Bldr\Block\Frontend\Call\CoffeeCall');
$this->addCall('bldr_frontend.concat', 'Bldr\Block\Frontend\Call\ConcatCall');
$this->addCall('bldr_frontend.minify.css', 'Bldr\Block\Frontend\Call\Minify\CssCall');
$this->addCall('bldr_frontend.minify.js', 'Bldr\Block\Frontend\Call\Minify\JsCall');
$this->addTask('bldr_frontend.less', 'Bldr\Block\Frontend\Task\LessTask');
$this->addTask('bldr_frontend.sass', 'Bldr\Block\Frontend\Task\SassTask');
$this->addTask('bldr_frontend.coffee', 'Bldr\Block\Frontend\Task\CoffeeTask');
$this->addTask('bldr_frontend.concat', 'Bldr\Block\Frontend\Task\ConcatTask');
$this->addTask('bldr_frontend.minify.css', 'Bldr\Block\Frontend\Task\Minify\CssTask');
$this->addTask('bldr_frontend.minify.js', 'Bldr\Block\Frontend\Task\Minify\JsTask');
}
}
35 changes: 18 additions & 17 deletions src/Call/CoffeeCall.php → src/Task/CoffeeTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
* with this source code in the file LICENSE
*/

namespace Bldr\Block\Frontend\Call;
namespace Bldr\Block\Frontend\Task;

use Bldr\Call\AbstractCall;
use Bldr\Call\Traits\FinderAwareTrait;
use Bldr\Block\Core\Task\AbstractTask;
use Bldr\Block\Core\Task\Traits\FinderAwareTrait;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use CoffeeScript\Compiler;

/**
* @author Aaron Scherer <[email protected]>
*/
class CoffeeCall extends AbstractCall
class CoffeeTask extends AbstractTask
{
use FinderAwareTrait;

Expand All @@ -37,42 +37,43 @@ public function configure()
{
$this->setName('coffee')
->setDescription('Compiles the `src` coffee files')
->addOption('src', true, 'Coffeescript files to compile')
->addOption('dest', true, 'Destination to save to');
->addParameter('src', true, 'Coffeescript files to compile')
->addParameter('dest', true, 'Destination to save to');
}

/**
* {@inheritDoc}
*/
public function run()
public function run(OutputInterface $output)
{
$this->coffee = new Compiler();

$source = $this->getOption('src');
$source = $this->getParameter('src');
$files = $this->getFiles($source);

$this->compileFiles($files, $this->getOption('dest'));
$this->compileFiles($output, $files, $this->getParameter('dest'));
}

/**
* @param SplFileInfo[] $files
* @param string $destination
* @param OutputInterface $output
* @param SplFileInfo[] $files
* @param string $destination
*/
private function compileFiles(array $files, $destination)
private function compileFiles(OutputInterface $output, array $files, $destination)
{
$code = '';
foreach ($files as $file) {
if ($this->getOutput()->isVerbose()) {
$this->getOutput()->writeln("Compiling ".$file);
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln("Compiling ".$file);
}

$code .= $file->getContents() . "\n";
}

$output = $this->coffee->compile($code);

if ($this->getOutput()->isVerbose()) {
$this->getOutput()->writeln("Writing to ".$destination);
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln("Writing to ".$destination);
}

$fs = new Filesystem;
Expand Down
25 changes: 13 additions & 12 deletions src/Call/ConcatCall.php → src/Task/ConcatTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
* with this source code in the file LICENSE
*/

namespace Bldr\Block\Frontend\Call;
namespace Bldr\Block\Frontend\Task;

use Bldr\Call\AbstractCall;
use Bldr\Call\Traits\FinderAwareTrait;
use Bldr\Block\Core\Task\AbstractTask;
use Bldr\Block\Core\Task\Traits\FinderAwareTrait;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\SplFileInfo;

/**
* @author Aaron Scherer <[email protected]>
*/
class ConcatCall extends AbstractCall
class ConcatTask extends AbstractTask
{
use FinderAwareTrait;

Expand All @@ -30,24 +31,24 @@ public function configure()
{
$this->setName('concat')
->setDescription('Concatenates the src files into a dest')
->addOption('src', true, 'The file(s) to concatenate')
->addOption('dest', true, 'The filename and path to save the concatenated file')
->addOption('banner', false, 'Banner to place at the top of the concatenated file')
->addOption('separator', true, 'The separator to use between files', "\n");
->addParameter('src', true, 'The file(s) to concatenate')
->addParameter('dest', true, 'The filename and path to save the concatenated file')
->addParameter('banner', false, 'Banner to place at the top of the concatenated file')
->addParameter('separator', true, 'The separator to use between files', "\n");
}

/**
* {@inheritDoc}
*/
public function run()
public function run(OutputInterface $output)
{
$destination = $this->getOption('dest');
$files = $this->getFiles($this->getOption('src'));
$destination = $this->getParameter('dest');
$files = $this->getFiles($this->getParameter('src'));

$content = '';
foreach ($files as $file) {
$fileContents = $this->getFileContents($file);
$content .= $fileContents . $this->getOption('separator');
$content .= $fileContents . $this->getParameter('separator');
}

$fs = new Filesystem();
Expand Down
115 changes: 115 additions & 0 deletions src/Task/LessTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

/**
* This file is part of frontend-block
*
* (c) Aaron Scherer <[email protected]>
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE
*/

namespace Bldr\Block\Frontend\Task;

use Bldr\Block\Core\Task\AbstractTask;
use Bldr\Block\Core\Task\Traits\FinderAwareTrait;
use Less_Parser;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\SplFileInfo;

/**
* @author Aaron Scherer <[email protected]>
*/
class LessTask extends AbstractTask
{
use FinderAwareTrait;

/**
* @var Less_Parser $less
*/
private $less;

/**
* {@inheritDoc}
*/
public function configure()
{
$this->setName('less')
->setDescription('Compiles the `src` less files')
->addParameter('src', true, 'Less files to compile')
->addParameter('dest', true, 'Destination to save to')
->addParameter('compress', false, 'Should bldr remove whitespace and comments')
->addParameter('sourceMap', false, 'Should bldr create a source map')
->addParameter(
'sourceMapWriteTo',
false,
'Where should bldr write to? If this isn\'t set, it will be written to the compiled file.'
)
->addParameter('sourceMapURL', false, 'Url to use for the source map');
}

/**
* {@inheritDoc}
*/
public function run()
{

$this->less = new Less_Parser($this->getLessOptions());

$source = $this->getParameter('src');
$files = $this->getFiles($source);

$this->compileFiles($output, $files, $this->getParameter('dest'));
}

/**
* @return array
* @throws \RuntimeException
*/
private function getLessOptions()
{
$options = [];
if ($this->getParameter('compress') === true) {
$options['compres'] = true;
}

if ($this->hasParameter('sourceMap')) {
$options['sourceMap'] = $this->getParameter('sourceMap');
}

if ($this->hasParameter('sourceMapWriteTo')) {
$options['sourceMapWriteTo'] = $this->getParameter('sourceMapWriteTo');
}

if ($this->hasParameter('sourceMapURL')) {
$options['sourceMapURL'] = $this->getParameter('sourceMapURL');
}

return $options;
}

/**
* @param OutputInterface $output
* @param SplFileInfo[] $files
* @param string $destination
*/
private function compileFiles(OutputInterface $output, array $files, $destination)
{
foreach ($files as $file) {
if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln("Compiling ".$file);
}
$this->less->parseFile($file);
}

$output = $this->less->getCss();

if ($output->getVerbosity() === OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln("Writing to ".$destination);
}
$fs = new Filesystem;
$fs->mkdir(dirname($destination));
$fs->dumpFile($destination, $output);
}
}
Loading

0 comments on commit e8586f6

Please sign in to comment.