I stumbled upon this project and I'm wondering if there are any plans to implement an asset pipeline like Rails does.
Implemented the right way it would make using arbitrary crates to transform assets a lot easier. I'm mostly thinking of HAML/SASS support.
I previously answered this question on a thread on Reddit. I've copy/pasted my response below:
Server-side asset rendering isn't something I see being added to Rocket core, but it might be a good contirb library. Implementing such a library is actually pretty straightforward with Rocket. One approach is to create a new type, Asset, that's constructed with a file path and implements Responder. When generating a Response, the Asset type can look up the file extension and perform the necessary compilation. You can even get fancy and implement a nice cache on top of this. To actually render an asset, you'd simply need to return the Asset type from a handler. That would look something like this:
#[get("/asset/<path...>")]
fn render_asset(path: PathBuf) -> Option<Asset> {
Asset::open(path).ok()
}
This would render every file at path $CWD/path. If the file doesn't exist, this would return a 404.
@sphinxc0re Do you feel we can close out this issue?
Yup! Thank you very much 馃憤
Most helpful comment
I previously answered this question on a thread on Reddit. I've copy/pasted my response below:
Server-side asset rendering isn't something I see being added to Rocket core, but it might be a good
contirblibrary. Implementing such a library is actually pretty straightforward with Rocket. One approach is to create a new type,Asset, that's constructed with a file path and implementsResponder. When generating aResponse, the Asset type can look up the file extension and perform the necessary compilation. You can even get fancy and implement a nice cache on top of this. To actually render an asset, you'd simply need to return theAssettype from a handler. That would look something like this:This would render every file at path
$CWD/path. If the file doesn't exist, this would return a 404.