forked from emmetio/brackets-emmet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brackets-fs.js
50 lines (41 loc) · 1.2 KB
/
brackets-fs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
define(function(require, exports, module) {
var path = require('./path');
var emmetFile = require('emmet/plugin/file');
var FileSystem = brackets.getModule('filesystem/FileSystem');
emmetFile({
read: function(file, callback) {
var fd = FileSystem.getFileForPath(file);
if (!fd) {
return callback('File "' + path + '" does not exists.');
}
fd.read({encoding: 'utf8'}, callback);
},
readText: function(file, callback) {
return this.read(file, callback);
},
locateFile: function(editorFile, fileName) {
var dirname = editorFile, f;
fileName = fileName.replace(/^\/+/, '');
while (dirname && dirname !== path.dirname(dirname)) {
dirname = path.dirname(dirname);
f = path.join(dirname, fileName);
if (FileSystem.getFileForPath(f)) {
return f;
}
}
return '';
},
createPath: function(parent, fileName, callback) {
FileSystem.getFileForPath(parent).exists(function(err, exists) {
if (exists) {
parent = path.dirname(parent);
}
return callback(path.resolve(parent, fileName));
});
},
save: function(file, content) {
FileSystem.getFileForPath(file).write(content, {encoding: 'ascii'});
}
});
return emmetFile;
});