From 3983ac71d8911234342386aed897d6d2f9fef13f Mon Sep 17 00:00:00 2001 From: bnewbold Date: Mon, 26 Dec 2016 05:01:29 -0800 Subject: remove metadata.toml Grab name and decription from modelica source. Only keep around examples in .toml (so far unimplemented) --- examples/classic_gravitation/examples.toml | 12 ++++++++++++ examples/classic_gravitation/metadata.toml | 16 ---------------- examples/classic_gravitation/model.modelica | 1 + examples/hodgkin_huxley/model.modelica | 1 + examples/lotka_volterra/examples.toml | 11 +++++++++++ examples/lotka_volterra/metadata.toml | 15 --------------- examples/van_der_pol/examples.toml | 0 examples/van_der_pol/metadata.toml | 0 src/bin/mt-webface.rs | 5 ++--- src/lib.rs | 28 ---------------------------- tests/lib.rs | 14 -------------- 11 files changed, 27 insertions(+), 76 deletions(-) create mode 100644 examples/classic_gravitation/examples.toml delete mode 100644 examples/classic_gravitation/metadata.toml create mode 100644 examples/lotka_volterra/examples.toml delete mode 100644 examples/lotka_volterra/metadata.toml create mode 100644 examples/van_der_pol/examples.toml delete mode 100644 examples/van_der_pol/metadata.toml diff --git a/examples/classic_gravitation/examples.toml b/examples/classic_gravitation/examples.toml new file mode 100644 index 0000000..516b16c --- /dev/null +++ b/examples/classic_gravitation/examples.toml @@ -0,0 +1,12 @@ + +[examples] + + [examples.earth_surface] + r = 6.371e6 # radius of earth + m1 = 5.972e24 # mass of earth + + [examples.earth_moon] + r = 385000 # radius of earth + m1 = 5.972e24 # mass of earth + m2 = 7.348e22 # mass of moon + diff --git a/examples/classic_gravitation/metadata.toml b/examples/classic_gravitation/metadata.toml deleted file mode 100644 index 9f43ae7..0000000 --- a/examples/classic_gravitation/metadata.toml +++ /dev/null @@ -1,16 +0,0 @@ - -[model] -name-en = "Classic Gravitation" -description-en = "Newtonian" - -[examples] - - [examples.earth_surface] - r = 6.371e6 # radius of earth - m1 = 5.972e24 # mass of earth - - [examples.earth_moon] - r = 385000 # radius of earth - m1 = 5.972e24 # mass of earth - m2 = 7.348e22 # mass of moon - diff --git a/examples/classic_gravitation/model.modelica b/examples/classic_gravitation/model.modelica index e0f7b60..7d5d327 100644 --- a/examples/classic_gravitation/model.modelica +++ b/examples/classic_gravitation/model.modelica @@ -1,4 +1,5 @@ model ClassicGravitation + "Newtonian" parameter Real G=6.674e-11 "Gravitational Constant"; Real m1(unit="kilogram") "mass #1"; Real m2(unit="kilogram") "mass #2"; diff --git a/examples/hodgkin_huxley/model.modelica b/examples/hodgkin_huxley/model.modelica index 9153799..532bdac 100644 --- a/examples/hodgkin_huxley/model.modelica +++ b/examples/hodgkin_huxley/model.modelica @@ -1,4 +1,5 @@ model HodgkinHuxley + "Predator-Prey Model" parameter Real G_Na =120 "conductance"; parameter Real G_K =36 "conductance"; parameter Real G_lk =0.3 "conductance"; diff --git a/examples/lotka_volterra/examples.toml b/examples/lotka_volterra/examples.toml new file mode 100644 index 0000000..0f5fb85 --- /dev/null +++ b/examples/lotka_volterra/examples.toml @@ -0,0 +1,11 @@ + +[examples] + + [examples.mathworld] + x = 10 + y = 5 + alpha = 1.5 + beta = 1 + gamma = 1 + t = [0, 20] + diff --git a/examples/lotka_volterra/metadata.toml b/examples/lotka_volterra/metadata.toml deleted file mode 100644 index 9753537..0000000 --- a/examples/lotka_volterra/metadata.toml +++ /dev/null @@ -1,15 +0,0 @@ - -[model] -name-en = "Lotka–Volterra equations" -description-en = "Predator-Prey Model" - -[examples] - - [examples.mathworld] - x = 10 - y = 5 - alpha = 1.5 - beta = 1 - gamma = 1 - t = [0, 20] - diff --git a/examples/van_der_pol/examples.toml b/examples/van_der_pol/examples.toml new file mode 100644 index 0000000..e69de29 diff --git a/examples/van_der_pol/metadata.toml b/examples/van_der_pol/metadata.toml deleted file mode 100644 index e69de29..0000000 diff --git a/src/bin/mt-webface.rs b/src/bin/mt-webface.rs index b5b4fe0..3b280e2 100644 --- a/src/bin/mt-webface.rs +++ b/src/bin/mt-webface.rs @@ -44,9 +44,8 @@ fn model_view(r: &mut Request) -> PencilResult { Ok(me) => { let mut context = BTreeMap::new(); context.insert("model_slug".to_string(), model_slug.to_string()); - context.insert("model_name".to_string(), me.metadata.name_en); - context.insert("model_description".to_string(), me.metadata.description_en.unwrap_or("".to_string())); - //context.insert("metadata".to_string(), me.metadata); + context.insert("model_name".to_string(), me.ast.name.clone()); + context.insert("model_description".to_string(), me.ast.description.clone().unwrap_or("".to_string())); context.insert("markdown_html".to_string(), markdown::to_html(&me.markdown)); context.insert("markdown".to_string(), me.markdown); context.insert("modelica".to_string(), format!("{:?}", me.ast)); diff --git a/src/lib.rs b/src/lib.rs index 91c99ea..f93f7fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,12 +14,6 @@ use std::fs; use std::io::Read; use std::fs::File; -#[derive(Debug, PartialEq)] -pub struct ModelMetadata { - pub name_en: String, - pub description_en: Option, -} - #[derive(Debug, PartialEq)] pub enum ModelVarType { Independent, @@ -42,22 +36,9 @@ pub struct ModelVar { #[derive(Debug, PartialEq)] pub struct ModelEntry { pub ast: modelica_parser::ModelicaModel, - pub metadata: ModelMetadata, pub markdown: String, } -pub fn parse_metadata(raw: String) -> Result { - let root = toml::Parser::new(&raw).parse().unwrap(); - let model = root.get("model") - .expect("missing 'model' section") - .as_table() - .unwrap(); - Ok(ModelMetadata { - name_en: model.get("name-en").unwrap().as_str().unwrap().to_string(), - description_en: model.get("description-en").map(|x| x.as_str().unwrap().to_string()), - }) -} - pub fn load_model_entry(p: &Path) -> Result { debug!("Attempting to load model from: {:?}", p); @@ -69,14 +50,6 @@ pub fn load_model_entry(p: &Path) -> Result { try!(modelica_parser::parse_model(&s).map_err(|e| format!("{:?}", e))) }; - let metadata = { - let mut s = String::new(); - try!(File::open(p.join("metadata.toml")) - .and_then(|mut f| f.read_to_string(&mut s)) - .map_err(|e| e.to_string())); - parse_metadata(s).unwrap() - }; - let markdown = { let mut s = String::new(); try!(File::open(p.join("page.md")) @@ -87,7 +60,6 @@ pub fn load_model_entry(p: &Path) -> Result { Ok(ModelEntry { ast: ast, - metadata: metadata, markdown: markdown, }) } diff --git a/tests/lib.rs b/tests/lib.rs index de19f5b..8899e0b 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -8,20 +8,6 @@ use modelthing::*; use modelica_parser::*; -#[test] -fn test_parse_metadata() { - let raw = -r#" -[model] -name-en = "Bogus Dummy Model" -"#.to_string(); - assert_eq!(parse_metadata(raw).unwrap(), - ModelMetadata { - name_en: "Bogus Dummy Model".to_string(), - description_en: None, - }); -} - #[test] fn test_load_model_entry() { load_model_entry(Path::new("./examples/classic_gravitation/")).unwrap(); -- cgit v1.2.3