Download the PHP package webrouse/n-asset-macro without Composer

On this page you can find all versions of the php package webrouse/n-asset-macro. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package n-asset-macro

Webrouse/n-asset-macro

Build Status Scrutinizer Code Quality Code Coverage Latest stable Donate

Asset macro for Latte and Nette Framework.

Useful for assets cache busting with gulp, webpack and other similar tools.

Requirements

Nette 3 is fully supported and tested.

Installation

The best way to install webrouse/n-asset-macro is using Composer:

Then register the extension in the config file:

Usage

Macro can by used in any presenter or control template:

It prepends path with $basePath or $baseUrl (see revision manifest:

See the webpack.

Revision manifest

Revision manifest is a JSON file that contains the revision (path or version) of asset.

It can be generated by various asset processors such as gulp and webpack, see examples.

Revision manifest is searched in the asset directory and in the parent directories up to %wwwDir%.

Expected file names: assets.json, busters.json, versions.json, manifest.json, rev-manifest.json.

The path to revision manifest can be set directly (instead of autodetection):

Or you can specify asset => revision pairs in config file:

Revision manifest may contains asset version or the asset path. Both ways are supported.

Method 1: asset version in file name (preferable)

With this method, the files have a different name at each change.

Example revision manifest:

With the example manifest, the expr. {asset "js/app.js"} generates: /base/path/js/app.234a81ab33.js.

Method 2: asset version as a query string

This approach looks better at first glance. The asset path is still the same, and only the parameter in the query changes.

However, it can cause problems with some cache servers, which don't take the URL parameters into account.

Example revision manifest:

With the example manifest, the expr. {asset "js/app.js"} generates: /base/path/js/app.js?v=234a81ab33.

Asset macro automatically detects which of these two formats of revision manifest is used.

Macro arguments

format

The format is defined by the second macro parameter or using the format key (default %url%).

format can be used with needed => false to hide whole asset expression (eg. <link ...) in case of an error.

You can also use it to include asset content instead of a path.

Placeholder Example output
%content% <svg>....</svg> (file content)
%path% js/main.js or js/main.8c48f58df.js
%raw% 8c48f58df or js/main.8c48f58df.js
%base% %baseUrl% if absolute => true else %basePath%
%basePath% /base/path
%baseUrl% http://www.example.com/base/path
%url% %base%%path% (default format) eg. /base/path/js/main.8c48f58df.js

needed

Error handling is set in the configuration using: missingAsset, missingManifest and missingRevision keys.

These settings can by overrided by third macro parameter or using needed key (default true).

Argument needed => false will cause the missing file or the missing revision record will be ignored.

Missing version will be replaced with unknown string.

Example of needed parameter

Generated output:

absolute

Output URL type - relative or absolute - is defined by fourth macro parameter or using absolute key (default false).

If absolute => true or asset path is prefixed with // eg. (//assets/js/main.js), the absolute URL will be generated instead of a relative URL.

Generated output:

Caching

In production mode is the macro output cached in default application's cache storage.

It can be changed in the configuration using the boolean cache key.

Configuration

Default configuration, which usually doesn't need to be changed:

ManifestService

It is also possible to access the manifest from your code using Webrouse\AssetMacro\ManifestService (from DI container).

Examples

Examples based on nette/sandbox:

License

N-asset-macro is under the MIT license. See the LICENSE file for details.


All versions of n-asset-macro with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
latte/latte Version >=2.4
nette/di Version >=2.4
nette/utils Version >=2.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package webrouse/n-asset-macro contains the following files

Loading the files please wait ....