Stolz / Assets

An ultra-simple-to-use assets management library for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Position in collection

oldy777 opened this issue · comments

commented

How can I add script in the beginning of list, in bottom of list, after certain script?

commented

@OLDPUNK, the assets list is a FIFO queue and I'm afraid there is no way to change this behavior. For adding a script at the end of the queue there is nothing you need to do, it's the default behavior.

For adding a script at the beginning, provided it needs to be added always, you can add it into the autoload configuration option, since autoloaded scripts always go to the beginning of the queue.

commented

@Stolz maybe it be useful to make prepend method, like in collections ?

$collection = collect([1, 2, 3, 4, 5]);

$collection->prepend(0);

$collection->all();

// [0, 1, 2, 3, 4, 5]
commented

I just added the feature to the develop branch. Please try.

composer require stolz/assets:dev-develop

There are 3 new methods: prepend(), prependCss() and prependJs(). Signature and behavior is the same than add(), addCss() and addJs() but with the difference the assets will be added at the beginning of the queue. Prepending multiple assets is also supported.

In my case this kills the purposes of collections and auto loaded assets, because all the assets I add they always depend on a framework, but it may be helpful for some other people.

commented

yes, it's work good for me! Thank you!
And some thoughts to improve your cool library, maybe it will be useful:
When i add directory, it added recursively. And some times I want to exclude some folders.

$without = ['secret_folder', 'test_folder'];
\Assets::addDirJs('/js/customs/', $without );

Or exclude some files

$withoutFiles = ['secret.js', 'test.js'];
\Assets::addDirJs('/js/customs/', $withoutFiles );
commented

@OLDPUNK that feature already exist and it already involves the second parameter of addDir() functions. Instead of passing an array, pass a regex that matches the files you want and discards the one you don't want. Search for regex negative lookahead to know how.

The regex will be used by a RegexIterator to add only the files matching the pattern.

You can find the default regexs at the api docs. Use them as a base and add there your negative lookahead.