From 664899436ce466b9eb68fd2c676e6c1fe6ec7378 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Tue, 12 Mar 2019 12:38:21 -0300 Subject: [PATCH] Paving the way to saving the content --- src/main.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 289e5b0..033caeb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,8 +74,20 @@ fn open_tag(current_state: State, tag: &str) -> State { } } -fn close_tag(current_state: State, _tag: &str) -> State { - current_state.remove_tag() +fn dump_resource(current_state: State) -> State { + let unnamed = String::from("content"); + Path::new("data") + .join(current_state.title.as_ref().unwrap()) + .join(current_state.filename.as_ref().unwrap_or(&unnamed)); + + current_state +} + +fn close_tag(current_state: State, tag: &str) -> State { + match tag { + "resource" => dump_resource(current_state), + _ => current_state + } } fn main() { @@ -109,7 +121,12 @@ fn main() { match state.tag { Some(CurrentTag::Title) => state.with_title(create_note_storage(&data)), Some(CurrentTag::ResourceData) => state.with_data( - data.into_bytes().iter().filter(|&x| *x != 13 && *x != 10).map(|&x| x).collect() + data + .into_bytes() + .iter() + .filter(|&x| *x != 13 && *x != 10) // remove new lines, it is base 64, after all + .map(|&x| x) + .collect() ), Some(CurrentTag::ResourceAttributesFilename) => state.with_filename(data), _ => state