module Lucky::AssetHelpers
Overview
Methods for returning the path to assets
These methods will return fingerprinted paths, check assets at compile time, and allow for setting a CDN.
For an in-depth guide check: https://luckyframework.org/guides/frontend/asset-handling
Direct including types
Defined in:
lucky/asset_helpers.crConstant Summary
-
ASSET_MANIFEST =
{} of String => String
-
CONFIG =
{has_loaded_manifest: false}
Macro Summary
-
asset(path)
Return the string path to an asset
- load_manifest(manifest_file = "")
-
load_manifest(manifest_file, use_vite)
EXPERIMENTAL This feature is experimental.
Instance Method Summary
-
#dynamic_asset(path) : String
Return the string path to an asset (allows string interpolation)
Macro Detail
Return the string path to an asset
# In a page or component:
# Will find the asset in `public/assets/images/logo.png`
img src: asset("images/logo.png")
# Can also be used elsewhere by prepending Lucky::AssetHelpers
Lucky::AssetHelpers.asset("images/logo.png")
Note that assets are checked at compile time so if it is not found, Lucky will let you know. It will also let you know if you had a typo and suggest an asset that is close to what you typed.
NOTE This macro requires a StringLiteral
. That means you cannot
interpolate strings like this: asset("images/icon-#{service_name}.png")
.
instead use #dynamic_asset
if you need string interpolation.
EXPERIMENTAL This feature is experimental. Use this to test vite integration with Lucky
Instance Method Detail
Return the string path to an asset (allows string interpolation)
# In a page or component
# Will find the asset in `public/assets/images/logo.png`
img src: asset("images/logo.png")
# Can also be used elsewhere by prepending Lucky::AssetHelpers
Lucky::AssetHelpers.asset("images/logo.png")
NOTE This method does not check assets at compile time. The asset path is found at runtime so it is possible the asset does not exist. Be sure to manually test that the asset is returned as expected.