From c030f0a151fd8a9f02657ea9c157ad0b25e2249e Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Tue, 12 Mar 2019 17:50:50 -0300 Subject: [PATCH] Exporting is working --- .gitignore | 1 + src/main.rs | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index b974e59..3e40ebb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target **/*.rs.bk +/data *.sw? diff --git a/src/main.rs b/src/main.rs index f566969..adea96b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,10 +50,15 @@ impl State { ..self } } - // pub fn remove_tag(self) -> Self { - // Self { tag: None, - // ..self } - // } + pub fn remove_tag(self) -> Self { + Self { tag: None, + ..self } + } + + pub fn remove_data(self) -> Self { + Self { data: Vec::new(), + ..self } + } } fn create_note_storage(title: &str) -> String { @@ -75,23 +80,26 @@ fn open_tag(current_state: State, tag: &str) -> State { } } -fn dump_resource(current_state: State) -> State { +fn dump_resource(current_state: &State) -> () { let unnamed = String::from("content"); let content_storage = Path::new("data") .join(current_state.title.as_ref().unwrap()) .join(current_state.filename.as_ref().unwrap_or(&unnamed)); let content = base64::decode(¤t_state.data).unwrap(); + println!("Will save {:?}", content_storage); + let mut target = File::create(content_storage).unwrap(); target.write_all(&content).unwrap(); - - current_state } fn close_tag(current_state: State, tag: &str) -> State { match tag { - "resource" => dump_resource(current_state), - _ => current_state + "resource" => { + dump_resource(¤t_state); + current_state.remove_data() + }, + _ => current_state.remove_tag() } }