Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions src/AssetsMinify.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@

class AssetsMinify extends AssetsMinify\Pattern\Singleton {

/**
* @var \AssetsMinify\Init
*/
private $initObject = null;

/**
* Constructor
*/
protected function __construct() {
if ( !is_admin() )
return new AssetsMinify\Init;
if ( !is_admin() ) {
$this->initObject = new AssetsMinify\Init;
return;
}

add_action( 'plugins_loaded', array( $this, 'loadAdmin' ) );
}
Expand All @@ -25,4 +32,11 @@ protected function __construct() {
public function loadAdmin() {
new AssetsMinify\Admin;
}

/**
* Provides access to the central Init object.
*/
public function getInitObject() {
return $this->initObject;
}
}
6 changes: 4 additions & 2 deletions src/AssetsMinify/Assets/Css.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public function extract() {

/**
* Takes all the stylesheets and manages their queue to compress them
*
* @param array $param Keyed array with settings for various Assetic classes.
*/
public function generate() {
public function generate($params = null) {
$profiler = array( time() );

foreach ( $this->assets as $media => $assets ) {
Expand All @@ -92,7 +94,7 @@ public function generate() {

if ( !$this->cache->fs->has( $cachefile ) ) {
$class = "AssetsMinify\\Assets\\Css\\" . ucfirst($ext);
new $class( $content['files'], $cachefile, $this );
new $class( $content['files'], $cachefile, $this, $params );
}

$key = "$media-$ext-am-generated";
Expand Down
3 changes: 2 additions & 1 deletion src/AssetsMinify/Assets/Css/Css.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class Css {
* @param array $content The files to save to cache
* @param string $cachefile The cache file name
* @param object $manager The Factory object
* @param array $param Keyed array with settings for various Assetic classes.
*/
public function __construct($content, $cachefile, $manager) {
public function __construct($content, $cachefile, $manager, $params = null) {
$manager->cache->fs->set( $cachefile, $manager->createAsset( $content, array( 'CssRewrite' ) )->dump() );
}
}
3 changes: 2 additions & 1 deletion src/AssetsMinify/Assets/Css/Less.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class Less extends \AssetsMinify\Assets\Factory {
* @param array $content The files to save to cache
* @param string $cachefile The cache file name
* @param object $manager The Factory object
* @param array $param Keyed array with settings for various Assetic classes.
*/
public function __construct($content, $cachefile, $manager) {
public function __construct($content, $cachefile, $manager, $params = null) {
parent::__construct( $this );
$manager->cache->fs->set( $cachefile, $this->createAsset( $content, $this->getFilters() )->dump() );
}
Expand Down
3 changes: 2 additions & 1 deletion src/AssetsMinify/Assets/Css/Sass.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class Sass extends \AssetsMinify\Assets\Factory {
* @param array $content The files to save to cache
* @param string $cachefile The cache file name
* @param object $manager The Factory object
* @param array $param Keyed array with settings for various Assetic classes.
*/
public function __construct($content, $cachefile, $manager) {
public function __construct($content, $cachefile, $manager, $params = null) {
parent::__construct( $this );
$manager->cache->fs->set( $cachefile, $this->createAsset( $content, $this->getFilters() )->dump() );
}
Expand Down
24 changes: 22 additions & 2 deletions src/AssetsMinify/Assets/Css/Scss.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
* @author Alessandro Carbone <ale.carbo@gmail.com>
*/
class Scss extends \AssetsMinify\Assets\Factory {
/**
* @var array
*/
private $params = null;

/**
* Constructor
*
* @param array $content The files to save to cache
* @param string $cachefile The cache file name
* @param object $manager The Factory object
*/
public function __construct($content, $cachefile, $manager) {
public function __construct($content, $cachefile, $manager, $params = null) {
$this->manager = $manager;
$this->params = $params;
parent::__construct( $this );
$manager->cache->fs->set( $cachefile, $this->createAsset( $content, $this->getFilters() )->dump() );
}
Expand All @@ -34,7 +40,21 @@ public function setFilters() {
$this->setFilter('Compass', $compassInstance);
$filter = 'Compass';
} else {
$this->setFilter('Scssphp', new ScssphpFilter);
$scssphpFilter = new ScssphpFilter();

if ( is_array($this->params) ) {
if ( ! empty($this->params['addImportPath']) ) {
if ( is_array($this->params['addImportPath'] ) ) {
foreach ( $this->params['addImportPath'] as $value ) {
$scssphpFilter->addImportPath($value);
}
} else {
$scssphpFilter->addImportPath($this->params['addImportPath']);
}
}
}

$this->setFilter('Scssphp', $scssphpFilter);
$filter = 'Scssphp';
}

Expand Down
5 changes: 3 additions & 2 deletions src/AssetsMinify/Assets/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public function extract() {
* Takes all the JavaScript and manages the queue to compress them
*
* @param string $where The page's place to dump the scripts in (header or footer)
* @param array $param Keyed array with settings for various Assetic classes.
*/
public function generate($where) {
public function generate($where, $params = null) {
$profiler = array( time() );

if ( !isset($this->assets[$where]) )
Expand All @@ -98,7 +99,7 @@ public function generate($where) {

if ( !$this->cache->fs->has( $cachefile ) ) {
$class = "AssetsMinify\\Assets\\Js\\" . ucfirst($ext);
new $class( $content['files'], $cachefile, $this );
new $class( $content['files'], $cachefile, $this, $params );
}

$key = "$ext-am-generated";
Expand Down
3 changes: 2 additions & 1 deletion src/AssetsMinify/Assets/Js/Coffee.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class Coffee extends \AssetsMinify\Assets\Factory {
* @param array $content The files to save to cache
* @param string $cachefile The cache file name
* @param object $manager The Factory object
* @param array $param Keyed array with settings for various Assetic classes.
*/
public function __construct($content, $cachefile, $manager) {
public function __construct($content, $cachefile, $manager, $params = null) {
parent::__construct( $this );
$manager->cache->fs->set( $cachefile, $this->createAsset( $content, $this->getFilters() )->dump() );
}
Expand Down
3 changes: 2 additions & 1 deletion src/AssetsMinify/Assets/Js/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class Js {
* @param array $content The files to save to cache
* @param string $cachefile The cache file name
* @param object $manager The Factory object
* @param array $param Keyed array with settings for various Assetic classes.
*/
public function __construct($content, $cachefile, $manager) {
public function __construct($content, $cachefile, $manager, $params = null) {
$manager->cache->fs->set( $cachefile, $manager->createAsset( $content, $manager->getFilters() )->dump() );
}
}
18 changes: 15 additions & 3 deletions src/AssetsMinify/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Init {

protected $exclusions;

/**
* @var array
*/
private $params = null;

/**
* Constructor
*/
Expand Down Expand Up @@ -47,6 +52,13 @@ public function __construct() {
add_action( 'wp_footer', array( $this, 'footer' ) );
}

/**
* @param array $param Keyed array with settings for various Assetic classes.
*/
public function setParams($params) {
$this->params = $params;
}

/**
* Checks if a file is within the list of resources to exclude
*
Expand All @@ -65,15 +77,15 @@ public function isFileExcluded( $path ) {
* Returns header's inclusion for CSS and JS
*/
public function header() {
$this->css->generate();
$this->js->generate('header');
$this->css->generate($this->params);
$this->js->generate('header', $this->params);
}

/**
* Returns footer's inclusion for JS
*/
public function footer() {
$this->js->generate('footer');
$this->js->generate('footer', $this->params);
if ( $this->cache->isUpdated() )
Log::getInstance()->dumpStorage();
}
Expand Down