diff options
-rw-r--r-- | src/bin/mt-webface.rs | 3 | ||||
-rw-r--r-- | src/repr_latex.rs | 40 | ||||
-rw-r--r-- | webface/templates/model_view.html | 8 |
3 files changed, 50 insertions, 1 deletions
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<String>; } +pub trait ReprVarsHTML { + fn repr_vars_html(&self) -> Result<String>; +} impl ReprLaTeX for ModelicaModel { fn repr_latex(&self) -> Result<String> { @@ -25,6 +28,43 @@ impl ReprLaTeX for ModelicaModel { } } +impl ReprVarsHTML for ModelicaModel { + + fn repr_vars_html(&self) -> Result<String> { + + let mut rows = vec![]; + for c in &self.components { + rows.push(format!(r#"<tr><td>\({name}\)</td> + <td>{prefix}</td> + <td>{description}</td> + <td>\({default}\)</td> + <td>{specifier}</td> + </tr>"#, + 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#"<table> + <tr><th>Variable</th> + <th>Type</th> + <th>Description</th> + <th>Value (default)</th> + <th>Datatype</th> + {rows} + </table>"#, + 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 @@ <style> .mfrac { font-size:0.8em; } .infoblock { margin-left: 0.25em; border-left: 4px solid #BBBBBB; } +#vars_table table { margin-top: 2em; margin-bottom: 2em; width: 100%; } +#vars_table td { text-align: center; } </style> {{/partial}} @@ -46,6 +48,12 @@ $${{ latex }}$$ </div> {{/if}} +{{# if vars_table }} +<div id="vars_table"> +{{{ vars_table}}} +</div> +{{/if}} + {{{ markdown_html }}} <br> |