Package Data | |
---|---|
Maintainer Username: | canalaiz |
Maintainer Contact: | canalaiz@gmail.com (Alessandro Canali) |
Package Create Date: | 2016-11-15 |
Package Last Update: | 2018-04-10 |
Home Page: | |
Language: | PHP |
License: | BSD-3-Clause |
Last Refreshed: | 2024-11-18 03:02:22 |
Package Statistics | |
---|---|
Total Downloads: | 91 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 1 |
Total Open Issues: | 0 |
Sam (short for Simple Assets Manager) is a library built for Laravel 5.*. It provides an easy way to add assets (usually stylesheet or javascript files) to the page after it has been rendered.
Sam, by default, uses simple substr and stripos to inject content within the html page. You can override this behaviour binding a different instance to Canalaiz\Sam\Contracts\HtmlInjectEngine
.
composer update
:"canalaiz/sam": "1.*"
config/app.php
and add the following to the providers
array:Canalaiz\Sam\SamServiceProvider::class,
config/app.php
and add the following to the aliases
array:'Sam' => Canalaiz\Sam\Facades\Sam::class,
app/Http/Kernel.php
in the generic $middleware
array or within the $middlewareGroups
array:\Canalaiz\Sam\Middleware\Sam::class,
You can use Sam in every context you like, since the injection happens after views are rendered and before the html is sent to the browser. The only requirement is to put the use statement:
use Sam;
Css can be appended within document in two different ways: normal and inline. An optional minify
parameter can be passed as second argument to request css minifying. This parameter defaults to false
on Sam::pushCss
and true
to Sam::pushInlineCss
. Minified assets are downloaded first and then served locally.
The following command appends a stylesheet tag declaration before the closing of the HEAD tag:
Sam::pushCss('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
If you need to minify the asset, use this command:
Sam::pushCss('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', true);
The following command appends a stylesheet tag declaration before the closing of the HEAD tag, but content of original source url will be directly injected in the html within a tag:
Sam::pushInlineCss('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
Javascript can be appended within document in two different ways: normal and inline. An optional minify
parameter can be passed as second argument to request css minifying. This parameter defaults to false
on Sam::pushJs
and true
to Sam::pushInlineJs
. Minified assets are downloaded first and then served locally.
The following command appends a script tag declaration before the closing of the BODY tag:
Sam::pushJs('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js');
If you need to minify the asset, use this command:
Sam::pushJs('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', true);
The following command appends a script tag declaration before the closing of the BODY tag, but content of original source url will be directly injected in the html within a tag:
Sam::pushInlineJs('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js');
A placeholder is an html comment in the format: <!--PLACEHOLDER-->
. The following command prepends an html block before a specific placeholder:
Sam::pushPlaceholder('PLACEHOLDER', '<div>Hello from Sam!</div>');
The following command appends an html block before the closing of a specific tag.
Sam::pushTag('body', '<div>Hello from Sam!</div>');
Simple Asset Manager is free software distributed under the terms of the BSD-3-Clause license. Please refer to license.
Support follows PSR-1 and PSR-4 PHP coding standards, and semantic versioning.
Please report any issue you find in the issues page.
Pull requests are welcome.