You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-16Lines changed: 54 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,11 @@ An ultra-simple-to-use assets management PHP library.
11
11
-[Usage](#usage).
12
12
-[Views](#views).
13
13
-[Controllers](#controllers).
14
-
-[API](#api).
15
14
-[Configuration](#configuration).
16
15
-[Collections](#collections).
17
16
-[Pipeline](#pipeline).
18
17
-[More options](#options).
18
+
-[Multitenancy](#multitenancy).
19
19
-[Non static interface usage](#nonstatic).
20
20
-[Sample collections](#samples).
21
21
-[Troubleshooting / F.A.Q.](#troubleshooting).
@@ -28,21 +28,21 @@ An ultra-simple-to-use assets management PHP library.
28
28
29
29
-**Very easy to use**.
30
30
- Autogenerates HTML tags for including your JavaScript and CSS files.
31
+
- Automatically detects type of asset (CSS, JavaScript or collection).
31
32
- Supports programmatically adding assets on the fly.
32
33
- Supports local (**including packages**) or remote assets.
33
34
- Prevents from loading duplicated assets.
34
35
- Included assets **pipeline** (*concatenate and minify all your assets to a single file*) with URL **timestamps** and **gzip** support.
35
36
- Automatically prefixes local assets with a configurable folder name or url.
36
37
- Supports secure (*https*) and protocol agnostic (*//*) links.
37
-
- Supports **collections** (*named groups of assets*) that can be nested, allowing assets dependencies definitions.
38
-
-Automatically detects type of asset (CSS, JavaScript or collection).
38
+
- Supports **collections** (*named sets of assets*) that can be nested, allowing assets dependencies definitions.
39
+
-Supports **multitenancy** (multiple independent configurations) for different groups of assets (*this feature is only available for Laravel >= 5.0*).
39
40
- Allows autoloading by default preconfigured assets and collections.
40
41
41
-
42
42
<aid="frameworks"></a>
43
43
## Supported frameworks
44
44
45
-
The library is framework agnostic and it should work well with any framework or naked PHP application. Nevertheless, the following instructions have been tailored for **Laravel 5** framework ([still on Laravel 4?](https://github.com/Stolz/Assets/issues/55#issuecomment-73024822)). If you want to use the library in any other scenario please read the [non static interface](#nonstatic) instructions.
45
+
The library is framework agnostic and it should work well with any framework or naked PHP application. Nevertheless, sice the library is most popular between Laravel users the following instructions have been tailored for **Laravel 5** framework ([still on Laravel 4?](https://github.com/Stolz/Assets/issues/55#issuecomment-73024822)). If you want to use the library in any other scenario please read the [non static interface](#nonstatic) instructions.
46
46
47
47
<aid="installation"></a>
48
48
## Installation
@@ -79,7 +79,8 @@ Basically all you have to do to add and asset, no matter if it's CSS or JS or a
79
79
80
80
Assets::add('filename');
81
81
82
-
*For more advanced uses keep reading ...*
82
+
>For more advanced uses keep reading but please note that there are some more methods not documented here. For a **full list of all the available methods** please read the provided [`API.md`](https://github.com/Stolz/Assets/blob/master/API.md) file.
83
+
83
84
84
85
Add more than one asset at once
85
86
@@ -98,8 +99,8 @@ You may add remote assets in the same fashion
98
99
99
100
If your assets have no extension and autodetection fails, then just use canonical functions *(they accept an array of assets too)*
100
101
101
-
Assets::addCss('asset.css');
102
-
Assets::addJs('asset.js');
102
+
Assets::addCss('CSSfile.foo');
103
+
Assets::addJs('JavaScriptFile.bar');
103
104
104
105
If at some point you decide you added the wrong assets you can reset them and start over
105
106
@@ -111,11 +112,6 @@ All methods that don't generate output will accept chaining:
There are some methods not documented here. For a **full list of all the available methods** please read the provided [`API.md`](https://github.com/Stolz/Assets/blob/master/API.md) file.
118
-
119
115
<aid="configuration"></a>
120
116
## Configuration
121
117
@@ -130,15 +126,15 @@ If you are using the [non static interface](#nonstatic) just pass an associative
130
126
<aid="collections"></a>
131
127
### Collections
132
128
133
-
A collection is a named group of assets, that is, a set of JavaScript and CSS files. Any collection may include more collections, allowing dependencies definition and collection nesting. Collections can be created on run time or via config file.
129
+
A collection is a named set of assets, that is, a set of JavaScript and CSS files. Any collection may include more collections, allowing dependencies definition and collection nesting. Collections can be created on run time or via config file.
134
130
135
131
To register a collection on run time for later use:
**Note:***This feature is only available for Laravel >= 5.0*.
243
+
244
+
Multitenancy is achieved using groups. A group is an isolated container of the library. Each group is totally independent of other groups so it uses its own settings and assets flow. This is useful if you need different approaches for different types of assets (for instance, you may need some assets to be pipelined but some others no). Therefore, when using multiple groups is your responsability to make sure the assets of different groups that depend on eachother are loaded in ther right order.
245
+
246
+
By default if no groups are defined the default group is used. To define a group just nest your normal settings within an array in the config file. The array key will be the group name. For instance:
247
+
248
+
249
+
// ... File: config/assets.php ...
250
+
251
+
// Default group
252
+
'default' => [
253
+
'pipeline' => true,
254
+
'js_dir' => 'js',
255
+
// ... more options for default group
256
+
],
257
+
258
+
// Other group
259
+
'group1' => [
260
+
'pipeline' => false,
261
+
'public_dir' => '/foo',
262
+
// ... more options for group1
263
+
],
264
+
265
+
// Another group
266
+
'group2' => [
267
+
'pipeline' => false,
268
+
'css_dir' => 'css/admin',
269
+
// ... more options for group2
270
+
],
271
+
272
+
For choosing which group you want to interact with, use the `group()` method. If no group is specified the 'default' group will be used.
273
+
274
+
Assets::add('foo.js')->js(); // Uses default group
275
+
Assets::group('group1')->add('bar.css')->css(); // Uses the 'group1' group.
276
+
277
+
Please note the `group()` method is part of the Facade, so it does not accept chaining and it always has to be used at the beginning of each interaction with the library.
278
+
243
279
----
244
280
245
281
<aid="nonstatic"></a>
@@ -357,7 +393,7 @@ If you use a massive amount of assets make sure your connection is fast enough a
357
393
<aid="faq_config_on_the_fly"></a>
358
394
### Can I use multiple instances of the library?
359
395
360
-
Yes you can but there is no need. Read next question. If you still want to use multiple instances, [read how](https://github.com/Stolz/Assets/issues/37#issuecomment-57676554).
396
+
Yes you can but there is no need. You better use the [multitenancy feature](#multitenancy) (*only available for Laravel >= 5.0*).
361
397
362
398
<aid="faq_instances"></a>
363
399
### Can I change settings on the fly?
@@ -367,6 +403,8 @@ Yes you can. There is a `config()` public method to change settings on the fly.
0 commit comments