Browse code

Exporting is working

Julio Biason authored on 12/03/2019 13:50:50
Showing 2 changed files

... ...
@@ -1,4 +1,5 @@
1 1
 /target
2 2
 **/*.rs.bk
3
+/data
3 4
 
4 5
 *.sw?
... ...
@@ -50,10 +50,15 @@ impl State {
50 50
                ..self }
51 51
     }
52 52
 
53
-    // pub fn remove_tag(self) -> Self {
54
-    //     Self { tag: None,
55
-    //            ..self }
56
-    // }
53
+    pub fn remove_tag(self) -> Self {
54
+        Self { tag: None,
55
+               ..self }
56
+    }
57
+
58
+    pub fn remove_data(self) -> Self {
59
+        Self { data: Vec::new(),
60
+               ..self }
61
+    }
57 62
 }
58 63
 
59 64
 fn create_note_storage(title: &str) -> String {
... ...
@@ -75,23 +80,26 @@ fn open_tag(current_state: State, tag: &str) -> State {
75 80
     }
76 81
 }
77 82
 
78
-fn dump_resource(current_state: State) -> State {
83
+fn dump_resource(current_state: &State) -> () {
79 84
     let unnamed = String::from("content");
80 85
     let content_storage = Path::new("data")
81 86
         .join(current_state.title.as_ref().unwrap())
82 87
         .join(current_state.filename.as_ref().unwrap_or(&unnamed));
83 88
     let content = base64::decode(&current_state.data).unwrap();
84 89
 
90
+    println!("Will save {:?}", content_storage);
91
+
85 92
     let mut target = File::create(content_storage).unwrap();
86 93
     target.write_all(&content).unwrap();
87
-
88
-    current_state
89 94
 }
90 95
 
91 96
 fn close_tag(current_state: State, tag: &str) -> State {
92 97
     match tag {
93
-        "resource" => dump_resource(current_state),
94
-        _ => current_state
98
+        "resource" => {
99
+            dump_resource(&current_state);
100
+            current_state.remove_data()
101
+        },
102
+        _ => current_state.remove_tag()
95 103
     }
96 104
 }
97 105