module

Plombir::Assets::Rewrite

Constants

OUTPUT_DIR = "assets"
REF = /((?:src|href)\s*=\s*)(["'])([^"']*)\2/i

Quoted src/href, either quote style, attribute name in any case. Group 1 is src=" (prefix), 2 the quote, 3 the URL.

URL_PREFIX = "/assets/"

URL prefix this pass owns, and the output directory fingerprinted files live under (dist/assets/…). public/ mirrors the output root, so /assets/x is backed by public/assets/x.

Class methods

asset_url(path : String, manifest : Hash(String, String)) : String

Resolves one asset path to its public URL through manifest: a hit returns the fingerprinted URL, a miss the unfingerprinted /assets/… form (backed by public/, or reported missing by the rewrite pass). The | asset_url filter delegates here so both spellings share one rule.

Rewrite.asset_url("style.css", {"style.css" => "assets/style.a1b2c3d4.css"})
# => "/assets/style.a1b2c3d4.css"
Rewrite.asset_url("logo.png", {} of String => String)
# => "/assets/logo.png"
Source
rewrite(html : String, manifest : Hash(String, String), public_dir : String) : Result

Rewrites quoted src/href attributes in html through manifest (source-relative under assets/ → output-relative under dist/). public_dir backs the existence check for non-fingerprinted files.

Rewrite.rewrite(%(<img src="/assets/a.png">), {"a.png" => "assets/a.12345678.png"}, "public")
Source

Nested types