-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathPublicLab.Formatter.js
57 lines (40 loc) · 1.58 KB
/
PublicLab.Formatter.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
51
52
53
54
55
56
57
/*
* Formatters package the post content for a specific
* application, like PublicLab.org or Drupal.
*/
var Class = require('resig-class');
module.exports = PublicLab.Formatter = Class.extend({
// eventually we could accept both a format and a URL
init: function() {
var _formatter = this;
// functions that accept standard <data> and output form data for known services
_formatter.schemas = {
"publiclab": function(data) {
var output = {};
output.title = data.title || null;
output.body = data.body || null;
// we can remove this from server req, since we're authenticated
output.authenticity_token = data.token || null;
// Whether note will be draft or not
output.draft = data.draft || false;
// Optional:
output.tags = data.tags || null; // comma delimited
output.has_main_image = data.has_main_image || null;
output.main_image = data.main_image || null; // id to associate with pre-uploaded image
output.node_images = data.node_images || null; // comma-separated image.ids, I think
// photo is probably actually a multipart, but we pre-upload anyways, so probably not necessary:
output.image = { };
output.image.photo = data.image || null;
return output;
}// ,
// "drupal": {
// "title": null,
// "body": null
// }
};
_formatter.convert = function(data, destination) {
// return formatted version of data
return _formatter.schemas[destination](data);
};
}
});