[][src]Struct ructe::StaticFiles

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 all files from a specific directory, indir, as static files.

The to string is used as a directory path of the resulting urls, the file names are taken as is, without adding any hash. This is usefull for resources used by preexisting javascript packages, where it might be hard to change the used urls.

Add one specific file as a static file.

Create a name to use in the url like name-hash.ext where name and ext are the name and extension from path and has is a few url-friendly bytes from a hash of the file content.

Add one specific file as a static file.

Use to_name in the url without adding any hash characters.

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.

Auto Trait Implementations

impl Send for StaticFiles

impl Sync for StaticFiles

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]