Skip to content

Commit

Permalink
Merge pull request #102 from out-of-cheese-error/url_encode
Browse files Browse the repository at this point in the history
add url_encode helper
  • Loading branch information
Ninjani authored Feb 3, 2024
2 parents 5983646 + 43b1784 commit 1440b9d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tokio = { version = "1.20.1", features = ["macros"] }

# To extract the base URI
url = "2.2.2"
urlencoding = "2.1.3"

# CLI
clap = { version = "4.4.12", features = ["derive", "env"] }
Expand Down
2 changes: 2 additions & 0 deletions src/gooseberry/knowledge_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub(crate) fn format_date<E: AsRef<str>>(
}

handlebars_helper!(date_format: |format: str, date: Json| format_date(format, date).map_err(|e| RenderError::from_error("serde_json", e))?);
handlebars_helper!(url_encode: |s: str| {urlencoding::encode(s).to_string()});

pub(crate) struct Templates<'a> {
pub(crate) annotation_template: &'a str,
Expand All @@ -110,6 +111,7 @@ pub(crate) fn get_handlebars(templates: Templates) -> color_eyre::Result<Handleb
handlebars_misc_helpers::register(&mut hbs);
hbs.register_escape_fn(handlebars::no_escape);
hbs.register_helper("date_format", Box::new(date_format));
hbs.register_helper("url_encode", Box::new(url_encode));
hbs.register_template_string("annotation", templates.annotation_template)?;
hbs.register_template_string("page", templates.page_template)?;
hbs.register_template_string("index_link", templates.index_link_template)?;
Expand Down

0 comments on commit 1440b9d

Please sign in to comment.