flowcontrol/assets-manager

1.1.5 2016-12-29 16:58 UTC

This package is auto-updated.

Last update: 2024-09-14 18:47:32 UTC


README

安装

使用 Composer

composer require flowcontrol/asset-manager

添加服务提供者

\FlowControl\Assets\AssetsServiceProvider::class,

外观

'Asset'    => \FlowControl\Assets\AssetsFacade::class,

用法

基本用法

资产管理器与 Laravel 框架配合使用。它提供了一个外观以方便使用。

您可以通过 add 方法或使用魔法方法来指定您的资产组。

Asset::add('test.css', 'css');
// is the same as
Asset::addCss('test.css');

您可以通过 get 方法或其等价魔法方法来检索一个组。

Asset::get('css');
// is the same as
Asset::getCss();

您还可以为您的资产指定优先级。例如,当使用 jQuery 库时,您需要在其依赖的其他库之前包含它。

// The sort is from highest to lowest priority. The default priority is 0.
Asset::addJs('jquery.js', 100);
Asset::add('jquery.js', 'js', 100);

快捷方式

您可以定义一个快捷方式,这是一个定义多个资产一次的类。如果您正在使用需要包含 js 和 css 代码的 js 库,可以使它更容易。

// Create a class that implements the Shortcut contract
class WysiwygShortcut implements FlowControl\Assets\Contracts\Shortcut {
    public function execute()
    {
        Asset::addJs('tinymce.js');
        Asset::addCss('tinymce.css');
        Asset::addCss('tinymce.theme.css');
    }
}

// Register it with the Asset Manager
Asset::shortcut('wysiwyg', WysiwygShortcut::class);

// And then call it like a method of the Manager
Asset::wysiwyg();

您需要决定在哪里注册快捷方式。一个好的地方是在您的 Laravel 应用程序中的服务提供者中。