New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset helper for various resourses. #106

Closed
wants to merge 1 commit into
base: develop
from

Conversation

Projects
None yet
3 participants
@turrsis
Contributor

turrsis commented Feb 9, 2017

The Assets helper allow to add various resourses to html page, such as .css, .js, etc.
It can be configure in config files.
For page performance optimisation assets can be placed in top or bottom of page (or elsewhere).

Allow to build several link by one alias:

// CONFIG FILE:
'assets_manager' => [
  ...
  'several_assets' => [
    'assets' => [
      'foo.css',
      'bar.css',
      'jquery.js' => 'https://code.jquery.com/jquery-3.0.0.min.js',
    ],
  ],
  ...

// LAYOUT:
echo $this->assets()->add('several_assets');

// OUTPUT:
<link href="/foo.css" type="text/css">
<link href="/bar.css" type="text/css">
<script type="application/javascript" src="https://code.jquery.com/jquery-3.0.0.min.js"></script>

Also can possible change layout decoration 'on fly' :

// CONFIG FILE:
'assets_manager' => [
  'assets' => [
    'default' => [
      'layout.css' => 'foo.css',
    ],
    'my-theme' => [
      'layout.css' => 'bar.css',
    ],
  ...

// LAYOUT:
$this->assets()->add('layout.css');
if ('good weather') {
  $this->assets()->getAssetsManager()->setCurrentGroup('my-theme');
} else {
  $this->assets()->getAssetsManager()->setCurrentGroup('default');
}
// GOOD WEATHER OUTPUT:
<link href="/bar.css" type="text/css">
// NOT GOOD WEATHER OUTPUT:
<link href="/foo.css" type="text/css">

@turrsis turrsis referenced this pull request Feb 9, 2017

Open

[WIP] AssetsListener #216

@turrsis turrsis force-pushed the turrsis:addAssetsManager branch 4 times, most recently from 8b457a7 to dfbf091 Feb 9, 2017

@turrsis turrsis changed the title from Asset helper for various resourses. to [WIP] Asset helper for various resourses. Feb 9, 2017

@turrsis turrsis force-pushed the turrsis:addAssetsManager branch from dfbf091 to a7f3b5b Feb 9, 2017

@froschdesign

This comment has been minimized.

Member

froschdesign commented Feb 9, 2017

In times of "CSS pre-processor", "PostCSS" and Co. is this really needed?

With your view helper and MVC extension you introduce a new heavyweight:

  • own cache solution
  • new resolver, manager etc.
  • hard dependency to the zend-mvccomponent

Please have a look at this light-weight solution: #64

@turrsis turrsis force-pushed the turrsis:addAssetsManager branch 2 times, most recently from f381918 to b3dc8fc Feb 9, 2017

@weierophinney

This comment has been minimized.

Member

weierophinney commented Feb 9, 2017

This looks great. However, I agree with @froschdesign that this may be a bit much to add directly to zend-view, due to the number of classes required; it's quite a bit of maintenance.

Might I suggest adding this as a separate repository/package instead? It could expose a ConfigProvider and/or Module class to ensure that the helper is wired when installed, and then have it's own development cycles separate from zend-view.

Thoughts?

@turrsis

This comment has been minimized.

Contributor

turrsis commented Feb 9, 2017

This helper not require MVC extention, only Router. But Url helper use router too.
I'm not entirely convinced of the necessity of the zendframework/zend-mvc#216.
However, this PR can help to develop own cache, filter and other functionality.
There is a great analogue : https://github.com/RWOverdijk/AssetManager, but, to my mind, it too heavy for simple tasks. The idea here is approximately the same.
In my view, this PR will make the zend-view more flexible.

@turrsis

This comment has been minimized.

Contributor

turrsis commented Feb 9, 2017

I would suggest to look to replace (perhaps) the HeadLink, HeadStyle and HeadScript this helper.

@turrsis turrsis force-pushed the turrsis:addAssetsManager branch from b3dc8fc to 6ac403b Feb 9, 2017

@turrsis turrsis force-pushed the turrsis:addAssetsManager branch from 6ac403b to ab5ca75 Feb 9, 2017

@turrsis turrsis changed the title from [WIP] Asset helper for various resourses. to Asset helper for various resourses. Feb 9, 2017

@froschdesign

This comment has been minimized.

Member

froschdesign commented Feb 9, 2017

This helper not require MVC extention, only Router.

Your PR on the zend-mvc says something different. 😉

There is a great analogue : https://github.com/RWOverdijk/AssetManager

Ah, there is the separate package.


I'm not against the idea, but I would prefer a solution which can be used in a zend-mvc and a zend-expressive application. (Or in a application which only uses zend-view.)

Btw. this reminds me of the Drupal\Core\Asset

@turrsis

This comment has been minimized.

Contributor

turrsis commented Feb 9, 2017

zend-mvc-PR require zend-view-PR, but zend-view-PR not require zend-mvc-PR. If this wrong - this is my mistake and I will fix it. This PR was planned as standalone of zend-mvc.

Unfortunately, but I don't know anything about zend-expressive.

@turrsis

This comment has been minimized.

Contributor

turrsis commented Feb 10, 2017

Both PR were moved to the module https://github.com/turrsis/zend-view-assets.
Can you review it?

@turrsis

This comment has been minimized.

Contributor

turrsis commented Mar 28, 2017

@froschdesign, @weierophinney https://github.com/turrsis/zend-view-assets is refactored.
Mvc folder should be moved to zend-mvc and can be used for mvc applications.
Other classes depends on zend-view, zend-cache, zend-filter and can be used for application which only uses zend-view.
Using in zend-expressive require additional PR for zend-expressive module.
If this is acceptable to you - I will move Mvc folder to zendframework/zend-mvc#216.

@froschdesign

This comment has been minimized.

Member

froschdesign commented Mar 28, 2017

@turrsis
Have you seen the new Asset helper?

And do not forget the @weierophinney comment:

Might I suggest adding this as a separate repository/package instead? It could expose a ConfigProvider and/or Module class to ensure that the helper is wired when installed, and then have it's own development cycles separate from zend-view.

The separate repository is a very good suggestion. No need to add some classes under different repositories / packages.

@turrsis

This comment has been minimized.

Contributor

turrsis commented Mar 28, 2017

@froschdesign, @weierophinney
Yes, I see https://docs.zendframework.com/zend-view/helpers/asset, but it only map resources and not allow use resources from modules.
turrsis/zend-view-assets allow to use resources from modules, group and filter it.
"The separate repository is a very good suggestion" - I done it as separate repository, but mvc part should be move from this. Where better to move it?
Can this module be included in the zendframework?

@froschdesign

This comment has been minimized.

Member

froschdesign commented Mar 28, 2017

@turrsis

but it only map resources and not allow use resources from modules.

Right, but I see a problem here: two view helpers with the equal / similar name.

turrsis/zend-view-assets allow to use resources from modules, group and filter it.

The modules depending on zend-mvc. I can not use this with modules in zend-expressive. Right?

@turrsis

This comment has been minimized.

Contributor

turrsis commented Mar 28, 2017

@froschdesign
Can be renamed to Resources.
Mvc dependency was moved to https://github.com/turrsis/zend-view-assets-mvc.
Now turrsis/zend-view-assets is not depending on zend-mvc and (to my mind) can be used with 'zend-expressive'.

@weierophinney

This comment has been minimized.

Member

weierophinney commented Dec 6, 2018

Closing, as the third party module has been created as requested.

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