2013-05-27 19:45:33 +00:00
|
|
|
define([
|
2013-10-06 14:34:40 +00:00
|
|
|
"underscore",
|
2013-10-27 20:27:39 +00:00
|
|
|
"settings",
|
2013-05-27 19:45:33 +00:00
|
|
|
"utils",
|
2013-06-22 23:48:57 +00:00
|
|
|
"classes/Provider",
|
2013-06-10 21:22:32 +00:00
|
|
|
"helpers/tumblrHelper"
|
2013-10-27 20:27:39 +00:00
|
|
|
], function(_, settings, utils, Provider, tumblrHelper) {
|
2013-04-28 22:33:17 +00:00
|
|
|
|
2013-06-22 23:48:57 +00:00
|
|
|
var tumblrProvider = new Provider("tumblr", "Tumblr");
|
|
|
|
tumblrProvider.publishPreferencesInputIds = [
|
|
|
|
"tumblr-hostname"
|
|
|
|
];
|
2013-05-29 19:55:23 +00:00
|
|
|
|
2013-10-06 14:34:40 +00:00
|
|
|
tumblrProvider.publish = function(publishAttributes, frontMatter, title, content, callback) {
|
|
|
|
var labelList = publishAttributes.tags || [];
|
|
|
|
if(frontMatter) {
|
|
|
|
frontMatter.tags !== undefined && (labelList = frontMatter.tags);
|
|
|
|
}
|
|
|
|
_.isString(labelList) && (labelList = _.compact(labelList.split(/[\s,]/)));
|
2013-10-27 20:27:39 +00:00
|
|
|
|
|
|
|
// Deduce format from publishAttributes/template
|
|
|
|
var format = (function() {
|
|
|
|
if(publishAttributes.format == 'html') {
|
|
|
|
return 'html';
|
|
|
|
}
|
|
|
|
if(publishAttributes.format == 'template') {
|
|
|
|
var template = publishAttributes.customTmpl || settings.template;
|
|
|
|
if(template.indexOf("documentHTML") !== -1) {
|
|
|
|
return 'html';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 'markdown';
|
|
|
|
})();
|
|
|
|
|
2013-12-08 18:05:49 +00:00
|
|
|
var state = (frontMatter && frontMatter.published === false) ? 'draft' : 'published';
|
|
|
|
var date = frontMatter && frontMatter.date;
|
|
|
|
tumblrHelper.upload(publishAttributes.blogHostname, publishAttributes.postId, labelList.join(','), format, state, date, title, content, function(error, postId) {
|
2013-05-29 19:55:23 +00:00
|
|
|
if(error) {
|
|
|
|
callback(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
publishAttributes.postId = postId;
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
tumblrProvider.newPublishAttributes = function(event) {
|
|
|
|
var publishAttributes = {};
|
|
|
|
publishAttributes.blogHostname = utils.getInputTextValue("#input-publish-tumblr-hostname", event, /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/);
|
|
|
|
publishAttributes.postId = utils.getInputTextValue("#input-publish-postid");
|
|
|
|
if(event.isPropagationStopped()) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return publishAttributes;
|
|
|
|
};
|
|
|
|
|
|
|
|
return tumblrProvider;
|
2013-04-28 22:33:17 +00:00
|
|
|
});
|