@@ -103,18 +103,18 @@ use Tatter\Assets\Bundle;
103103
104104class FrontendBundle extends Bundle
105105{
106- protected $bundles = [
107- StylesBundle::class,
108- ];
109-
110- protected $paths = [
111- 'bootstrap/dist/css/bootstrap.min.css',
112- 'bootstrap/dist/js/bootstrap.bundle.min.js',
113- ];
114-
115- protected $uris = [
116- 'https://pagecdn.io/lib/cleave/1.6.0/cleave.min.js',
117- ];
106+ protected $bundles = [
107+ StylesBundle::class,
108+ ];
109+
110+ protected $paths = [
111+ 'bootstrap/dist/css/bootstrap.min.css',
112+ 'bootstrap/dist/js/bootstrap.bundle.min.js',
113+ ];
114+
115+ protected $uris = [
116+ 'https://pagecdn.io/lib/cleave/1.6.0/cleave.min.js',
117+ ];
118118}
119119```
120120
@@ -132,17 +132,17 @@ use Tatter\Assets\Bundle;
132132
133133class ColorBundle extends Bundle
134134{
135- protected function define()
136- {
137- $this
138- ->add(Asset::createFromPath('styles.css')) // Add individual Assets
139- ->merge($someOtherBundle); // Or combine multiple Bundles
140-
141- // Create more complex Assets
142- $source = '<script src =" https://pagecdn.io/lib/cleave/1.6.0/cleave.min.js" type =" text/javascript" ></script >';
143- $inHead = true; // Force a JavaScript Asset to the <head > tag
144- $asset = new Asset($source, $inHead);
145- }
135+ protected function define()
136+ {
137+ $this
138+ ->add(Asset::createFromPath('styles.css')) // Add individual Assets
139+ ->merge($someOtherBundle); // Or combine multiple Bundles
140+
141+ // Create more complex Assets
142+ $source = '<script src =" https://pagecdn.io/lib/cleave/1.6.0/cleave.min.js" type =" text/javascript" ></script >';
143+ $inHead = true; // Force a JavaScript Asset to the <head > tag
144+ $asset = new Asset($source, $inHead);
145+ }
146146}
147147```
148148
@@ -159,18 +159,18 @@ use Tatter\Assets\Config\Assets as AssetsConfig;
159159
160160class Assets extends AssetsConfig
161161{
162- public $routes = [
163- '*' => [
164- 'bootstrap/bootstrap.min.css',
165- 'bootstrap/bootstrap.bundle.min.js',
166- 'font-awesome/css/all.min.css',
167- 'styles/main.css',
168- ],
169- 'files' => [
170- 'dropzone/dropzone.min.css',
171- 'dropzone/dropzone.min.js',
172- ],
173- ];
162+ public $routes = [
163+ '*' => [
164+ 'bootstrap/bootstrap.min.css',
165+ 'bootstrap/bootstrap.bundle.min.js',
166+ 'font-awesome/css/all.min.css',
167+ 'styles/main.css',
168+ ],
169+ 'files' => [
170+ 'dropzone/dropzone.min.css',
171+ 'dropzone/dropzone.min.js',
172+ ],
173+ ];
174174}
175175```
176176
@@ -192,21 +192,21 @@ Add this module as well:
192192Edit your ** Filters.php** config file to enable the ` AssetsFilter ` on all routes:
193193
194194``` php
195- /**
196- * List of filter aliases that are always
197- * applied before and after every request.
198- *
199- * @var array
200- */
201- public $globals = [
202- 'before' => [
203- // 'honeypot',
204- // 'csrf',
205- ],
206- 'after' => [
207- 'assets' => ['except' => 'api/*'],
208- ],
209- ];
195+ /**
196+ * List of filter aliases that are always
197+ * applied before and after every request.
198+ *
199+ * @var array
200+ */
201+ public $globals = [
202+ 'before' => [
203+ // 'honeypot',
204+ // 'csrf',
205+ ],
206+ 'after' => [
207+ 'assets' => ['except' => 'api/*'],
208+ ],
209+ ];
210210```
211211
212212Create a new ` Bundle ` to define your Bootstrap files in ** app/Bundles/DropzoneJS.php** :
@@ -218,10 +218,10 @@ use Tatter\Assets\Bundle;
218218
219219class DropzoneJS extends Bundle
220220{
221- protected $paths = [
222- 'dropzone/dropzone.min.css',
223- 'dropzone/dropzone.min.js',
224- ];
221+ protected $paths = [
222+ 'dropzone/dropzone.min.css',
223+ 'dropzone/dropzone.min.js',
224+ ];
225225}
226226```
227227
@@ -230,20 +230,20 @@ will load on every route and DropzoneJS will load on specific routes:
230230
231231``` php
232232public $routes = [
233- '*' => [
234- 'bootstrap/dist/css/bootstrap.min.css',
235- 'bootstrap/dist/js/bootstrap.bundle.min.js',
236- ],
237- 'files/*' => [
238- \App\Bundles\DropzoneJS::class,
239- ],
240- 'upload' => [
241- \App\Bundles\DropzoneJS::class,
242- ],
233+ '*' => [
234+ 'bootstrap/dist/css/bootstrap.min.css',
235+ 'bootstrap/dist/js/bootstrap.bundle.min.js',
236+ ],
237+ 'files/*' => [
238+ \App\Bundles\DropzoneJS::class,
239+ ],
240+ 'upload' => [
241+ \App\Bundles\DropzoneJS::class,
242+ ],
243243];
244244```
245245
246- > Note: We could have made a ` Bundle ` for Bootstrap as well but since they are only needed for on route this is just as easy.
246+ > Note: We could have made a ` Bundle ` for Bootstrap as well but since they are only needed for one route this is just as easy.
247247
248248If you finished all that then your assets should be injected into your ` <head> ` and ` <body> ` tags accordingly.
249249
@@ -278,3 +278,65 @@ Your view file:
278278</body >
279279</html >
280280```
281+
282+ ## Vendor Classes
283+
284+ This library includes two abstract class stubs to ease working with third-party assets.
285+ ` VendorPublisher ` is a wrapper for the framework's [ Publisher Library] ( https://codeigniter.com/user_guide/libraries/publisher.html )
286+ primed for use with ` Assets ` , and ` VendorBundle ` is a specialized version of this library's
287+ ` Bundle ` primed to handle assets published via ` VendorPublisher ` . Together these two classes
288+ can take a lot of the work out of managing assets you include from external sources.
289+
290+ Let's revisit the example above... Instead of copies the files into ** public/assets/** ourselves
291+ (and re-copying every time there is an update) let's create a ` VendorPublisher ` to do that
292+ for us. In ** app/Publishers/BootstrapPublisher.php** :
293+ ``` php
294+ <?php
295+
296+ namespace App\Publishers;
297+
298+ use Tatter\Assets\VendorPublisher;
299+
300+ class BootstrapPublisher extends VendorPublisher
301+ {
302+ protected $source = 'vendor/twbs/bootstrap/dist';
303+ protected $path = 'bootstrap';
304+ }
305+
306+ ```
307+
308+ That's all! ` VendorPublisher ` knows that ` $path ` is relative the to directory in your Assets
309+ config file, so when you run ` php spark publish ` next all the latest Bootstrap assets will
310+ be copied into that directory (default: ** public/assets/vendor/** ).
311+
312+ > Note: Since these are external dependencies be sure to exclude them from your repo with your ** .gitignore** file.
313+
314+ Now lets use these assets. We can create a new ` VendorBundle ` and use the new ` addPath() `
315+ method to access the same files we just published from Composer's vendor directory.
316+ In ** app/Bundles/BootstrapBundle.php** :
317+ ``` php
318+ <?php
319+
320+ namespace App\Bundles;
321+
322+ use Tatter\Assets\VendorBundle;
323+
324+ class BootstrapBundle extends VendorBundle
325+ {
326+ protected function define(): void
327+ {
328+ $this
329+ ->addPath('bootstrap/bootstrap.min.css')
330+ ->addPath('bootstrap/bootstrap.bundle.min.js');
331+ }
332+ }
333+ ```
334+
335+ Now add the new bundle to our ** app/Config/Assets.php** routes:
336+ ``` php
337+ public $routes = [
338+ '*' => [\App\Bundles\BootstrapBundle::class],
339+ ];
340+ ```
341+
342+ And we have hands-free Bootstrap updates from now on!
0 commit comments