public abstract class AssetProcessor extends AssetOptions
Checks, validate and/or modify asset contents. An AssetProcessor
is usually provided as a separated dependency.
First thing to do is to add the dependency:
<dependency> <groupId>org.jooby</groupId> <artifactId>jooby-assets-my-processor</artifactId> <scope>provided</scope> </dependency>
Did you see the provided scope? We just need the processor for development, because assets are processed on the fly. For prod
, assets are processed at built-time via Maven/Gradle plugin, at runtime we don't need this. This also, helps to keep our dependencies and the jar size small.
Now we have the dependency all we have to do is to add it to our pipeline:
assets { pipeline: { dev: [my-processor] } }
It is possible to configure or set options too:
assets { pipeline: { dev: [my-processor] dist: [my-processor] } my-processor { foo: bar } }
Previous example, set a foo
property to bar
! Options can be set per environment too:
assets { pipeline: { dev: [my-processor] dist: [my-processor] } my-processor { dev { bar: bar } dist { foo: bar } foo: foo } }
Here, in dev
processor has two properties: foo:foo
and bar:bar
, while in dist
the processor only has foo:bar
The my-processor
will be resolved it to: org.jooby.assets.MyProcessor
class. The processor name is converted to MyProcessor
, it converts the hyphenated name to upper camel and by default processors are defined in the org.jooby.assets
package.
A custom binding is provided via the class
property:
assets { pipeline: { dev: [my-processor] dist: [my-processor] } my-processor { class: whatever.i.Want } }
Constructor and Description |
---|
AssetProcessor() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
matches(MediaType type) |
String |
name() |
String |
process(String filename, String source, com.typesafe.config.Config conf)
Method that processes the provided source and returns the processed contents.
|
abstract String |
process(String filename, String source, com.typesafe.config.Config conf, ClassLoader loader)
Method that processes the provided source and returns the processed contents, with access to the ClassLoader.
|
AssetProcessor |
set(com.typesafe.config.Config options) |
AssetProcessor |
set(EngineFactory factory)
This method is executed by the AssetCompiler at processor creation time.
|
AssetProcessor |
set(String name, Object value) |
String |
toString() |
excludes, get, options
public String name()
public AssetProcessor set(String name, Object value)
set
in class AssetOptions
public AssetProcessor set(com.typesafe.config.Config options)
set
in class AssetOptions
public abstract boolean matches(MediaType type)
public String process(String filename, String source, com.typesafe.config.Config conf) throws Exception
filename
- name of the file
source
- contents of the file
conf
- application configuration
Exception
- if any error occurred
public abstract String process(String filename, String source, com.typesafe.config.Config conf, ClassLoader loader) throws Exception
filename
- name of the file
source
- contents of the file
conf
- application configuration
loader
- loader to use if any additional files need to be loaded from disk
Exception
- if any error occurred
public AssetProcessor set(EngineFactory factory)
AssetCompiler
at processor creation time.
factory
- Factory or null
.
Copyright © 2019. All rights reserved.