Skip to content

Commit d02c755

Browse files
committed
less verbose handlebars helpers
1 parent 2aa0eec commit d02c755

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/template_helpers.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type EH = fn(&JsonValue) -> anyhow::Result<JsonValue>;
1616
type HH = fn(&JsonValue, &JsonValue) -> JsonValue;
1717

1818
pub fn register_all_helpers(h: &mut Handlebars<'_>, config: &AppConfig) {
19+
let site_prefix = config.site_prefix.clone();
1920
register_helper(h, "stringify", stringify_helper as H);
2021
register_helper(h, "parse_json", parse_json_helper as EH);
2122
register_helper(h, "default", default_helper as HH);
@@ -39,10 +40,7 @@ pub fn register_all_helpers(h: &mut Handlebars<'_>, config: &AppConfig) {
3940
h.register_helper("array_contains", Box::new(array_contains));
4041

4142
// static_path helper: generate a path to a static file. Replaces sqpage.js by sqlpage.<hash>.js
42-
let static_path_helper = StaticPathHelper {
43-
site_prefix: config.site_prefix.clone(),
44-
};
45-
register_helper(h, "static_path", static_path_helper);
43+
register_helper(h, "static_path", StaticPathHelper(site_prefix));
4644

4745
// icon helper: generate an image with the specified icon
4846
h.register_helper("icon_img", Box::new(icon_img_helper));
@@ -133,9 +131,7 @@ fn to_array_helper(v: &JsonValue) -> JsonValue {
133131
.into()
134132
}
135133

136-
struct StaticPathHelper {
137-
site_prefix: String,
138-
}
134+
struct StaticPathHelper(String);
139135

140136
impl CanHelp for StaticPathHelper {
141137
fn call(&self, args: &[PathAndJson]) -> Result<JsonValue, String> {
@@ -153,7 +149,7 @@ impl CanHelp for StaticPathHelper {
153149
"tomselect.js" => static_filename!("tomselect.js"),
154150
other => return Err(format!("unknown static file: {other:?}")),
155151
};
156-
Ok(format!("{}{}", self.site_prefix, path).into())
152+
Ok(format!("{}{}", self.0, path).into())
157153
}
158154
}
159155

0 commit comments

Comments
 (0)