Skip to main content

Module assets

Module assets 

Expand description

#1883 (static assets), slice 1b: the project’s assets folder — the one directory an asset name = "path" declaration may name a file in — and the walk that reads it.

Assets are public by construction, so they come only from <project root>/assets/ (decided on #1883 after the review of #1903): a declaration can never publish .env or a .bynk source by mistake. The checker states the rule (bynk.asset.outside_assets_dir); the driver and the test harnesses list the folder as an AssetFolder, so bynk-emit and bynk-check stay disk-free and read the bytes of only the files a declaration names, and the LSP lists it with list_asset_files for the existence check.

Structs§

AssetFolder
The project’s assets/ folder as the compiler sees it: the files in it, listed up front, and a reader the compiler calls for the bytes of only those a declaration names. A large file nothing declares is never read.

Constants§

PROJECT_ASSETS_DIR
The project’s assets folder, relative to the project root.
PROJECT_EMBEDS_DIR
The project’s embedded-text folder, relative to the project root (#2387). Unlike PROJECT_ASSETS_DIR nothing in it is served: an embed compiles a file’s text into the code. It is listed and read as an AssetFolder (EmbedFolder).

Functions§

is_in_assets_dir
Whether the normalised path names a file inside the assets folder — assets/<at least one more segment>.
is_in_embeds_dir
Whether the normalised path names a file inside the embeds folder — embeds/<at least one more segment>.
list_asset_files
Every regular file under <project_root>/assets/, by its normalised project-relative path (assets/board.css), without reading any bytes. Symbolic links are not followed, so a link cannot pull a file in from outside the folder; a missing folder is an empty set.
list_embed_files
list_asset_files for the project’s embeds/ folder (#2387).
normalise_asset_path
path as the key list_asset_files files it under: separators made /, and empty and . segments dropped, so ./assets//board.css and assets\board.css both become assets/board.css. A .. segment is kept (the checker rejects it separately, bynk.asset.unsafe_path).

Type Aliases§

AssetReader
Reads one listed asset file’s bytes, given its normalised key.
EmbedFolder
The project’s embeds/ folder as the compiler sees it: an AssetFolder over embeds/ instead of assets/ (#2387).