diff options
author | bnewbold <bnewbold@robocracy.org> | 2017-01-14 14:33:13 -0800 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2017-01-14 14:33:13 -0800 |
commit | f8b7d9d7e936bb53db3f978b54592b7af791d1ec (patch) | |
tree | 7716380973af5301701f171bd844909ee84bacda /src/bin | |
parent | ecc4f3ef8a23e3d4143954fdccc5a28a83f9039f (diff) | |
download | modelthing-f8b7d9d7e936bb53db3f978b54592b7af791d1ec.tar.gz modelthing-f8b7d9d7e936bb53db3f978b54592b7af791d1ec.zip |
add repr to webface
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/mt-webface.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/bin/mt-webface.rs b/src/bin/mt-webface.rs index 96bc456..5361a73 100644 --- a/src/bin/mt-webface.rs +++ b/src/bin/mt-webface.rs @@ -19,6 +19,8 @@ use pencil::{Request, PencilResult, Response, HTTPError, PencilError}; use pencil::{redirect, abort}; use pencil::method::{Get, Post}; use regex::Regex; +use modelthing::transpile_scheme::TranspileScheme; +use modelthing::transpile_js::TranspileJS; /* This command doesn't use error_chain (or raise errors in general) because the @@ -90,6 +92,29 @@ fn model_view(r: &mut Request) -> PencilResult { } } +fn model_repr(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(namespace).join(model_slug); + let format = r.url + .query_pairs() + .filter(|x| x.0 == "format") + .map(|(_,v)| v.into_owned()) + .nth(0) + .unwrap_or("".to_string()); + let format: &str = &format; + match modelthing::load_model_entry(model_path.as_path()) { + Ok(me) => { + match format { + "scheme" => Ok(Response::from(me.ast.repr_scheme().unwrap())), + "javascript" => Ok(Response::from(me.ast.repr_js().unwrap())), + _ => abort(403), + } + }, + Err(_) => Err(PencilError::PenHTTPError(pencil::HTTPError::NotFound)), + } +} + // Sends the modelica file fn model_raw(r: &mut Request) -> PencilResult { let namespace = r.view_args.get("namespace").unwrap(); @@ -305,6 +330,7 @@ fn main() { app.register_template("model_view.html"); app.get("/m/<namespace:string>/<model_slug:string>/", "model_view", model_view); app.get("/m/<namespace:string>/<model_slug:string>/raw/", "model_raw", model_raw); + app.get("/m/<namespace:string>/<model_slug:string>/repr/", "model_repr", model_repr); app.get("/m/<namespace:string>/<model_slug:string>/markdown/", "model_markdown", model_markdown); app.register_template("model_create.html"); app.route("/create/", &[Get, Post], "model_create", model_create); |