trikoder/assets-manifest-bundle

There is no license information available for the latest version (v1.0.1) of this package.

Symfony bundle for generating asset urls for our new frontend static asset builing tool

v1.0.1 2018-11-27 11:33 UTC

This package is auto-updated.

Last update: 2024-03-28 04:41:14 UTC


README

This bundle provides Twig helper for generating urls for static public assets.

It reads information from simple JSON config file. There is an example file in manifest.json

Usage

Bundle provides two Twig functions - manifestAsset and manifestAssetInline.

mainfestAsset takes 2 parameters:

  • asset url in format @BundleName:path/to/asset or namespaced path @BundleName/path/to/asset
  • optional array with options
    • for now only option is: "absolute" => if true function returns absolute URIs

Example usage:

<link href="{{ manifestAsset('@AppBundle:css/bundles/home.css') }}" rel="stylesheet" type="text/css">

<script async src="{{ manifestAsset('@AppBundle:js/home.js') }}"></script>

manifestAssetInline takes 1 parameter:

  • asset url in format @BundleName:path/to/asset or namespaced path @BundleName/path/to/asset

It returns the file content of the asset.

Example usage:

<style>{{ manifestAssetInline('@AppBundle:css/bundles/home.css') }}</style>

Using custom Twig namespaces

First, you need to register your Twig namespace:

twig:
    paths:
        '%kernel.project_dir%/src/App/Resources': SomeTwigNamepace

Then, you can use :

<style>{{ manifestAsset('@SomeTwigNamepace/css/home.css') }}</style>
<style>{{ manifestAssetInline('@SomeTwigNamepace/js/home.js') }}</style>

Note: Twig namespace references does not contain separator : like bundles. See this link for more details.

Running tests and linter

For running tests and linter, there is a complete docker enviroment with php and all required tools. To setup environment use:

bin/dev/docker-compose build
bin/dev/composer install

To run tests (after environment is built):

bin/dev/composer test

To run linter:

bin/dev/phpcsfixer fix --dry-run .

To automaticaly fix coding standards, just ommit --dry-run parameter.

Credits

Copyright (C) 2017 Trikoder

Authors: Alen Pokos, Damir Brekalo, Krešo Kunjas.

Contributors: Branimir Đurek

License

Package is licensed under MIT License