diff options
-rw-r--r-- | src/bin/mt-webface.rs | 26 | ||||
-rw-r--r-- | webface/templates/model_view.html | 3 |
2 files changed, 27 insertions, 2 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); diff --git a/webface/templates/model_view.html b/webface/templates/model_view.html index 6062f33..4218f11 100644 --- a/webface/templates/model_view.html +++ b/webface/templates/model_view.html @@ -10,8 +10,7 @@ <a href="markdown/">markdown</a> - <a href="raw/">modelica</a> - <a href="repr/?format=scheme">scheme</a> - -<a href="repr/?format=javascript">javascript</a> - -<a href="repr/?format=latex">latex</a> +<a href="repr/?format=javascript">javascript</a> </span> <p><i style="color: #222222;">{{ model_description }}</i> |