Explorar el Código

Feature: Add FontSizeEditing plugins stub.

Maciej Gołaszewski hace 8 años
padre
commit
823876442f

+ 2 - 1
packages/ckeditor5-font/src/fontsize.js

@@ -8,6 +8,7 @@
  */
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+import FontSizeEditing from './fontsizeediting';
 
 /**
  * The Font Size plugin.
@@ -19,7 +20,7 @@ export default class FontSize extends Plugin {
 	 * @inheritDoc
 	 */
 	static get requires() {
-		return [];
+		return [ FontSizeEditing ];
 	}
 
 	/**

+ 38 - 0
packages/ckeditor5-font/src/fontsizeediting.js

@@ -0,0 +1,38 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * @module font/fontsizeediting
+ */
+
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+
+/**
+ * The Font Size Editing feature.
+ *
+ * @extends module:core/plugin~Plugin
+ */
+export default class FontSizeEditing extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	constructor( editor ) {
+		super( editor );
+
+		editor.config.define( 'fontSize', { items: [] } );
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		const editor = this.editor;
+
+		// Allow highlight attribute on all elements
+		editor.document.schema.allow( { name: '$inline', attributes: 'fontSize', inside: '$block' } );
+		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
+		editor.document.schema.allow( { name: '$inline', attributes: 'fontSize', inside: '$clipboardHolder' } );
+	}
+}

+ 4 - 25
packages/ckeditor5-font/tests/font.js

@@ -3,36 +3,15 @@
  * For licensing, see LICENSE.md.
  */
 
-/* global document */
-
 import Font from './../src/font';
 import FontSize from './../src/fontsize';
 
-import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
-
 describe( 'Font', () => {
-	let editor, element;
-
-	beforeEach( () => {
-		element = document.createElement( 'div' );
-		document.body.appendChild( element );
-
-		return ClassicTestEditor
-			.create( element, {
-				plugins: [ Font ]
-			} )
-			.then( newEditor => {
-				editor = newEditor;
-			} );
-	} );
-
-	afterEach( () => {
-		element.remove();
-
-		return editor.destroy();
-	} );
-
 	it( 'requires FontSize', () => {
 		expect( Font.requires ).to.deep.equal( [ FontSize ] );
 	} );
+
+	it( 'defines plugin name', () => {
+		expect( Font.pluginName ).to.equal( 'Font' );
+	} );
 } );

+ 17 - 0
packages/ckeditor5-font/tests/fontsize.js

@@ -0,0 +1,17 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import FontSize from './../src/fontsize';
+import FontSizeEditing from './../src/fontsizeediting';
+
+describe( 'FontSize', () => {
+	it( 'requires FontSizeEditing', () => {
+		expect( FontSize.requires ).to.deep.equal( [ FontSizeEditing ] );
+	} );
+
+	it( 'defines plugin name', () => {
+		expect( FontSize.pluginName ).to.equal( 'FontSize' );
+	} );
+} );

+ 43 - 0
packages/ckeditor5-font/tests/fontsizeediting.js

@@ -0,0 +1,43 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import FontSizeEditing from './../src/fontsizeediting';
+
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
+
+import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
+
+describe( 'FontSizeEditing', () => {
+	let editor, doc;
+
+	beforeEach( () => {
+		return VirtualTestEditor
+			.create( {
+				plugins: [ FontSizeEditing, Paragraph ]
+			} )
+			.then( newEditor => {
+				editor = newEditor;
+
+				doc = editor.document;
+			} );
+	} );
+
+	afterEach( () => {
+		editor.destroy();
+	} );
+
+	it( 'should set proper schema rules', () => {
+		expect( doc.schema.check( { name: '$inline', attributes: 'fontSize', inside: '$block' } ) ).to.be.true;
+		expect( doc.schema.check( { name: '$inline', attributes: 'fontSize', inside: '$clipboardHolder' } ) ).to.be.true;
+	} );
+
+	describe( 'config', () => {
+		describe( 'default value', () => {
+			it( 'should be set', () => {
+				expect( editor.config.get( 'fontSize.items' ) ).to.deep.equal( [] );
+			} );
+		} );
+	} );
+} );