From 351a2e81fdc50a16d44efd25d1516de7afb08b11 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 4 Jan 2017 00:06:56 -0800 Subject: switch URL scheme to be based at /m/{namespace}/{model}/ --- src/bin/mt-webface.rs | 20 +++++++++++++++----- webface/templates/base.html | 2 +- webface/templates/model_list.html | 6 +++--- 3 files changed, 19 insertions(+), 9 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 = 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> = 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//", "model_list", model_list); app.register_template("model_view.html"); - app.get("/model//", "model", model_view); + app.get("/m///", "model_view", model_view); let bind = matches.opt_str("bind").unwrap_or("127.0.0.1:5000".to_string()); let bind_str: &str = &bind; diff --git a/webface/templates/base.html b/webface/templates/base.html index 8d77a5e..b427d3a 100644 --- a/webface/templates/base.html +++ b/webface/templates/base.html @@ -16,7 +16,7 @@ body { font-family: monospace; font-size: larger; line-height: 1.3; }

-examples index - +examples index - full readme - source code
diff --git a/webface/templates/model_list.html b/webface/templates/model_list.html index db11bdc..4c80315 100644 --- a/webface/templates/model_list.html +++ b/webface/templates/model_list.html @@ -1,9 +1,9 @@ {{# partial content}} -

Example Models

+

Models

-- cgit v1.2.3