pub struct Ramhorns<H = FnvBuildHasher> { /* private fields */ }
Expand description
Implementations§
source§impl<H: BuildHasher + Default> Ramhorns<H>
impl<H: BuildHasher + Default> Ramhorns<H>
sourcepub fn from_folder<P: AsRef<Path>>(dir: P) -> Result<Self, Error>
pub fn from_folder<P: AsRef<Path>>(dir: P) -> Result<Self, Error>
Loads all the .html
files as templates from the given folder, making them
accessible via their path, joining partials as required. If a custom
extension is wanted, see [from_folder_with_extension]
let tpls: Ramhorns = Ramhorns::from_folder("./templates").unwrap();
let content = "I am the content";
let rendered = tpls.get("hello.html").unwrap().render(&content);
sourcepub fn from_folder_with_extension<P: AsRef<Path>>(
dir: P,
extension: &str
) -> Result<Self, Error>
pub fn from_folder_with_extension<P: AsRef<Path>>( dir: P, extension: &str ) -> Result<Self, Error>
Loads all files with the extension given in the extension
parameter as templates
from the given folder, making them accessible via their path, joining partials as
required.
let tpls: Ramhorns = Ramhorns::from_folder_with_extension("./templates", "mustache").unwrap();
let content = "I am the content";
let rendered = tpls.get("hello.mustache").unwrap().render(&content);
sourcepub fn extend_from_folder<P: AsRef<Path>>(
&mut self,
dir: P
) -> Result<(), Error>
pub fn extend_from_folder<P: AsRef<Path>>( &mut self, dir: P ) -> Result<(), Error>
Extends the template collection with files with .html
extension
from the given folder, making them accessible via their path, joining partials as
required.
If there is a file with the same name as a previously loaded template or partial,
it will not be loaded.
sourcepub fn extend_from_folder_with_extension<P: AsRef<Path>>(
&mut self,
dir: P,
extension: &str
) -> Result<(), Error>
pub fn extend_from_folder_with_extension<P: AsRef<Path>>( &mut self, dir: P, extension: &str ) -> Result<(), Error>
Extends the template collection with files with extension
from the given folder, making them accessible via their path, joining partials as
required.
If there is a file with the same name as a previously loaded template or partial,
it will not be loaded.
sourcepub fn lazy<P: AsRef<Path>>(dir: P) -> Result<Self, Error>
pub fn lazy<P: AsRef<Path>>(dir: P) -> Result<Self, Error>
Create a new empty aggregator for a given folder. This won’t do anything until
a template has been added using from_file
.
let mut tpls: Ramhorns = Ramhorns::lazy("./templates").unwrap();
let content = "I am the content";
let rendered = tpls.from_file("hello.html").unwrap().render(&content);
sourcepub fn get(&self, name: &str) -> Option<&Template<'static>>
pub fn get(&self, name: &str) -> Option<&Template<'static>>
Get the template with the given name, if it exists.
sourcepub fn from_file(&mut self, name: &str) -> Result<&Template<'static>, Error>
pub fn from_file(&mut self, name: &str) -> Result<&Template<'static>, Error>
Get the template with the given name. If the template doesn’t exist, it will be loaded from file and parsed first.
Use this method in tandem with lazy
.