Skip to content

Commit

Permalink
Support for scss files
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Jul 15, 2014
1 parent 9f66578 commit 54bc9bd
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"symfony/http-kernel": "2.*",
"symfony/console": "2.*",
"tedivm/jshrink": "~1.0",
"leafo/lessphp": "0.4.*"
"leafo/lessphp": "0.4.*",
"leafo/scssphp": "0.*"
},
"require-dev": {
"phpunit/phpunit": "*"
Expand Down
19 changes: 19 additions & 0 deletions src/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,23 @@ public function requireLess($filename, $options = null)
);
}
}

/**
* Add a scss file to the css store
*
* @param $filename
* @param $options
*/
public function requireScss($filename, $options = null)
{
$filenames = ValueAs::arr($filename);
foreach($filenames as $filename)
{
static::_addToStore(
'css',
$this->getResourceUri($filename . '.scss'),
$options
);
}
}
}
1 change: 1 addition & 0 deletions src/AssetResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AssetResponse
'js' => 'Javascript',
'json' => 'Json',
'css' => 'Css',
'scss' => 'Scss',
'less' => 'Less',
'swf' => 'Flash',
'pdf' => 'Pdf',
Expand Down
20 changes: 20 additions & 0 deletions src/Assets/ScssAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Packaged\Dispatch\Assets;

class ScssAsset extends AbstractDispatchableAsset
{
public function getExtension()
{
return 'scss';
}

public function getContentType()
{
return "text/css";
}

public function getContent()
{
return (new \scssc)->compile(parent::getContent());
}
}
4 changes: 3 additions & 1 deletion tests/AssetManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public function testStore()
$manager = \Packaged\Dispatch\AssetManager::assetType();
$manager->requireCss('test', ['delay' => true]);
$manager->requireLess('test');
$manager->requireScss('test');
$manager->requireJs('test');

$this->assertEquals(
[
'//www.packaged.in/res/p/8cac7/b/76d6c18/test.css' => ['delay' => true],
'//www.packaged.in/res/p/8cac7/b/2900bb5/test.less' => null
'//www.packaged.in/res/p/8cac7/b/2900bb5/test.less' => null,
'//www.packaged.in/res/p/8cac7/b/d22435c/test.scss' => null,
],
\Packaged\Dispatch\AssetManager::getUrisByType('css')
);
Expand Down
1 change: 1 addition & 0 deletions tests/Assets/GenericAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public function testAsset($ext, \Packaged\Dispatch\Assets\IAsset $class)
"ico" => "image/x-icon",
"css" => "text/css",
"less" => "text/css",
"scss" => "text/css",
"js" => "text/javascript",
"json" => "application/json",
"png" => "image/png",
Expand Down
2 changes: 1 addition & 1 deletion tests/Assets/LessAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class LessAssetTest extends PHPUnit_Framework_TestCase
{
public function testMinify()
public function testCompile()
{
$original = '@base: 24px;
@border-color: #B2B;
Expand Down
44 changes: 44 additions & 0 deletions tests/Assets/ScssAssetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

class ScssAssetTest extends PHPUnit_Framework_TestCase
{
public function testCompile()
{
$original = '.navigation {
ul {
line-height: 20px;
color: blue;
a {
color: red;
}
}
}
.footer {
.copyright {
color: silver;
}
}';

$expect = '.navigation ul {
line-height: 20px;
color: blue; }
.navigation ul a {
color: red; }
.footer .copyright {
color: silver; }
';
$asset = new \Packaged\Dispatch\Assets\ScssAsset();

$asset->setContent($original);
$this->assertEquals($expect, $asset->getContent());
}

public function testAsset()
{
$asset = new \Packaged\Dispatch\Assets\ScssAsset();
$this->assertEquals('scss', $asset->getExtension());
$this->assertEquals('text/css', $asset->getContentType());
}
}
15 changes: 15 additions & 0 deletions tests/asset/test.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.navigation {
ul {
line-height: 20px;
color: blue;
a {
color: red;
}
}
}

.footer {
.copyright {
color: silver;
}
}

0 comments on commit 54bc9bd

Please sign in to comment.