aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/mt-webface.rs26
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);