Skip to content

RC5 - improved formatter #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions src/Processor/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@

class Processor
{
const TYPE_SCSS = 'scss';
const TYPE_COMPASS = 'scss';
const TYPE_SASS = 'sass';
const TYPE_LESS = 'less';
const FORMATTER_COMPRESSED = 'compressed';
const FORMATTER_CRUNCHED = 'crunched';
const FORMATTER_EXPANDED = 'expanded';
const FORMATTER_NESTED = 'nested';
const FORMATTER_COMPACT = 'compact';
const SUPPORTED_FORMATTERS = [
self::FORMATTER_COMPRESSED,
self::FORMATTER_CRUNCHED,
self::FORMATTER_EXPANDED,
self::FORMATTER_NESTED,
self::FORMATTER_COMPACT
];
/**
* @var IOInterface
*/
Expand Down Expand Up @@ -119,30 +127,18 @@ public function saveOutput()
*/
public function processFiles($formatter)
{
switch ($formatter) {
case 'compressed':
case 'crunched':
case 'expanded':
case 'nested':
case 'compact':
$formatter = 'Leafo\\ScssPhp\\Formatter\\' . ucfirst($formatter);
break;
default:
throw new \InvalidArgumentException('available options are: xxx');
}

foreach ($this->files as $file) {
$this->io->write("<info>processing</info>: {$file->getSourcePath()}");
$file->setSourceContentFromSourcePath();

switch ($file->getType()) {
case static::TYPE_COMPASS:
case static::TYPE_SCSS:
case static::TYPE_SASS:
$this->sass->setFormatter($formatter);
case File::TYPE_COMPASS:
case File::TYPE_SCSS:
case File::TYPE_SASS:
$this->sass->setFormatter($this->getFormatterClass($formatter));
$content = $this->sass->compile($file->getSourceContent());
break;
case static::TYPE_LESS:
case File::TYPE_LESS:
$content = $this->less->compile($file->getSourceContent());
break;
default:
Expand All @@ -152,4 +148,18 @@ public function processFiles($formatter)
$file->setParsedContent($content);
}
}

/**
* @param string $formatter
*
* @return string
*/
protected function getFormatterClass($formatter)
{
if (!in_array($formatter, static::SUPPORTED_FORMATTERS)) {
throw new \InvalidArgumentException('unknown formatter, available options are: ' . print_r(static::SUPPORTED_FORMATTERS, true));
}

return 'Leafo\\ScssPhp\\Formatter\\' . ucfirst($formatter);
}
}