trikoder / assets-manifest-bundle
Symfony bundle for generating asset urls for our new frontend static asset builing tool
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 7
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.6.0
- symfony/config: >=2.7 <=5.0
- symfony/dependency-injection: >=2.7 <=5.0
- symfony/http-foundation: >=2.7 <=5.0
- symfony/http-kernel: >=2.7 <=5.0
- twig/twig: ~1.14|~2.0
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2024-10-28 05:49:13 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