Skip to content

added asset file mapping parameter to define files which are remapped af...#5

Open
schmunk42 wants to merge 3 commits intomikehaertl:masterfrom
schmunk42:update-assets-script-map
Open

added asset file mapping parameter to define files which are remapped af...#5
schmunk42 wants to merge 3 commits intomikehaertl:masterfrom
schmunk42:update-assets-script-map

Conversation

@schmunk42
Copy link
Contributor

...ter package compression.

Description and param name can still be improved ;)

@mikehaertl
Copy link
Owner

Can you give an example use case here to better understand what problem this helps to solve?

@schmunk42
Copy link
Contributor Author

Here's the config of my current project:

'clientScript'  => array(
            'class'              => 'vendor.mikehaertl.packagecompressor.PackageCompressor',
            'coreScriptPosition' => 0, //
            'enableCompression'  => 1,
            'combineOnly'        => 1,
            'copyCssImages'      => true,
            'assetsScriptMap'    => array(
                'jquery-ui.min.js'          => false,
                'jquery.fancybox-1.3.4.js'  => false,
                'iscroll.js'                => false,
                'main.js'                   => false,
                'jquery.zoom-min.js'        => false,
                'jquery.fancybox-1.3.4.css' => false,
                'jquery-ui-bootstrap.css'   => false,
                'p3.css'                    => false,
                'flags.css'                 => false,
            ),
            'packages'           => array(
                'iscroll'            => array(
                    'basePath' => 'application.components.iscroll-widget.assets',
                    'depends'  => array(
                        'jquery',
                    ),
                    'js'       => array(
                        'iscroll.js',
                    )
                ),
                'fancybox'           => array(
                    'basePath' => 'vendor.yiiext.fancybox-widget.assets',
                    'depends'  => array(
                        'jquery',
                    ),
                    'js'       => array(
                        'jquery.fancybox-1.3.4.js',
                    ),
                    'css'      => array(
                        'jquery.fancybox-1.3.4.css',
                    )
                ),
                'language-selection' => array(
                    'basePath' => 'application.components.language-selection-widget.assets',
                    'css'      => array(
                        'flags.css',
                    )
                ),
                'frontend'           => array(
                    'depends' => array(
                        'jquery',
                        'jquery.ui',
                        'bbq',
                        'bootstrap.js',
                        'bootbox',
                        'notify',
                        'jquery-css',
                        'bootstrap-yii',
                        'iscroll',
                        'fancybox',
                        'language-selection'
                    ),
                    'baseUrl' => 'themes/frontend/compressor/',
                    'js'      => array(
                        #'../../../../app/components/google-maps-widget/assets/google.js',
                        #'../../../../app/components/iscroll-widget/assets/iscroll.js',

                        '../js/main.js',
                        '../js/zoom-master/jquery.zoom-min.js',
                    ),
                    'css'     => array(
                        '../css/p3.css',
                    )
                ),
            )
        ),

As you can see I, i.e. override jquery.fancybox-1.3.4.js/css in a package.
If I'd put these files into the standard scriptMap attribute they won't also be bundled into the package.
If I put the files in assetSriptMap I can bundle them, but still remap them for final output.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so what this basically does: Prevent asset publishing from components, that don't use the package system. I don't quite like the name of that property. Should better be blockedScripts. And while i can see, why you chose the same format as for scriptMap (it makes the implementation below very easy), it's not very clean. E.g. what happens if you configure this to true or some URL?

This should rather be a list of script names:

public $blockedScripts = array(
    'jquery-ui.min.js',
    'jquery.fancybox-1.3.4.js',
);

Implementation will not change much, except that you can't use CMap::mergeArray() anymore.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment block messed up now? :)

@schmunk42
Copy link
Contributor Author

Should be fixed, let me know if there are problems with the other branch.

@schmunk42
Copy link
Contributor Author

Would be an 1.1.0 btw.
</erbsenzählermodus>

@schmunk42
Copy link
Contributor Author

Before I start coding ... just some thoughts:

To finalize this feature we should add another public $blockedPackages = array(); property.

This would not register packages, when the compressor is off.
Because if you define scripts in a package to override publication as a single file - like we do with the blockedScripts property when the compressor is on -, then these files get included twice.
One time from asset publication and the other time from package registration.

But with the changes from my other PR
We can at least "fix" this just by config settings.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we should update this docs once again, to be 100% precise. What about this (and please correct me if I'm wrong):

When compression is enabled, scripts defined in this array will be ignored if registered 
through `CClientScript::registerScriptFile()`. This way you can package assets from
widgets that don't use the package system. For the time being this is for example the
case for CListView. So you could use:

    'blockedScripts' => array(
        'jquery.yiilistview.js',
    ),
    'packages' => array(
        'listview' => array(
            'basePath' => 'zii.widgets.assets.listview',
            'js' => array('jquery.yiilistview.js'),
        ),
        'mypackage' => array(
           'js' => array( ... ),
           'depends' => array(
               'listview',
           ),
        ),
    ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants