Skip to content

Commit 7b66c90

Browse files
committed
fix icons in tables
1 parent 03b0885 commit 7b66c90

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

sqlpage/templates/table.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
{{{markdown this}}}
3636
{{~else~}}
3737
{{~#if (array_contains ../../icon @key)~}}
38-
{{~icon_img icon~}}
38+
{{~icon_img this~}}
3939
{{~else~}}
4040
{{this}}
4141
{{~/if~}}

src/templates.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use crate::file_cache::AsyncFromStrWithState;
22
use crate::utils::static_filename;
33
use crate::{AppState, FileCache, TEMPLATES_DIR};
44
use async_trait::async_trait;
5-
use handlebars::RenderErrorReason;
65
use handlebars::{
76
handlebars_helper, template::TemplateElement, Context, Handlebars, JsonValue, RenderError,
87
Renderable, Template,
98
};
9+
use handlebars::{PathAndJson, RenderErrorReason};
1010
use include_dir::{include_dir, Dir};
1111
use std::path::PathBuf;
1212
use std::sync::Arc;
@@ -160,16 +160,22 @@ fn icon_img_helper<'reg, 'rc>(
160160
_rc: &mut handlebars::RenderContext<'reg, 'rc>,
161161
writer: &mut dyn handlebars::Output,
162162
) -> handlebars::HelperResult {
163-
let name = helper
164-
.params()
165-
.get(0)
166-
.and_then(|v| v.value().as_str())
167-
.ok_or(RenderErrorReason::InvalidParamType("str"))?;
168-
let size = helper
169-
.params()
170-
.get(1)
171-
.and_then(|v| v.value().as_u64())
172-
.unwrap_or(24);
163+
let null = handlebars::JsonValue::Null;
164+
let params = [0, 1].map(|i| {
165+
helper
166+
.params()
167+
.get(i)
168+
.map(PathAndJson::value)
169+
.unwrap_or(&null)
170+
});
171+
let err_fmt = || {
172+
RenderErrorReason::Other(format!(
173+
"{{icon_img str int}}: invalid parameters {:?}",
174+
params
175+
))
176+
};
177+
let name = params[0].as_str().ok_or_else(err_fmt)?;
178+
let size = params[1].as_u64().unwrap_or(24);
173179
write!(
174180
writer,
175181
"<svg width={size} height={size}><use href=\"/{}#tabler-{name}\" /></svg>",

0 commit comments

Comments
 (0)