Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #149 from ckeditor/t/146
Browse files Browse the repository at this point in the history
Feature: Implemented the `extraPlugins` editor configuration. Closes #146.
  • Loading branch information
scofalik authored Nov 26, 2018
2 parents c4795fb + 36f54c0 commit 4b5c3d4
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ export default class Editor {
function loadPlugins() {
const plugins = config.get( 'plugins' ) || [];
const removePlugins = config.get( 'removePlugins' ) || [];
const extraPlugins = config.get( 'extraPlugins' ) || [];

return that.plugins.load( plugins, removePlugins );
return that.plugins.load( plugins.concat( extraPlugins ), removePlugins );
}

function initPlugins( loadedPlugins, method ) {
Expand Down
25 changes: 25 additions & 0 deletions src/editor/editorconfig.jsdoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,34 @@
* plugins: [ Essentials, Bold ]
* };
*
* **Note:** To load additional plugins, you should use the {@link #extraPlugins `extraPlugins`} configuration.
* To narrow the list of loaded plugins, use the {@link #removePlugins `removePlugins`} configuration.
*
* @member {Array.<String|Function>} module:core/editor/editorconfig~EditorConfig#plugins
*/

/**
* The list of additional plugins to load along those already available in the
* {@glink builds/guides/overview editor build}. It extends the {@link #plugins `plugins`} configuration.
*
* function MyPlugin( editor ) {
* // ...
* }
*
* const config = {
* extraPlugins: [ MyPlugin ]
* };
*
* **Note:** This configuration works only for simple plugins which utilize the
* {@link module:core/plugin~PluginInterface plugin interface} and have no dependencies. To extend a
* build with complex features, create a {@glink builds/guides/development/custom-builds custom build}.
*
* **Note:** Make sure you include the new features in you toolbar configuration. Learn more
* about {@glink builds/guides/integration/configuration#toolbar-setup toolbar setup}.
*
* @member {Array.<Function>} module:core/editor/editorconfig~EditorConfig#extraPlugins
*/

/**
* The list of plugins which should not be loaded despite being available in an {@glink builds/guides/overview editor build}.
*
Expand Down
112 changes: 86 additions & 26 deletions tests/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,47 +630,107 @@ describe( 'Editor', () => {
} );
} );

it( 'should not load plugins specified in the config as "removePlugins"', () => {
const editor = new Editor( {
plugins: [ PluginA, PluginD ],
removePlugins: [ PluginD ]
describe( '"removePlugins" config', () => {
it( 'should prevent plugins from being loaded', () => {
const editor = new Editor( {
plugins: [ PluginA, PluginD ],
removePlugins: [ PluginD ]
} );

return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 1 );
expect( editor.plugins.get( PluginA ) ).to.be.an.instanceof( Plugin );
} );
} );

return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 1 );
expect( editor.plugins.get( PluginA ) ).to.be.an.instanceof( Plugin );
it( 'should not load plugins built in the Editor', () => {
Editor.builtinPlugins = [ PluginA, PluginD ];

const editor = new Editor( {
removePlugins: [ 'D' ]
} );

return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 1 );
expect( editor.plugins.get( PluginA ) ).to.be.an.instanceof( Plugin );
} );
} );

it( 'should not load plugins build into Editor\'s subclass', () => {
class CustomEditor extends Editor {}

CustomEditor.builtinPlugins = [ PluginA, PluginD ];

const editor = new CustomEditor( {
removePlugins: [ 'D' ]
} );

return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 1 );
expect( editor.plugins.get( PluginA ) ).to.not.be.undefined;
} );
} );
} );

it( 'should not load plugins built in the Editor when "removePlugins" option is specified', () => {
Editor.builtinPlugins = [ PluginA, PluginD ];
describe( '"extraPlugins" config', () => {
it( 'should load additional plugins', () => {
const editor = new Editor( {
plugins: [ PluginA, PluginC ],
extraPlugins: [ PluginB ]
} );

const editor = new Editor( {
removePlugins: [ 'D' ]
return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 3 );
expect( editor.plugins.get( PluginB ) ).to.be.an.instanceof( Plugin );
} );
} );

return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 1 );
expect( editor.plugins.get( PluginA ) ).to.be.an.instanceof( Plugin );
it( 'should not duplicate plugins', () => {
const editor = new Editor( {
plugins: [ PluginA, PluginB ],
extraPlugins: [ PluginB ]
} );
} );

it( 'should not load plugins build into Editor\'s subclass when "removePlugins" option is specified', () => {
class CustomEditor extends Editor {}
return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 2 );
expect( editor.plugins.get( PluginB ) ).to.be.an.instanceof( Plugin );
} );
} );

CustomEditor.builtinPlugins = [ PluginA, PluginD ];
it( 'should not duplicate plugins built in the Editor', () => {
Editor.builtinPlugins = [ PluginA, PluginB ];

const editor = new CustomEditor( {
removePlugins: [ 'D' ]
const editor = new Editor( {
extraPlugins: [ 'B' ]
} );

return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 2 );
expect( editor.plugins.get( PluginB ) ).to.be.an.instanceof( Plugin );
} );
} );

return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 1 );
expect( editor.plugins.get( PluginA ) ).to.not.be.undefined;
it( 'should not duplicate plugins build into Editor\'s subclass', () => {
class CustomEditor extends Editor {}

CustomEditor.builtinPlugins = [ PluginA, PluginB ];

const editor = new CustomEditor( {
extraPlugins: [ 'B' ]
} );

return editor.initPlugins()
.then( () => {
expect( getPlugins( editor ).length ).to.equal( 2 );
expect( editor.plugins.get( PluginB ) ).to.be.an.instanceof( Plugin );
} );
} );
} );

it( 'should not call "afterInit" method if plugin does not have this method', () => {
Expand Down

0 comments on commit 4b5c3d4

Please sign in to comment.