diff options
author | bnewbold <bnewbold@robocracy.org> | 2017-01-04 00:06:56 -0800 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2017-01-04 00:06:56 -0800 |
commit | 351a2e81fdc50a16d44efd25d1516de7afb08b11 (patch) | |
tree | c7120426a550026ac7c7c1ee540bad06f342ffeb /src | |
parent | 4e2937fc614538fd73363a41667c9472fb6ff5f3 (diff) | |
download | modelthing-351a2e81fdc50a16d44efd25d1516de7afb08b11.tar.gz modelthing-351a2e81fdc50a16d44efd25d1516de7afb08b11.zip |
switch URL scheme to be based at /m/{namespace}/{model}/
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/mt-webface.rs | 20 |
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; |