handlebars_misc_helpers/
http_helpers.rs1#[cfg(feature = "http_attohttpc")]
2use attohttpc;
3use handlebars::{handlebars_helper, Handlebars};
4#[cfg(all(feature = "http_reqwest", not(feature = "http_attohttpc")))]
5use reqwest;
6
7#[cfg(feature = "http_attohttpc")]
8fn http_get_fct<T: AsRef<str>>(url: T) -> Result<String, attohttpc::Error> {
9 attohttpc::get(url.as_ref()).send()?.text()
10}
11
12#[cfg(all(feature = "http_reqwest", not(feature = "http_attohttpc")))]
13fn http_get_fct<T: AsRef<str>>(url: T) -> Result<String, reqwest::Error> {
14 reqwest::blocking::get(url.as_ref())?.text()
15}
16
17#[cfg(any(feature = "http_reqwest", feature = "http_attohttpc"))]
18pub fn register(handlebars: &mut Handlebars) {
19 {
20 handlebars_helper!(http_get: |v: str| http_get_fct(v).map_err(crate::to_nested_error)?);
21 handlebars.register_helper("http_get", Box::new(http_get))
22 }
23 {
24 handlebars_helper!(gitignore_io: |v: str| http_get_fct(format!("https://www.gitignore.io/api/{}", v)).map_err(crate::to_nested_error)?);
25 handlebars.register_helper("gitignore_io", Box::new(gitignore_io))
26 }
27}
28
29