PHP code example of cornernote / yii-asset-compress

1. Go to this page and download the library: Download cornernote/yii-asset-compress library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cornernote / yii-asset-compress example snippets


return array(
    'aliases' => array(
        'vendor' => '/path/to/vendor',
    ),
);

return array(
    'commandMap' => array(
        'assetCompress' => array(
            'class' => 'vendor.cornernote.yii-asset-compress.commands.AssetCompressCommand',
            'assetsPath' => 'application.assets',
            'css' => array(
                'combine' => array(
                    'css/combined.css' => array(                                     // output to application.assets|css/desktop.css
                        // format is: asset.path.alias|path/to/asset.css
                        'vendor.twbs.bootstrap.dist|css/bootstrap.css',             // -{ (alias!=application) = this asset path will be
                        'bootstrap.assets|css/yiistrap.css',                        // -{ published, and any url() in the CSS will be 
                        'vendor.fortawesome.font-awesome|css/font-awesome.min.css', // -{ replaced with the correct relative path.
                        'application.assets|css/app.css',                           // -{
                        'application|css/app.css',                                  // - (alias=application) = Uses webroot, assets not published.
                    ),
                ),
                'minify' => true
            ),
            'js' => array(
                'combine' => array(
                    'js/combined.js' => array(                            // output to application.assets|js/desktop.js
                        // format is: asset.path.alias|path/to/asset.js
                        'system.web.js.source|jquery.min.js',            // -{ (alias!=application) = this asset path will be
                        'system.web.js.source|jquery.yiiactiveform.js',  // -{ published, and any url() in the CSS will be 
                        'vendor.twbs.bootstrap.dist|js/bootstrap.js',    // -{ replaced with the correct relative path.
                        'application.assets|js/app.js',                  // -{ 
                        'application|js/app.js',                         // - (alias=application) = Uses webroot, assets not published.
                    ),
                ),
                'minify' => true
            )
        ),
    ),
);

$baseUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.assets'));
Yii::app()->clientScript->registerCssFile($baseUrl . '/css/combined.css');
Yii::app()->clientScript->registerScriptFile($baseUrl . '/js/combined.js');


class ClientScript extends CClientScript
{
    public $ignoreCoreScript = array();
    public $ignoreScriptFile = array();
    public $ignoreCssFile = array();

    public function registerCoreScript($name, $options = array())
    {
        if (in_array($name, $this->ignoreCoreScript))
            return $this;
        return parent::registerCoreScript($name);
    }
    public function registerScriptFile($url, $position = null, array $htmlOptions = array())
    {
        foreach ($this->ignoreScriptFile as $ignore)
            if ($this->endsWith($url, $ignore))
                return $this;
        return parent::registerScriptFile($url, $position, $htmlOptions);
    }
    public function registerCssFile($url, $media = '')
    {
        foreach ($this->ignoreCssFile as $ignore)
            if ($this->endsWith($url, $ignore))
                return $this;
        return parent::registerCssFile($url, $media);
    }

    private function endsWith($haystack, $needle)
    {
        $length = strlen($needle);
        if ($length == 0)
            return true;
        return (substr($haystack, -$length) === $needle);
    }
}

return array(
    'components' => array(
        'clientScript' => array(
            'class' => 'application.components.ClientScript',
            'ignoreCssFile' => array(
                'bootstrap.css',
                'yiistrap.css',
                'font-awesome.min.css',
            ),
            'ignoreScriptFile'=>array(
                'bootstrap.js',
            ),
            'ignoreCoreScript' => array(
                'jquery',
                'yiiactiveform',
            ),
        ),
    ),
);

curl http://getcomposer.org/installer | php

php composer.phar  

php yiic assetCompress