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

feat: add Tera:new_uninitialized (#677) #845

Closed
wants to merge 1 commit into from
Closed
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
34 changes: 24 additions & 10 deletions src/tera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,24 @@ impl Tera {
Self::create(dir, true)
}

/// Create a new instance of Tera with no templates, filters, testers or functions registered.
///
/// To create a new instance of Tera without any templates, but with the default filters,
/// testers and functions registered, use [`Tera::default`].
///
#[must_use]
pub fn new_uninitialized() -> Tera {
Tera {
glob: None,
templates: HashMap::new(),
filters: HashMap::new(),
testers: HashMap::new(),
functions: HashMap::new(),
autoescape_suffixes: vec![".html", ".htm", ".xml"],
escape_fn: escape_html,
}
}

/// Loads all the templates found in the glob that was given to [`Tera::new`].
fn load_from_glob(&mut self) -> Result<()> {
let glob = match &self.glob {
Expand Down Expand Up @@ -890,17 +908,13 @@ impl Tera {
}

impl Default for Tera {
/// Creates a new Tera instance with the default filters, testers, and
/// functions registered.
///
/// For creating a new Tera instance with no default filters, testers, and
/// functions registered, use [`Tera::new_uninitialized`] instead.
fn default() -> Tera {
let mut tera = Tera {
glob: None,
templates: HashMap::new(),
filters: HashMap::new(),
testers: HashMap::new(),
functions: HashMap::new(),
autoescape_suffixes: vec![".html", ".htm", ".xml"],
escape_fn: escape_html,
};

let mut tera = Tera::new_uninitialized();
tera.register_tera_filters();
tera.register_tera_testers();
tera.register_tera_functions();
Expand Down
Loading