Stackedit/public/res/providers/githubProvider.js

36 lines
1.4 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
"utils",
2013-06-22 23:48:57 +00:00
"classes/Provider",
2013-05-27 19:45:33 +00:00
"settings",
2013-06-10 21:22:32 +00:00
"helpers/githubHelper"
2013-06-22 23:48:57 +00:00
], function(utils, Provider, settings, githubHelper) {
2013-04-14 13:24:29 +00:00
2013-06-22 23:48:57 +00:00
var githubProvider = new Provider("github", "GitHub");
githubProvider.publishPreferencesInputIds = [
2014-07-22 18:08:19 +00:00
"github-repo",
2013-06-22 23:48:57 +00:00
"github-branch"
];
2013-05-29 19:55:23 +00:00
2013-10-06 14:34:40 +00:00
githubProvider.publish = function(publishAttributes, frontMatter, title, content, callback) {
2013-05-29 19:55:23 +00:00
var commitMsg = settings.commitMsg;
2013-06-27 23:10:04 +00:00
githubHelper.upload(publishAttributes.repository, publishAttributes.username, publishAttributes.branch, publishAttributes.path, content, commitMsg, callback);
2013-05-29 19:55:23 +00:00
};
githubProvider.newPublishAttributes = function(event) {
var publishAttributes = {};
2014-07-22 11:42:21 +00:00
publishAttributes.repository = utils.getInputTextValue("#input-publish-github-repo", event);
2013-05-29 19:55:23 +00:00
publishAttributes.branch = utils.getInputTextValue("#input-publish-github-branch", event);
publishAttributes.path = utils.getInputTextValue("#input-publish-file-path", event);
if(event.isPropagationStopped()) {
return undefined;
}
2014-07-22 11:42:21 +00:00
var parsedRepository = publishAttributes.repository.match(/[\/:]?([^\/:]+)\/([^\/]+?)(?:\.git)?$/);
if(parsedRepository) {
publishAttributes.repository = parsedRepository[2];
publishAttributes.username = parsedRepository[1];
}
2013-05-29 19:55:23 +00:00
return publishAttributes;
};
return githubProvider;
2013-04-14 13:24:29 +00:00
});