From 288ed7bf6c557723b658f9be5694e7a496e5d1f5 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sat, 28 Jan 2017 19:47:16 -0800 Subject: variable table (in HTML) --- src/bin/mt-webface.rs | 3 ++- src/repr_latex.rs | 40 +++++++++++++++++++++++++++++++++++++++ webface/templates/model_view.html | 8 ++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/bin/mt-webface.rs b/src/bin/mt-webface.rs index 59b0621..4d26d21 100644 --- a/src/bin/mt-webface.rs +++ b/src/bin/mt-webface.rs @@ -21,7 +21,7 @@ use pencil::method::{Get, Post}; use regex::Regex; use modelthing::transpile_scheme::TranspileScheme; use modelthing::transpile_js::{TranspileJS, TranspileJSODE}; -use modelthing::repr_latex::ReprLaTeX; +use modelthing::repr_latex::{ReprLaTeX, ReprVarsHTML}; /* This command doesn't use error_chain (or raise errors in general) because the @@ -86,6 +86,7 @@ fn model_view(r: &mut Request) -> PencilResult { context.insert("markdown".to_string(), me.markdown.clone()); context.insert("modelica".to_string(), format!("{:?}", me.ast)); context.insert("latex".to_string(), me.ast.repr_latex().unwrap()); + context.insert("vars_table".to_string(), me.ast.repr_vars_html().unwrap()); context.insert("editable".to_string(), if namespace == "sandbox" { "true".to_string() } else { "".to_string() }); context.insert("computable".to_string(), diff --git a/src/repr_latex.rs b/src/repr_latex.rs index 4c4e34c..b5426e8 100644 --- a/src/repr_latex.rs +++ b/src/repr_latex.rs @@ -8,6 +8,9 @@ pub trait ReprLaTeX { fn repr_latex(&self) -> Result; } +pub trait ReprVarsHTML { + fn repr_vars_html(&self) -> Result; +} impl ReprLaTeX for ModelicaModel { fn repr_latex(&self) -> Result { @@ -25,6 +28,43 @@ impl ReprLaTeX for ModelicaModel { } } +impl ReprVarsHTML for ModelicaModel { + + fn repr_vars_html(&self) -> Result { + + let mut rows = vec![]; + for c in &self.components { + rows.push(format!(r#"\({name}\) + {prefix} + {description} + \({default}\) + {specifier} + "#, + prefix = if let Some(ref cp) = c.prefix { + format!("{:?}", cp) } + else { "free".to_string() }, + specifier = c.specifier, + name = try!(Expr::Ident(c.name.clone()).repr_latex()), + default = if let Some(ref v) = c.value { + try!(v.repr_latex()) } + else { "".to_string() }, + description = if let Some(ref d) = c.description { + d.clone() } + else { "".to_string() })); + } + let rows = rows.join("\n"); + Ok(format!(r#" + + + + + + {rows} +
VariableTypeDescriptionValue (default)Datatype
"#, + rows = rows)) + } +} + fn is_latexy_ident(s: &str) -> bool { let latexy_idents = [ "alpha", "Alpha", "beta", "gamma", "Gamma", "delta", "Delta", diff --git a/webface/templates/model_view.html b/webface/templates/model_view.html index 14ed5ef..878edaa 100644 --- a/webface/templates/model_view.html +++ b/webface/templates/model_view.html @@ -12,6 +12,8 @@ {{/partial}} @@ -46,6 +48,12 @@ $${{ latex }}$$ {{/if}} +{{# if vars_table }} +
+{{{ vars_table}}} +
+{{/if}} + {{{ markdown_html }}}
-- cgit v1.2.3