Stackedit/public/res/providers/githubProvider.js

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
"utils",
"classes/Provider",
"settings",
"helpers/githubHelper"
2013-06-22 23:48:57 +00:00
], function(utils, Provider, settings, githubHelper) {
2013-04-14 13:24:29 +00:00
var githubProvider = new Provider("github", "GitHub");
githubProvider.publishPreferencesInputIds = [
"github-repo",
"github-branch"
];
2013-05-29 19:55:23 +00:00
githubProvider.getPublishLocationLink = function(attributes) {
var result = [
'https://github.com',
attributes.username,
attributes.repository,
'blob',
attributes.branch
];
return result.concat(attributes.path.split('/').map(encodeURIComponent)).join('/');
};
2013-05-29 19:55:23 +00:00
githubProvider.publish = function(publishAttributes, frontMatter, title, content, callback) {
var commitMsg = settings.commitMsg;
githubHelper.upload(publishAttributes.repository, publishAttributes.username, publishAttributes.branch, publishAttributes.path, content, commitMsg, function(err, username) {
publishAttributes.username = username;
callback(err);
});
};
githubProvider.newPublishAttributes = function(event) {
var publishAttributes = {};
publishAttributes.repository = utils.getInputTextValue("#input-publish-github-repo", event);
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];
}
return publishAttributes;
};
2013-05-29 19:55:23 +00:00
return githubProvider;
2013-04-14 13:24:29 +00:00
});