Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stackedit modularization: Plugins folders #595

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added simple plugin model. Handles loading of Providers for now.
Instead of having every model which might need a provider having to
specify every possible provider as input argument, we now have a plugin
model which can expose a list of providers, which the event manager then
will notify about when they are loaded.

Conflicts:
	public/res/publisher.js
	public/res/sharing.js
  • Loading branch information
Tobias Haagen Michaelsen authored and jesperronn committed Oct 30, 2014
commit ba81b080cffa714c7aa38966078287c261df9006
11 changes: 11 additions & 0 deletions public/res/classes/Plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define([
], function() {
function Plugin(properties) {
for (var prop in properties) {
if (properties.hasOwnProperty(prop)) {
this[prop] = properties[prop];
}
}
}
return Plugin;
});
3 changes: 3 additions & 0 deletions public/res/eventMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ define([
// Refresh twitter buttons
addEventHook("onTweet");

// Plugins
addEventHook("onProviderLoaded");
addEventHook("onPluginsLoaded");

var onPreviewFinished = createEventHook("onPreviewFinished");
var onAsyncPreviewListenerList = getExtensionListenerList("onAsyncPreview");
Expand Down
1 change: 1 addition & 0 deletions public/res/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ require([
"publisher",
"sharing",
"mediaImporter",
"plugins",
"css",
"rangy-cssclassapplier",
themeModule
Expand Down
5 changes: 2 additions & 3 deletions public/res/mediaImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ define([
"constants",
"classes/Provider",
"core",
"eventMgr",
"providers/gplusProvider"
"eventMgr"
], function($, _, constants, Provider, core, eventMgr) {

var mediaImporter = {};
Expand Down Expand Up @@ -82,4 +81,4 @@ define([
});

return mediaImporter;
});
});
21 changes: 21 additions & 0 deletions public/res/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define([
"eventMgr",
"classes/Plugin",
"plugins/blogger/index",
"plugins/dropbox/index",
"plugins/github/index",
"plugins/google/index",
"plugins/ssh/index",
"plugins/tumblr/index",
"plugins/wordpress/index"
], function(eventMgr, Plugin) {
Array.prototype.slice.call(arguments).forEach(function(argument) {
if (argument && argument instanceof Plugin) {
var providers = argument.providers || [];
providers.forEach(function(provider) {
eventMgr.onProviderLoaded(provider);
});
}
});
eventMgr.onPluginsLoaded();
});
9 changes: 9 additions & 0 deletions public/res/plugins/blogger/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define([
"classes/Plugin",
"providers/bloggerProvider",
"providers/bloggerPageProvider"
], function(Plugin, bloggerProvider, bloggerPageProvider) {
return new Plugin({
providers: [bloggerProvider, bloggerPageProvider]
});
});
8 changes: 8 additions & 0 deletions public/res/plugins/couchdb/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define([
"classes/Plugin",
"providers/couchdbProvider"
], function(Plugin, couchdbProvider) {
return new Plugin({
providers: [couchdbProvider]
};
});
8 changes: 8 additions & 0 deletions public/res/plugins/download/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define([
"classes/Plugin",
"providers/downloadProvider"
], function(Plugin, downloadProvider) {
return new Plugin({
providers: [downloadProvider]
};
});
8 changes: 8 additions & 0 deletions public/res/plugins/dropbox/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define([
"classes/Plugin",
"providers/dropboxProvider"
], function(Plugin, dropboxProvider) {
return new Plugin({
providers: [dropboxProvider]
};
});
9 changes: 9 additions & 0 deletions public/res/plugins/github/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define([
"classes/Plugin",
"providers/gistProvider",
"providers/githubProvider"
], function(Plugin, gistProvider, githubProvider) {
return new Plugin({
providers: [gistProvider, githubProvider]
};
});
10 changes: 10 additions & 0 deletions public/res/plugins/google/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
define([
"classes/Plugin",
"providers/gdriveProvider",
"providers/gdrivesecProvider",
"providers/gdriveterProvider"
], function(Plugin, gdriveProvider, gdrivesecProvider, gdriveterProvider) {
return new Plugin({
providers: [gdriveProvider, gdrivesecProvider, gdriveterProvider]
};
});
8 changes: 8 additions & 0 deletions public/res/plugins/ssh/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define([
"classes/Plugin",
"providers/sshProvider"
], function(Plugin, sshProvider) {
return new Plugin({
providers: [sshProvider]
};
});
8 changes: 8 additions & 0 deletions public/res/plugins/tumblr/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define([
"classes/Plugin",
"providers/tumblrProvider"
], function(Plugin, tumblrProvider) {
return new Plugin({
providers: [tumblrProvider]
});
});
8 changes: 8 additions & 0 deletions public/res/plugins/wordpress/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define([
"classes/Plugin",
"providers/wordpressProvider"
], function(Plugin, wordpressProvider) {
return new Plugin({
providers: [wordpressProvider]
});
});
33 changes: 11 additions & 22 deletions public/res/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,22 @@ define([
"fileSystem",
"fileMgr",
"monetizejs",
"classes/Provider",
"classes/AsyncTask",
"providers/bloggerProvider",
"providers/bloggerPageProvider",
"providers/dropboxProvider",
"providers/gistProvider",
"providers/githubProvider",
"providers/gdriveProvider",
"providers/gdrivesecProvider",
"providers/gdriveterProvider",
"providers/sshProvider",
"providers/tumblrProvider",
"providers/wordpressProvider"
], function($, _, constants, utils, storage, settings, eventMgr, fileSystem, fileMgr, MonetizeJS, Provider, AsyncTask) {
"classes/AsyncTask"
], function($, _, constants, utils, storage, settings, eventMgr, fileSystem, fileMgr, MonetizeJS, AsyncTask) {

var publisher = {};

// Create a map with providerId: providerModule
var providerMap = _.chain(arguments).map(function(argument) {
return argument instanceof Provider && argument.isPublishEnabled === true && [
argument.providerId,
argument
];
}).compact().object().value();
var providerMap = {};

eventMgr.addListener("onProviderLoaded", function(provider) {
if (provider.isPublishEnabled === true) {
providerMap[provider.providerId] = provider;
}
});

// Retrieve publish locations from storage
(function() {
eventMgr.addListener("onPluginsLoaded", function() {
var publishIndexMap = {};
_.each(fileSystem, function(fileDesc) {
utils.retrieveIndexArray(fileDesc.fileIndex + ".publish").forEach(function(publishIndex) {
Expand Down Expand Up @@ -68,7 +57,7 @@ define([
storage.removeItem(key);
}
});
})();
});

// Apply template to the current document
publisher.applyTemplate = function(fileDesc, publishAttributes, html) {
Expand Down
12 changes: 6 additions & 6 deletions public/res/sharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define([
"fileMgr",
"classes/AsyncTask",
"classes/Provider",
"providers/karnovProvider",
"providers/couchdbProvider",
"providers/downloadProvider",
"providers/gistProvider"
Expand All @@ -15,12 +16,11 @@ define([
var sharing = {};

// Create a map with providerId: providerModule
var providerMap = _.chain(arguments).map(function(argument) {
return argument instanceof Provider && [
argument.providerId,
argument
];
}).compact().object().value();
var providerMap = {};

eventMgr.addListener("onProviderLoaded", function(provider) {
providerMap[provider.providerId] = provider;
});

// Listen to offline status changes
var isOffline = false;
Expand Down
30 changes: 10 additions & 20 deletions public/res/synchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,22 @@ define([
"storage",
"eventMgr",
"fileSystem",
"fileMgr",
"classes/Provider",
"providers/dropboxProvider",
"providers/couchdbProvider",
"providers/gdriveProvider",
"providers/gdrivesecProvider",
"providers/gdriveterProvider"
], function($, _, utils, storage, eventMgr, fileSystem, fileMgr, Provider) {
"fileMgr"
], function($, _, utils, storage, eventMgr, fileSystem, fileMgr) {

var synchronizer = {};

// Create a map with providerId: providerModule
var providerMap = _.chain(arguments).map(function(argument) {
return argument instanceof Provider && [
argument.providerId,
argument
];
}).compact().object().value();
var providerMap = {};

eventMgr.addListener("onProviderLoaded", function(provider) {
providerMap[provider.providerId] = provider;
// AutoSync configuration
provider.autosyncConfig = utils.retrieveIgnoreError(provider.providerId + ".autosyncConfig") || {};
});

// Retrieve sync locations from storage
(function() {
eventMgr.addListener("onPluginsLoaded", (function() {
var syncIndexMap = {};
_.each(fileSystem, function(fileDesc) {
utils.retrieveIndexArray(fileDesc.fileIndex + ".sync").forEach(function(syncIndex) {
Expand Down Expand Up @@ -58,11 +53,6 @@ define([
storage.removeItem(key);
}
});
})();

// AutoSync configuration
_.each(providerMap, function(provider) {
provider.autosyncConfig = utils.retrieveIgnoreError(provider.providerId + ".autosyncConfig") || {};
});

// Returns true if at least one file has synchronized location
Expand Down