diff --git a/examples/sbadmin2/templates/index.json b/examples/sbadmin2/templates/index.json
new file mode 100644
index 0000000..da03d27
--- /dev/null
+++ b/examples/sbadmin2/templates/index.json
@@ -0,0 +1,7 @@
+{
+ "products": [
+ "Apple",
+ "Pear",
+ "Banana"
+ ]
+}
\ No newline at end of file
diff --git a/examples/sbadmin2/templates/topbar.html b/examples/sbadmin2/templates/topbar.html
index 0eaf942..2016ea7 100644
--- a/examples/sbadmin2/templates/topbar.html
+++ b/examples/sbadmin2/templates/topbar.html
@@ -96,6 +96,12 @@
+ {{loop.index}}. {{product}}
+
+ {% endfor %}
+
tmpl.render(&file, &ctx).map_err(|e| {
+ error::ErrorInternalServerError(format!(
+ "Template error: {} with context: {:?}",
+ e, &ctx
+ ))
+ })?,
+ Err(e) => {
+ error!("{}",e);
+ format!("Couldn't read context json: {}", e)
+ }
+ }
} else {
tmpl.render("404.html", &tera::Context::new())
.map_err(|_| error::ErrorInternalServerError("Template error"))?
@@ -69,32 +71,33 @@ fn main() -> std::io::Result<()> {
.service(fs::Files::new("/js", "js").show_files_listing())
.service(fs::Files::new("/vendor", "vendor").show_files_listing())
.service(fs::Files::new("/img", "img").show_files_listing())
+ .service(fs::Files::new("/fonts", "fonts").show_files_listing())
.service(web::resource("{any:.*}").route(web::get().to(templates)))
})
.bind("127.0.0.1:8080")?
.run()
}
-fn get_context(file: &str) -> Result, Error> {
+fn get_context(file: &str) -> Result {
let mut fl = concat!(env!("CARGO_MANIFEST_DIR"), "/templates/").to_owned();
fl.push_str(file);
let ctx_file = if let Some(file_ext) = std::path::Path::new(&fl)
.extension()
.and_then(std::ffi::OsStr::to_str)
{
- fl.replace(file_ext, "ctx")
+ fl.replace(file_ext, "json")
} else {
let mut s = fl.to_owned();
- s.push_str(".ctx");
+ s.push_str(".json");
s
};
if std::path::Path::new(&ctx_file).exists() {
let file = std::fs::File::open(ctx_file)?;
let reader = std::io::BufReader::new(file);
- let json: HashMap = serde_json::from_reader(reader)?;
+ let json: serde_json::Value = serde_json::from_reader(reader)?;
return Ok(json);
}
- Ok(HashMap::new())
+ Ok(serde_json::Value::Null)
}
/// favicon handler
diff --git a/tera_design_0-1-1.zip b/tera_design_0-1-1.zip
deleted file mode 100644
index e135e5b..0000000
Binary files a/tera_design_0-1-1.zip and /dev/null differ