Browse code

Paving the way to saving the content

Julio Biason authored on 12/03/2019 08:38:21
Showing 1 changed files

... ...
@@ -74,8 +74,20 @@ fn open_tag(current_state: State, tag: &str) -> State {
74 74
     }
75 75
 }
76 76
 
77
-fn close_tag(current_state: State, _tag: &str) -> State {
78
-    current_state.remove_tag()
77
+fn dump_resource(current_state: State) -> State {
78
+    let unnamed = String::from("content");
79
+    Path::new("data")
80
+        .join(current_state.title.as_ref().unwrap())
81
+        .join(current_state.filename.as_ref().unwrap_or(&unnamed));
82
+
83
+    current_state
84
+}
85
+
86
+fn close_tag(current_state: State, tag: &str) -> State {
87
+    match tag {
88
+        "resource" => dump_resource(current_state),
89
+        _ => current_state
90
+    }
79 91
 }
80 92
 
81 93
 fn main() {
... ...
@@ -109,7 +121,12 @@ fn main() {
109 121
                 match state.tag {
110 122
                     Some(CurrentTag::Title) => state.with_title(create_note_storage(&data)),
111 123
                     Some(CurrentTag::ResourceData) => state.with_data(
112
-                        data.into_bytes().iter().filter(|&x| *x != 13 && *x != 10).map(|&x| x).collect()
124
+                        data
125
+                            .into_bytes()
126
+                            .iter()
127
+                            .filter(|&x| *x != 13 && *x != 10)  // remove new lines, it is base 64, after all
128
+                            .map(|&x| x)
129
+                            .collect()
113 130
                     ),
114 131
                     Some(CurrentTag::ResourceAttributesFilename) => state.with_filename(data),
115 132
                     _ => state