Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Changes write to export. #4

Closed
wants to merge 1 commit into from

2 participants

Jerad Bitner Veselin
Jerad Bitner

Exports after every save.
Export uses path and defaults to /data/todo.txt

Jerad Bitner Changes write to export.
Exports after every save.
Export uses path and defaults to /data/todo.txt
731111e
Jerad Bitner

I'll see if i can throw in some tests now.

Veselin
Owner

Thanks, man. I really appreciate it.

Jerad Bitner

So, I'll admit, I'm struggling here with the test. I can't seem to find a sine command for testing file creation. Can you give me a little direction on what exactly you think this should test? I've not gotten very far :( https://gist.github.com/1747985

Veselin
Owner

https://github.com/vesln/box/blob/master/test/storage.test.js#L85 This test is pretty similar. I hope it will give you some directions.

Jerad Bitner

Thanks that helped, and I'm close I think.

https://gist.github.com/1747985

However I'm still getting an error about the file not existing:
error

It seems I need to able to add in the file path as the argument to the .stub() but I'm not quite sure how. I tried using stub.withArgs() with no success.

Any more pointers?

Veselin vesln closed this January 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 04, 2012
Jerad Bitner Changes write to export.
Exports after every save.
Export uses path and defaults to /data/todo.txt
731111e
This page is out of date. Refresh to see the latest.
2  lib/app.js
@@ -33,7 +33,7 @@ app.use(flatiron.plugins.cli, {
33 33
     '       todo undo 1       - Marks #1 item as not done yet.',
34 34
     '       todo clear        - Clears the whole list.',
35 35
     '       todo version      - Lib version.',
36  
-    '       todo write        - Write items to file.',
  36
+    '       todo export       - Export items to file.',
37 37
     '',
38 38
     'Author: Veselin Todorov <hi@vesln.com>'
39 39
   ]
2  lib/cli.js
@@ -38,7 +38,7 @@ app.cmd(/undo (.+)/, commands.undo);
38 38
 app.cmd(/rm (.+)/, commands.delete);
39 39
 
40 40
 // Writes todo to file.
41  
-app.cmd(/write (.+)/, commands.write);
  41
+app.cmd(/export (.+)/, commands.export);
42 42
 
43 43
 // Adds new todo item.
44 44
 app.cmd(/(.+)/, commands.add);
15  lib/commands.js
@@ -43,7 +43,8 @@ var formatter = require('./formatter');
43 43
 /**
44 44
  * File writing.
45 45
  */
46  
-var fs = require('fs');
  46
+var fs = require('fs'),
  47
+    path = require('path');
47 48
 
48 49
 /**
49 50
  * Prints current version.
@@ -112,6 +113,7 @@ commands.toggle = function(num, state) {
112 113
     storage.set('items', items, function() {
113 114
       storage.save(function(err) {
114 115
         if (err) throw err;
  116
+        commands.export();
115 117
       });
116 118
     });
117 119
   });
@@ -131,6 +133,7 @@ commands.delete = function(num) {
131 133
     storage.set('items', items, function() {
132 134
       storage.save(function(err) {
133 135
         if (err) throw err;
  136
+        commands.export();
134 137
       });
135 138
     });
136 139
   });
@@ -146,6 +149,7 @@ commands.clear = function(num) {
146 149
   storage.set('items', [], function(err, items) {
147 150
     storage.save(function(err) {
148 151
       if (err) throw err;
  152
+      commands.export();
149 153
     });
150 154
   });
151 155
 };
@@ -163,6 +167,7 @@ commands.add = function(item) {
163 167
     storage.set('items', items, function(err) {
164 168
       storage.save(function(err) {
165 169
         if (err) throw err;
  170
+        commands.export();
166 171
       });
167 172
     });
168 173
   });
@@ -174,10 +179,10 @@ commands.add = function(item) {
174 179
  * @param {String} File location/name
175 180
  * @api public
176 181
  */
177  
-commands.write = function(filename) {
  182
+commands.export = function(filename) {
178 183
   var data = '';
179 184
   if (!filename) {
180  
-    var filename = "~/todo.txt";
  185
+    var filename = path.join(__dirname, '..', 'data', 'todo.txt');
181 186
   }
182 187
   var out = [];
183 188
   storage.get('items', function(err, items) {
@@ -189,12 +194,10 @@ commands.write = function(filename) {
189 194
 
190 195
     out.push('') && out.unshift('');
191 196
     out.map(function(line) {
192  
-      console.log(line);
193 197
       data += line +"\n";
194 198
     });
195 199
     fs.writeFile(filename, data, 'utf8', function(err, written) {
196  
-      if (err) return console.log(err);
197  
-
  200
+      if (err) throw err;
198 201
     });
199 202
   });
200 203
 };
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.