Skip to content

Commit

Permalink
Merge pull request #19 from hostep/fix-issue-17
Browse files Browse the repository at this point in the history
Instead of overwriting the minify_exclude value, append your css file to it.
  • Loading branch information
sydekumf authored Feb 25, 2018
2 parents 0d786c9 + ad7c8e2 commit d36722d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
65 changes: 65 additions & 0 deletions Plugin/View/ExcludeCssFromMinification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*/

namespace Magenerds\PageDesigner\Plugin\View;

use Magento\Framework\View\Asset\Minification;

/**
* Class ExcludeCssFromMinification
*
* @package Magenerds\PageDesigner\Plugin\View
* @file ExcludeCssFromMinification.php
*/
class ExcludeCssFromMinification
{
/**
* Adds css file to the minify_exclude config setting to avoid a bug with minification of this css file
* Only occurs with tubalmartin/cssmin < v2.4.8-p7
*
* Ref:
* - https://github.com/magento/magento2/issues/8552
* - https://github.com/magento/magento2/pull/9027
* - https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/commit/59e5e8b0b8225244aea90da3cd5f81b1ba575da2#diff-80f11f7052c350cef68c3041a5479789R588
*
* @param Minification $subject
* @param callable $proceed
* @param string $contentType
* @return string[]
*/
public function aroundGetExcludes(Minification $subject, callable $proceed, $contentType)
{
$result = $proceed($contentType);

if ($contentType !== 'css' || !$this->isCssminLibraryOlderThanVersion3()) {
return $result;
}

$result[] = '/Magenerds_PageDesigner/css/pd-ui.css';

return $result;
}

/**
* Checks if the current version of tubalmartin/cssmin can cause problems with minifying
* Strictly speaking, not all versions 2.x.x of the library caused issues (since it got fixed in v2.4.8-p7),
* but here we check to see if version 2 is being used, where the class was called 'CSSmin' and existed in the global namespace,
* from version 3 on out, the class name was changed and put in a namespace: 'tubalmartin\CssMin\Minifier'
* So if we detect version 2 of the library, we assume it is broken
*
* Ref:
* - https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/compare/v2.4.8-p10...v3.0.0#diff-411bfa1ca68f3e86ffb0276bcffd838dL22
*
* @return bool
*/
private function isCssminLibraryOlderThanVersion3()
{
return class_exists(\CSSmin::class);
}
}
8 changes: 0 additions & 8 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<dev>
<!-- temporary solution until https://github.com/magento/magento2/issues/8552 is fixed-->
<css>
<minify_exclude>
/Magenerds_PageDesigner/css/pd-ui.css
</minify_exclude>
</css>
</dev>
<pagedesigner>
<general>
<css_classes_column>pd-highlight</css_classes_column>
Expand Down
6 changes: 6 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@
<plugin name="Magenerds_PageDesigner::widgetDecodeBackend"
type="Magenerds\PageDesigner\Plugin\Block\WidgetOptionsPlugin"/>
</type>

<!-- needed for tubalmartin/cssmin < v2.4.8-p7 -->
<type name="Magento\Framework\View\Asset\Minification">
<plugin name="Magenerds_PageDesigner::excludeCssFromMinification"
type="Magenerds\PageDesigner\Plugin\View\ExcludeCssFromMinification"/>
</type>
</config>

0 comments on commit d36722d

Please sign in to comment.