2017 © Pedro PelĂĄez
 

library assets

Assets module for UserFrosting

image

userfrosting/assets

Assets module for UserFrosting

  • Sunday, April 22, 2018
  • by alexweissman
  • Repository
  • 5 Watchers
  • 3 Stars
  • 9,270 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 12 Versions
  • 13 % Grown

The README.md

UserFrosting/Assets

Latest Version Software License Join the chat at https://chat.userfrosting.com/channel/support Donate, (*1)

Branch Build Coverage Style
master [![][assets-master-build]][assets-travis]
develop [![][assets-develop-build]][assets-travis]  

Assets is a library originally created for UserFrosting 4 to make it much easier to reference frontend assets in both production and development contexts., (*2)

Out of the box it can:, (*3)

  • Provide an easy way to generate an absolute url to an asset via a locator.
  • Provide a basic level of integration with gulp-bundle-assets and complete integration with @userfrosting/gulp-bundle-assets, making it easy to reference asset bundles.
  • Integrate via a common interface with virtually any bundling system.
  • Integrate with Slim to serve assets that are inaccessible from the public folder, in the development context.
  • Perform url-to-path transformations. Useful for making debuggable URLs that can be reverted back to the path to be used by the Slim asset server.
  • Integrate with your preferred (and extendable) templating engine to provide easy access to asset bundles (that get wrapped with the appropriate tags) and individual assets.

Installation

composer require userfrosting/assets

Usage

To use Assets, you will need:, (*4)

  • An instance of ResourceLocator, where you can add your desired search paths.
  • The locator scheme (if it exists) you wish to look for assets in.
  • The base url (used in generating URLs to assets).
  • The base path (used in trimming the absolute path returned by the locator).
<?php

use UserFrosting\UniformResourceLocator\ResourceLocator;
use UserFrosting\Assets\Assets;

$basePath = __DIR__;
$baseUrl = 'https://assets.userfrosting.com/';
$locator = new ResourceLocator($basePath);
$locator->registerStream('assets', '', [
    'owls/assets',
    'hawks/assets'
]);

$assets = new Assets($locator, 'assets', $baseUrl);

Optionally 1 more argument can be passed into the Assets constructor, an instance of PrefixTransformer., (*5)

Have a look at UserFrosting in dev mode to see this in action!, (*6)

Asset Bundles

To access asset bundles from an Assets instance, it must first be passed an instance of AssetBundlesInterface via addAssetBundles. The following example demonstates how to integrate with @userfrosting/gulp-bundle-assets (and by extension gulp-bundle-assets). Note that raw bundles are only supported when their configuration is defined as JSON., (*7)

Directory Tree, (*8)

/
├build/
│ └asset-bundles.json
└public/
  └index.php

build/asset-bundles.json, (*9)

{
  "bundle": {
    "js/main": {
      "scripts": [
        "js/bootstrap-3.3.1.js",
        "js/crud.js"
      ]
    },
    "css/main": {
      "styles": [
        "vendor/font-awesome-4.5.0/css/font-awesome.css",
        "css/bootstrap-3.3.1.css",
        "css/bootstrap-custom.css",
        "css/paper.css"
      ]
    }
  }
}

public/index.php, (*10)

use UserFrosting\Assets\GulpBundleAssetsRawBundles;

// Load asset bundles.
$assetBundles = new GulpBundleAssetsRawBundles('../build/asset-bundles.json');

// Send loaded asset bundles to Assets instance.
$assets->addAssetBundles($assetBundles);

// Grab an asset bundle.
$assets->getJsBundleAssets('js/main');
// Outputs ["js/bootstrap-3.3.1.js", "js/crud.js"]

Compiled bundles can be used in much the same way, except using GulpBundleAssetsCompiledBundles and the bundlers result file., (*11)

If using the original gulp-bundle-assets you'll need to include an additional setting options->result->type->styles/scripts="plain" in each bundle., (*12)

The Template Plugin

The template plugin is easy initialized by giving it the Assets instance, and simply gets passed into the templating engine environment of your choice to be used., (*13)

use UserFrosting\Assets\AssetsTemplatePlugin;

$assetsPlugin = new AssetsTemplatePlugin($assets);

// Some code that passes it to Twig rendering environment.
{# Gets replaced at runtime with the following. Additional argument is optional. #}
{{ assets.js("js/main", { defer: true }) }}
<script src="https://assets.userfrosting.com/assets/bootstrap/js/bootstrap.js" defer="true"></script>
<script src="https://assets.userfrosting.com/assets/bootstrap/js/npm.js" defer="true"></script>

Style Guide

Testing

The Versions

22/04 2018

dev-feature-locator

dev-feature-locator https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordan Mele

css javascript assets images userfrosting

13/12 2017

dev-develop

dev-develop https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordan Mele

css javascript assets images userfrosting

13/12 2017

5.0.0-rc.0

5.0.0.0-RC0 https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordan Mele

css javascript assets images userfrosting

18/11 2017

dev-feature-modularisation-overhaul

dev-feature-modularisation-overhaul https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript assets images userfrosting

18/06 2017

dev-master

9999999-dev https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript assets images userfrosting

18/06 2017

4.1.0

4.1.0.0 https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript assets images userfrosting

09/03 2017

4.0.1

4.0.1.0 https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript assets images userfrosting

09/03 2017

dev-fix-deps

dev-fix-deps https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

The Development Requires

css javascript assets images userfrosting

18/02 2017

4.0.0

4.0.0.0 https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

css javascript assets images userfrosting

18/02 2017

dev-dev

dev-dev https://github.com/userfrosting/assets

Assets module for UserFrosting

  Sources   Download

MIT

The Requires

 

css javascript assets images userfrosting

01/05 2016

1.1

1.1.0.0

  Sources   Download

The Requires

  • php >=5.4

 

05/04 2016

1.0

1.0.0.0

  Sources   Download

The Requires

  • php >=5.4