aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-12-26 05:01:29 -0800
committerbnewbold <bnewbold@robocracy.org>2016-12-26 05:01:31 -0800
commit3983ac71d8911234342386aed897d6d2f9fef13f (patch)
tree3646646feddeb5fbc5ce8b3176e2a7bae9753f34 /src
parentc12c61cb0f34df3421b9e967e74c0603f9e44a0f (diff)
downloadmodelthing-3983ac71d8911234342386aed897d6d2f9fef13f.tar.gz
modelthing-3983ac71d8911234342386aed897d6d2f9fef13f.zip
remove metadata.toml
Grab name and decription from modelica source. Only keep around examples in .toml (so far unimplemented)
Diffstat (limited to 'src')
-rw-r--r--src/bin/mt-webface.rs5
-rw-r--r--src/lib.rs28
2 files changed, 2 insertions, 31 deletions
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
@@ -15,12 +15,6 @@ use std::io::Read;
use std::fs::File;
#[derive(Debug, PartialEq)]
-pub struct ModelMetadata {
- pub name_en: String,
- pub description_en: Option<String>,
-}
-
-#[derive(Debug, PartialEq)]
pub enum ModelVarType {
Independent,
Dependent,
@@ -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<ModelMetadata, String> {
- 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<ModelEntry, String> {
debug!("Attempting to load model from: {:?}", p);
@@ -69,14 +50,6 @@ pub fn load_model_entry(p: &Path) -> Result<ModelEntry, String> {
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<ModelEntry, String> {
Ok(ModelEntry {
ast: ast,
- metadata: metadata,
markdown: markdown,
})
}