pub struct Assets { /* private fields */ }
Implementations§
Source§impl Assets
impl Assets
Sourcepub fn new<S: Into<String>, P: Into<PathBuf>>(identifier: S, path: P) -> Self
pub fn new<S: Into<String>, P: Into<PathBuf>>(identifier: S, path: P) -> Self
Creates a new Assets
Pipeline
By default, the filter list type is a blacklist.
Sourcepub fn filter(self, filter: Filter) -> Self
pub fn filter(self, filter: Filter) -> Self
Add a filter to the pipeline
Filters are applied in the order that they were added, the first matching filter determines how the file entry is handled. If you want to include all Lua files, but not the ones in a certain folder, then you should add the exclusion rule first, and then the inclusion filter.
If there are no filters then all files are matched. If there are no filters and it’s a whitelist, no files are matched.
§Examples
Matching everything except png and jpg files:
Assets::new("NON_IMAGE_ASSETS", "../resources")
.filter(Filter::exclude_extension("png"))
.filter(Filter::exclude_extension("jpg"))
.filter(Filter::exclude_extension("jpeg"));
Include all Lua files and exclude all files in the admin
subdirectory:
Assets::new("ASSETS", "../lua_src")
.whitelist()
.filter(Filter::exclude_regex(r"^admin/.*$"))
.filter(Filter::include_extension("lua"));
If you wanted to only match text and markdown files:
Assets::new("ASSETS", "../notes")
.whitelist()
.filter(Filter::include_extension("txt"))
.filter(Filter::include_extension("md"));
or to include all assets in a subdirectory styles
:
Assets::new("ASSETS", "../web/dist")
.whitelist()
.filter(Filter::include_regex(r"^styles/.*$"));
NOTE: If you need to care about multi-platform it’s your responsibility
to use a proper regex that accounts for the proper path separator.
See FilterRule::regex
for examples that account for this.
AFAIK std::path
doesn’t normalize the separators.
Sourcepub fn prefix<S: Into<String>>(self, prefix: S) -> Self
pub fn prefix<S: Into<String>>(self, prefix: S) -> Self
Sets the prefix to use for the normalized path uri.
This is relative to where your asset path is. If your asset path is "./web/dist/assets"
,
with your web root being at "./web/dist"
, then having a prefix of "/assets"
would make
the relative URIs align with your web root to make the hit URL correct.
Defaults to "/"