...
Components learn about assets via injection. The @Inject annotation allows Assets to be injected into components as read-only properties. The path to the resource is specified using the Path annotation:
Code Block | ||||
---|---|---|---|---|
| ||||
@Inject @Path("context:images/tapestry_banner.gif") private Asset banner; |
Assets are located within domains; these domains are identified by the prefix on the @Path annotation's value
.
...
You can use relative paths with domains (if you omit the prefix):
Code Block | ||||
---|---|---|---|---|
| ||||
@Inject @Path("../edit.png") private Asset icon; |
Since you must omit the prefix, this only makes sense for components packaged in a library for reuse.
...
Symbols inside the annotation value are expanded. This allows you to define a symbol and reference it as part of the path. For example, you could contribute a symbol named "skin.root" as "context:skins/basic" and then reference an asset from within it:
Code Block | ||||
---|---|---|---|---|
| ||||
@Inject @Path("${skin.root}/style.css") private Asset style; |
Note |
---|
The use of the |
...
By default, Tapestry secures file extensions ".class', ".tml" and ".properties". The list can be extended by contributing to the ResourceDigestGenerator service contribution.
...
Minimizing Assets
Since version 5.3, Tapestry provides a service, ResourceMinimizer, which will help to minimize all your static resources (principally CSS and JavaScript files).
...
Code Block | ||||
---|---|---|---|---|
| ||||
<dependency> <groupId>org.apache.tapestry</groupId> <artifactId>tapestry-yuicompressor</artifactId> <version>5.3.1</version> </dependency> |
...
If you want to add your own minimizer for particular types of assets, you can contribute to the ResourceMinimizer service. The service configuration maps the MIME-TYPE of your resource to an implementation of the ResourceMinimizer interface.
Code Block | ||
---|---|---|
| ||
@Contribute(ResourceMinimizer.class)
@Primary
public static void contributeMinimizers(MappedConfiguration<String, ResourceMinimizer> configuration)
{
configuration.addInstance(" text/coffeescript", CoffeeScriptMinimizer.class);
}
|
...