Browse Source

Start Plugin Manager

pull/36/head
Artur Arseniev 10 years ago
parent
commit
f10352ae65
  1. 1
      src/config/require-config.js
  2. 3
      src/grapesjs/config/config.js
  3. 52
      src/grapesjs/main.js
  4. 7
      src/plugin_manager/config/config.js
  5. 59
      src/plugin_manager/main.js
  6. 1
      test/runner/main.js
  7. 39
      test/specs/plugin_manager/main.js

1
src/config/require-config.js

@ -37,6 +37,7 @@ require.config({
{ name: 'StyleManager', location: 'style_manager', }, { name: 'StyleManager', location: 'style_manager', },
{ name: 'ClassManager', location: 'class_manager', }, { name: 'ClassManager', location: 'class_manager', },
{ name: 'StorageManager', location: 'storage_manager', }, { name: 'StorageManager', location: 'storage_manager', },
{ name: 'PluginManager', location: 'plugin_manager', },
{ name: 'Navigator', location: 'navigator', }, { name: 'Navigator', location: 'navigator', },
{ name: 'DomComponents', location: 'dom_components', }, { name: 'DomComponents', location: 'dom_components', },
{ name: 'RichTextEditor', location: 'rich_text_editor', }, { name: 'RichTextEditor', location: 'rich_text_editor', },

3
src/grapesjs/config/config.js

@ -9,7 +9,7 @@ define(function () {
// CSS string or object of rules // CSS string or object of rules
style: '', style: '',
// If true, will fetch HTML and CSS from selected element // If true, will fetch HTML and CSS from selected container
fromElement: false, fromElement: false,
// Enable/Disable the possibility to copy(ctrl + c) & paste(ctrl + v) components // Enable/Disable the possibility to copy(ctrl + c) & paste(ctrl + v) components
@ -23,6 +23,7 @@ define(function () {
//Indicates which storage to use. Available: local | remote | none //Indicates which storage to use. Available: local | remote | none
storageType: 'local', // (!) storageType: 'local', // (!)
// More correct
storage:{ storage:{
id: '', id: '',
type: '', type: '',

52
src/grapesjs/main.js

@ -0,0 +1,52 @@
define(function(require) {
return function(config) {
var c = config || {},
defaults = require('./config/config');
// Set default options
for (var name in defaults) {
if (!(name in c))
c[name] = defaults[name];
}
var plugins = [];
/*
.plugins will be PluginManager
grapesjs.plugins.add('sheeet', function(editor){
editor.commands.add('openbar', function(){});
});
*/
var editors = [];
return {
plugins: plugins,
/**
* Initializes an editor based on passed options
* @param {Object} config Configuration object
* @param {string} config.container Selector which indicates where render the editor
* @param {Object|string} config.components='' HTML string or Component model in JSON format
* @param {Object|string} config.style='' CSS string or CSS model in JSON format
* @param {Boolean} [config.copyPaste=true] Enable/Disable the possibility to copy(ctrl+c) & paste(ctrl+v) components
* @param {Boolean} [config.undoManager=true] Enable/Disable undo manager
* @param {Array} [config.plugins=[]] Array of plugins to execute on start
* @return {grapesjs.Editor} GrapesJS Editor instance
*/
init: function(config) {
//
var editor = new Editor(config);
//- new EditorView({model: editor}).render();
//- inject and start plugins (plugins)
// foreach config.plugins
// pluginManager.get('plugin')(editor);
//
return editor;
},
};
};
});

7
src/plugin_manager/config/config.js

@ -0,0 +1,7 @@
define(function () {
return {
plugins: []
};
});

59
src/plugin_manager/main.js

@ -0,0 +1,59 @@
define(function(require) {
return function(config) {
var c = config || {},
defaults = require('./config/config');
// Set default options
for (var name in defaults) {
if (!(name in c))
c[name] = defaults[name];
}
var plugins = {};
return {
/**
* Add new plugin. Plugins could not be overwritten
* @param {string} id Plugin ID
* @param {Function} plugin Function which contains all plugin logic
* @example
* PluginManager.add('some-plugin', function(editor){
* editor.Commands.add('new-command', {
* run: function(editor, senderBtn){
* console.log('Executed new-command');
* }
* })
* });
*/
add: function(id, plugin){
plugins[id] = plugin;
return this;
},
/**
* Returns plugin by ID
* @param {string} id Plugin ID
* @return {Function|undefined} Plugin
* @example
* var plugin = PluginManager.get('some-plugin');
* plugin(editor);
*/
get: function(id){
return plugins[id];
},
/**
* Returns object with all plugins
* @return {Object}
*/
getAll: function(){
return plugins;
}
};
};
});

1
test/runner/main.js

@ -19,6 +19,7 @@ require(['../src/config/require-config.js', 'config/config.js'], function() {
'specs/commands/main.js', 'specs/commands/main.js',
'specs/style_manager/main.js', 'specs/style_manager/main.js',
'specs/storage_manager/main.js', 'specs/storage_manager/main.js',
'specs/plugin_manager/main.js',
'specs/parser/main.js', 'specs/parser/main.js',
'specs/utils/main.js' 'specs/utils/main.js'
], function(chai) ], function(chai)

39
test/specs/plugin_manager/main.js

@ -0,0 +1,39 @@
var modulePath = './../../../test/specs/plugin_manager';
define(['PluginManager'], function(PluginManager) {
describe('PluginManager', function() {
describe('Main', function() {
var obj;
var val;
var testPlugin = function(e){
val = e;
};
beforeEach(function () {
obj = new PluginManager();
});
afterEach(function () {
delete obj;
});
it('Object exists', function() {
obj.should.be.exist;
});
it('No plugins inside', function() {
obj.getAll().should.be.empty;
});
it('Add new plugin', function() {
obj.add('test', testPlugin);
obj.get('test').should.not.be.empty;
});
});
});
});
Loading…
Cancel
Save