Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable running in WebAssembly #79

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion ramhorns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ impl<H> fmt::Debug for Ramhorns<H> {
}

impl<H: BuildHasher + Default> Ramhorns<H> {

/// Create a new empty aggregator with no initial folder.
/// ```no_run
/// use ramhorns::{Ramhorns,Content};
/// #[derive(Content)]
/// struct Data {
/// content: String,
/// }
/// let data = Data{
/// content: "I am the content".to_string(),
/// };
/// let mut tpls: Ramhorns = Ramhorns::new();
/// tpls.insert("{{content}}", "template").unwrap();
/// let rendered = tpls.get("template").unwrap().render(&data);
/// ```
pub fn new() -> Self {
Ramhorns {
partials: HashMap::default(),
dir: PathBuf::new(),
}
}

/// 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]
Expand Down Expand Up @@ -200,7 +222,7 @@ impl<H: BuildHasher + Default> Ramhorns<H> {
partials: HashMap::default(),
dir: dir.as_ref().canonicalize()?,
})
}
}

/// Get the template with the given name, if it exists.
pub fn get(&self, name: &str) -> Option<&Template<'static>> {
Expand Down