├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── composer.json
├── config
└── asset-helper.php
└── src
├── AssetHelper.php
├── AssetHelperFacade.php
└── AssetHelperServiceProvider.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.phar
3 | composer.lock
4 | .DS_Store
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.3
5 | - 5.4
6 | - 5.5
7 | - 5.6
8 | - hhvm
9 |
10 | before_script:
11 | - composer self-update
12 | - composer install --prefer-source --no-interaction --dev
13 |
14 | script: phpunit
15 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All Notable changes to `asset-helper` will be documented in this file
4 |
5 | ## 2.0.0 - 2016-04-22
6 | - Laravel 5.1 compatibility
7 |
8 | ## 1.1.1 - 2015-09-17
9 |
10 | ### Fixed
11 | - Killed a bug where directory would not be returned
12 |
13 | ## 1.1.0 - 2015-09-17
14 |
15 | ### Added
16 | - Support for complex paths
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Freek
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | [](https://supportukrainenow.org)
3 |
4 | Get the url to a revisioned asset
5 | =======
6 | [](https://packagist.org/packages/spatie/asset-helper)
7 | [](https://packagist.org/packages/spatie/asset-helper)
8 |
9 | This Laravel 4 package enables you to get an url to a revisioned asset.
10 |
11 | That sounds a bit vague, right? Let me clear it up by showing an example.
12 | Calling this provided method `Asset::getUrl('admin.css')` returns `/assets/admin.0ce5cb43.css`
13 |
14 | This package assumes that your asset pipeline:
15 | - saves all of your assets in one public folder.
16 | - puts a random string in the filename of every asset as a cache-busting mechanism
17 |
18 | Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).
19 |
20 | ## Support us
21 |
22 | Learn how to create a package like this one, by watching our premium video course:
23 |
24 | [](https://laravelpackage.training)
25 |
26 | We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
27 |
28 | We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
29 |
30 | ## Postcardware
31 |
32 | You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.
33 |
34 | Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
35 |
36 | The best postcards will get published on the open source page on our website.
37 |
38 | ##Installation
39 | The package can be installed through Composer:
40 |
41 | ```
42 | composer require spatie/asset-helper
43 | ```
44 |
45 | This service provider must be installed:
46 |
47 | ```php
48 |
49 | //for laravel <=4.2: app/config/app.php
50 |
51 | 'providers' => [
52 | ...
53 | 'Spatie\AssetHelper\AssetHelperServiceProvider'
54 | ...
55 | ];
56 | ```
57 |
58 | This package also comes with a facade, which provides an easy way to call the the functionality.
59 |
60 |
61 | ```php
62 |
63 | //for laravel <=4.2: app/config/app.php
64 |
65 | 'aliases' => array(
66 | ...
67 | 'Asset' => 'Spatie\AssetHelper\AssetHelperFacade',
68 | ...
69 | )
70 | ```
71 |
72 | ##Configuration
73 | You can publish the configuration file using this command:
74 | ```console
75 | php artisan config:publish spatie/asset-helper
76 | ```
77 |
78 | A configuration-file with some sensible defaults will be placed in your config/packages directory:
79 |
80 | ```php
81 | return
82 | [
83 | /**
84 | * The url that points to the directory were your assets are stored
85 | *
86 | */
87 | 'assetDirectoryUrl' => '/assets',
88 | ];
89 | ```
90 |
91 | ##Usage
92 | ```Asset::getUrl($nonRevisionedAssetName)``` takes a non-revisioned asset name and it returns the url to the revisioned asset.
93 |
94 | ##Example
95 | Let's assume the public path of your website is `/home/forge/yourwebsite.be/public` and that your asset pipeline stores the minified, uglified, ... and whatnot assets in this directory: `/home/forge/yourwebsite.be/public/assets`
96 |
97 | Suppose this is the contents of that directory:
98 | - admin.0ce5cb43.css
99 | - admin.defer.adc60631.js
100 | - admin.head.1954b61c.js
101 | - front.0b4c09c7.css
102 | - front.defer.1ba6b072.js
103 | - front.head.1954b61c.js
104 |
105 | As a cache-busting mechanism your asset pipeline probably puts a random string in the filename of the asset. In the example above this is '0ce5cb43', 'adc60631', '1954b61c.js', ...
106 |
107 | Calling `Asset::getUrl('admin.css')` returns `/assets/admin.0ce5cb43.css`
108 |
109 | So your layout file could look something like this:
110 |
111 | ```html+php
112 |
113 |
114 |