aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/mt-webface.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/bin/mt-webface.rs b/src/bin/mt-webface.rs
index 4cdc509..50179e1 100644
--- a/src/bin/mt-webface.rs
+++ b/src/bin/mt-webface.rs
@@ -34,19 +34,29 @@ fn readme(r: &mut Request) -> PencilResult {
}
fn model_list(r: &mut Request) -> PencilResult {
- let paths = modelthing::search_models(Path::new("examples"));
- let l: Vec<String> = paths.iter().map(|x| Path::new(x).strip_prefix("examples").unwrap().to_string_lossy().to_string()).collect();
+ let namespace = r.view_args.get("namespace").unwrap();
+ let paths = modelthing::search_models(Path::new(namespace));
+ let l: Vec<Vec<String>> = paths.iter()
+ .map(|x| vec![namespace.to_string(),
+ Path::new(x).strip_prefix(namespace)
+ .unwrap()
+ .to_string_lossy()
+ .to_string()
+ ])
+ .collect();
let mut context = BTreeMap::new();
context.insert("model_slug_list".to_string(), l);
return r.app.render_template("model_list.html", &context);
}
fn model_view(r: &mut Request) -> PencilResult {
+ let namespace = r.view_args.get("namespace").unwrap();
let model_slug = r.view_args.get("model_slug").unwrap();
- let model_path = Path::new("examples").join(model_slug);
+ let model_path = Path::new(namespace).join(model_slug);
match modelthing::load_model_entry(model_path.as_path()) {
Ok(me) => {
let mut context = BTreeMap::new();
+ context.insert("namespace".to_string(), namespace.to_string());
context.insert("model_slug".to_string(), model_slug.to_string());
context.insert("model_name".to_string(), me.ast.name.clone());
context.insert("model_description".to_string(), me.ast.description.clone().unwrap_or("".to_string()));
@@ -122,9 +132,9 @@ fn main() {
app.get("/", "home", home);
app.get("/readme/", "readme", readme);
app.register_template("model_list.html");
- app.get("/model_list/", "model_list", model_list);
+ app.get("/m/<namespace:string>/", "model_list", model_list);
app.register_template("model_view.html");
- app.get("/model/<model_slug:string>/", "model", model_view);
+ app.get("/m/<namespace:string>/<model_slug:string>/", "model_view", model_view);
let bind = matches.opt_str("bind").unwrap_or("127.0.0.1:5000".to_string());
let bind_str: &str = &bind;