Added Gist provider

This commit is contained in:
benweet 2013-04-30 00:19:54 +01:00
parent bd7b5a3b5e
commit 4c976fa77e
11 changed files with 164 additions and 54 deletions

View File

@ -1 +1 @@
CACHE MANIFEST # v18 CACHE: index.html css/main-min.css js/main-min.js js/require.js img/ajax-loader.gif img/glyphicons-halflings.png img/glyphicons-halflings-white.png img/icons.png img/stackedit-32.ico img/stackedit-promo.png NETWORK: *
CACHE MANIFEST # v19 CACHE: index.html css/main-min.css js/main-min.js js/require.js img/ajax-loader.gif img/glyphicons-halflings.png img/glyphicons-halflings-white.png img/icons.png img/stackedit-32.ico img/stackedit-promo.png NETWORK: *

6
css/main-min.css vendored
View File

@ -5541,7 +5541,8 @@ hr {
height: 16px;
background-position: -37px 0;
}
.icon-github {
.icon-github,
.icon-gist {
background-image: url("../img/icons.png") !important;
width: 16px;
height: 16px;
@ -5613,7 +5614,8 @@ hr {
z-index: 1050 !important;
}
#modal-settings textarea {
height: 180px;
height: 80px;
max-width: 206px;
}
.tooltip-inner {
text-align: left;

View File

@ -246,7 +246,8 @@ hr {
background-position: -37px 0;
}
.icon-github {
.icon-github,
.icon-gist {
background-image: url("../img/icons.png") !important;
width: 16px;
height: 16px;

View File

@ -14,7 +14,7 @@
var code = getParameter("code");
if (client_id) {
window.location.href = "https://github.com/login/oauth/authorize?client_id="
+ client_id + "&scope=repo";
+ client_id + "&scope=repo,gist";
} else {
if (code) {
localStorage["githubCode"] = code;

View File

@ -88,17 +88,7 @@
<li class="divider"></li>
<li class="dropdown-submenu"><a href="#"><i
class="icon-share"></i> Publish on</a>
<ul class="dropdown-menu">
<li><a href="#" class="action-publish-blogger"><i
class="icon-blogger"></i> Blogger</a></li>
<li><a href="#" class="action-publish-dropbox"><i
class="icon-dropbox"></i> Dropbox</a></li>
<li><a href="#" class="action-publish-github"><i
class="icon-github"></i> GitHub</a></li>
<li><a href="#" class="action-publish-gdrive"><i
class="icon-gdrive"></i> Google Drive</a></li>
<li><a href="#" class="action-publish-tumblr"><i
class="icon-tumblr"></i> Tumblr</a></li>
<ul id="publish-menu" class="dropdown-menu">
</ul></li>
<li><a href="#" data-toggle="modal"
data-target="#modal-manage-publish" class="action-reset-input"><i
@ -176,8 +166,10 @@
<div class="modal-body">
<p>Are you sure you want to remove "<span class="file-title"></span>"?
</p>
<blockquote class="muted"><b>NOTE:</b> This will not remove the file on
synchronized locations.</blockquote>
<blockquote class="muted">
<b>NOTE:</b> This will not remove the file on synchronized
locations.
</blockquote>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Cancel</a> <a href="#"
@ -194,8 +186,10 @@
<div class="modal-body">
<p>This will upload the current document into your Google Drive
root folder and keep it synchronized.</p>
<blockquote class="muted"><b>NOTE:</b> You can move or rename the file
afterwards within Google Drive.</blockquote>
<blockquote class="muted">
<b>NOTE:</b> You can move or rename the file afterwards within
Google Drive.
</blockquote>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Cancel</a> <a href="#"
@ -269,8 +263,10 @@
class="btn action-sync-manual-dropbox" title="Add location"
data-dismiss="modal"><i class="icon-ok"></i></a>
</div>
<blockquote class="muted"><b>NOTE:</b> This will upload the local document
firstly and overwrite the existing file on the server.</blockquote>
<blockquote class="muted">
<b>NOTE:</b> This will upload the local document firstly and
overwrite the existing file on the server.
</blockquote>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>
@ -309,6 +305,28 @@
placeholder="path/to/file.md">
</div>
</div>
<div class="control-group modal-publish-gist">
<label class="control-label" for="input-publish-filename">Filename</label>
<div class="controls">
<input type="text" id="input-publish-filename"
placeholder="Filename">
</div>
</div>
<div class="control-group modal-publish-gist">
<label class="control-label" for="input-publish-gist-id">Existing
ID (optional)</label>
<div class="controls">
<input type="text" id="input-publish-gist-id"
placeholder="Gist ID">
</div>
</div>
<div class="control-group modal-publish-gist">
<label class="control-label" for="input-publish-gist-public">Public</label>
<div class="controls">
<input type="checkbox" id="input-publish-gist-public"
checked="checked" />
</div>
</div>
<div class="control-group modal-publish-blogger">
<label class="control-label" for="input-publish-blogger-url">Blog
URL</label>
@ -325,12 +343,12 @@
placeholder="exemple.tumblr.com">
</div>
</div>
<div class="control-group modal-publish-blogger modal-publish-tumblr">
<div
class="control-group modal-publish-blogger modal-publish-tumblr">
<label class="control-label" for="input-publish-postid">Update
existing post ID (optional)</label>
<div class="controls">
<input type="text" id="input-publish-postid"
placeholder="Post ID">
<input type="text" id="input-publish-postid" placeholder="Post ID">
</div>
</div>
<div class="control-group modal-publish-blogger">
@ -417,8 +435,9 @@
<p class="msg-no-publish hide">"<span class="file-title"></span>"
is not published.
</p>
<blockquote class="muted"><b>NOTE:</b> You can add locations using
"Publish on" sub-menu.</blockquote>
<blockquote class="muted">
<b>NOTE:</b> You can add locations using "Publish on" sub-menu.
</blockquote>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>
@ -485,8 +504,8 @@
</div>
<div class="control-group">
<label class="control-label"
for="textarea-settings-default-content">Default content <a
href="#" class="tooltip-default-content">(?)</a>
for="textarea-settings-default-content">Default content
<a href="#" class="tooltip-default-content">(?)</a>
</label>
<div class="controls">
<textarea id="textarea-settings-default-content"></textarea>
@ -643,8 +662,8 @@
<div class="modal-body">
<p>StackEdit has stopped because another instance was running in
the same browser.</p>
<blockquote class="muted">If you want to reopen StackEdit, click on
"Reload".</blockquote>
<blockquote class="muted">If you want to reopen
StackEdit, click on "Reload".</blockquote>
</div>
<div class="modal-footer">
<a href="javascript:window.location.reload();"

View File

@ -15,6 +15,7 @@ var USER_IDLE_THRESHOLD = 300000;
var PROVIDER_BLOGGER = "blogger";
var PROVIDER_DROPBOX = "dropbox";
var PROVIDER_GDRIVE = "gdrive";
var PROVIDER_GIST = "gist";
var PROVIDER_GITHUB = "github";
var PROVIDER_TUMBLR = "tumblr";
var WELCOME_DOCUMENT_TITLE = "Welcome document";

View File

@ -762,6 +762,14 @@ define(
}
version = "v4";
}
// Upgrade from v4 to v5
if(version == "v4") {
// Recreate GitHub token
localStorage.removeItem("githubToken");
version = "v5";
}
localStorage["version"] = version;
}
// Setup the localStorage when starting

33
js/gist-provider.js Normal file
View File

@ -0,0 +1,33 @@
define(["jquery", "core", "github-helper"], function($, core, githubHelper) {
var gistProvider = {
providerId: PROVIDER_GIST,
providerName: "Gist"
};
gistProvider.publish = function(publishAttributes, title, content, callback) {
githubHelper.gistUpload(publishAttributes.gistId, publishAttributes.filename, publishAttributes.isPublic,
title, content, function(error, gistId) {
if(error) {
callback(error);
return;
}
publishAttributes.gistId = gistId;
callback();
}
);
};
gistProvider.newPublishAttributes = function(event) {
var publishAttributes = {};
publishAttributes.gistId = core.getInputValue($("#input-publish-gist-id"));
publishAttributes.filename = core.getInputValue($("#input-publish-filename"), event);
publishAttributes.isPublic = $("#input-publish-gist-public").is(":checked");
if(event.isPropagationStopped()) {
return undefined;
}
return publishAttributes;
};
return gistProvider;
});

View File

@ -144,6 +144,45 @@ define(["jquery", "core", "async-runner"], function($, core, asyncRunner) {
asyncRunner.addTask(task);
};
githubHelper.gistUpload = function(gistId, filename, isPublic, title, content, callback) {
callback = callback || core.doNothing;
var task = asyncRunner.createTask();
connect(task);
authenticate(task);
task.onRun(function() {
var gist = github.getGist(gistId);
var files = {};
files[filename] = {content: content};
githubFunction = gist.update;
if(gistId === undefined) {
githubFunction = gist.create;
}
githubFunction({
description: title,
"public": isPublic,
files: files
}, function(err, gist) {
if(err) {
// Handle error
if(err.error === 404 && gistId !== undefined) {
err = 'Gist ' + gistId + ' not found on GitHub.|removePublish';
}
handleError(err, task);
return;
}
gistId = gist.id;
task.chain();
});
});
task.onSuccess(function() {
callback(undefined, gistId);
});
task.onError(function(error) {
callback(error);
});
asyncRunner.addTask(task);
};
function handleError(error, task) {
var errorMsg = undefined;
if (error) {

2
js/main-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
define(["jquery", "core", "github-provider", "blogger-provider", "dropbox-provider", "gdrive-provider", "tumblr-provider", "underscore"], function($, core) {
define(["jquery", "core", "blogger-provider", "dropbox-provider", "gist-provider", "github-provider", "gdrive-provider", "tumblr-provider", "underscore"], function($, core) {
var publisher = {};
@ -219,12 +219,19 @@ define(["jquery", "core", "github-provider", "blogger-provider", "dropbox-provid
};
core.onReady(function() {
// Init each provider
// Add every provider
var publishMenu = $("#publish-menu");
_.each(providerMap, function(provider) {
// Publish provider button
$(".action-publish-" + provider.providerId).click(function() {
// Provider's publish button
publishMenu.append(
$("<li>").append(
$('<a href="#"><i class="icon-' + provider.providerId + '"></i> ' + provider.providerName + '</a>')
.click(function() {
initNewLocation(provider);
});
}
)
)
);
});
$(".action-process-publish").click(performNewLocation);