Struct ructe::StaticFiles [] [src]

pub struct StaticFiles { /* fields omitted */ }

Handler for static files.

To just add all files in a single directory, there is a shorthand method compile_static_files. For more complex setups (static files in more than one directory, generated static files, etc), use this struct.

Each static file will be available as a StaticFile struct instance in your templates::statics module. Also, the const STATICS array in the same module will contain a reference to each of those instances.

Methods

impl StaticFiles
[src]

Create a new set of static files.

There should only be one StaticFiles for a set of compiled templates. The outdir should be the same as in the call to compile_templates.

Add all files from a specific directory, indir, as static files.

Add one specific file as a static file.

Add a file by its name and content.

The path parameter is used only to create a file name, the actual content of the static file will be the data parameter.

Get a mapping of names, from without hash to with.

let mut statics = StaticFiles::new(&p).unwrap();
statics.add_file_data("black.css".as_ref(), b"body{color:black}\n");
statics.add_file_data("blue.css".as_ref(), b"body{color:blue}\n");
assert_eq!(statics.get_names().iter()
               .map(|(a, b)| format!("{} -> {}", a, b))
               .collect::<Vec<_>>(),
           vec!["black_css -> black-r3rltVhW.css".to_string(),
                "blue_css -> blue-GZGxfXag.css".to_string()])

Trait Implementations

impl Drop for StaticFiles
[src]

Write the ending of the statics source code, declaring the STATICS variable.