aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2017-01-04 00:06:56 -0800
committerbnewbold <bnewbold@robocracy.org>2017-01-04 00:06:56 -0800
commit351a2e81fdc50a16d44efd25d1516de7afb08b11 (patch)
treec7120426a550026ac7c7c1ee540bad06f342ffeb
parent4e2937fc614538fd73363a41667c9472fb6ff5f3 (diff)
downloadmodelthing-351a2e81fdc50a16d44efd25d1516de7afb08b11.tar.gz
modelthing-351a2e81fdc50a16d44efd25d1516de7afb08b11.zip
switch URL scheme to be based at /m/{namespace}/{model}/
-rw-r--r--src/bin/mt-webface.rs20
-rw-r--r--webface/templates/base.html2
-rw-r--r--webface/templates/model_list.html6
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<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;
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; }
<br><br>
<center>
-<a href="/model_list/">examples index</a> -
+<a href="/m/examples/">examples index</a> -
<a href="/readme/">full readme</a> -
<a href="https://git.bnewbold.net/modelthing">source code</a>
</center>
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}}
-<h1>Example Models</h1>
+<h1>Models</h1>
<ul>
-{{#each model_slug_list slug}}
-<li><a href="/model/{{this}}/">{{ this }}</a>
+{{#each model_slug_list }}
+<li><a href="/m/{{ this[0] }}/{{ this[1] }}/">{{ this[1] }}</a>
{{/each}}
</ul>