-
Notifications
You must be signed in to change notification settings - Fork 21
/
yaml.js
33 lines (27 loc) · 981 Bytes
/
yaml.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
'use strict';
angular.module('sw.plugin.yaml', ['sw.plugins'])
.factory('yaml', function ($q, $window) {
return {
execute: function (options) {
var deferred = $q.defer();
options.transformResponse = function (data, headersGetter) {
try {
return angular.fromJson(data);
} catch (ign) {
try {
var obj = $window.jsyaml.safeLoad(data);
headersGetter()['content-type'] = 'application/json';
return obj;
} catch (ign) {
return data;
}
}
};
deferred.resolve();
return deferred.promise;
}
};
})
.run(function (plugins, yaml) {
plugins.add(plugins.BEFORE_LOAD, yaml);
});