Skip to content

Fixed dead link on Tera reference#33

Closed
Arteneko wants to merge 3 commits intoKeats:masterfrom
Arteneko:master
Closed

Fixed dead link on Tera reference#33
Arteneko wants to merge 3 commits intoKeats:masterfrom
Arteneko:master

Conversation

@Arteneko
Copy link
Copy Markdown
Contributor

No description provided.

.filter_map(|e| e.ok());

// Register the `slug` filter
Tera::default().register_filter("slugify", |value, _| slugify(value));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not how you register it, this is dropping the Tera instance right away. Since the code uses Tera::one_off a few times, it's probably better to have a function to render a template that looks like

fn render_template(content, context) -> Result<String> {
  let mut tera = Tera::default();
  tera.register_filter("slugify", |value, _| slugify(value));
  tera.add_raw_template("one_off", content)?;
  let res = tera.render("one_off", &context).map_err(|err| new_error(ErrorKind::Tera { err, path: None }))?;
  Ok(res)
}

or something similar

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the insight.

I thought for a second that Tera::default() was referring to a static instance.

@Arteneko
Copy link
Copy Markdown
Contributor Author

Arteneko commented Jan 28, 2020

I fucked up the PR, I aimed to only fix the README.

I'll create a new PR with only the README's changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants