浏览代码

Other: Aligning with new conversion helpers API.

Szymon Cofalik 7 年之前
父节点
当前提交
1cea44a787

+ 3 - 2
packages/ckeditor5-font/src/fontfamily/fontfamilyediting.js

@@ -8,10 +8,10 @@
  */
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import { attributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/two-way-converters';
 
 import FontFamilyCommand from './fontfamilycommand';
 import { normalizeOptions } from './utils';
+import { buildDefinition } from '../utils';
 
 const FONT_FAMILY = 'fontFamily';
 
@@ -59,9 +59,10 @@ export default class FontFamilyEditing extends Plugin {
 
 		// Get configured font family options without "default" option.
 		const options = normalizeOptions( editor.config.get( 'fontFamily.options' ) ).filter( item => item.model );
+		const definition = buildDefinition( FONT_FAMILY, options );
 
 		// Set-up the two-way conversion.
-		attributeToElement( editor.conversion, FONT_FAMILY, options );
+		editor.conversion.attributeToElement( definition );
 
 		editor.commands.add( FONT_FAMILY, new FontFamilyCommand( editor ) );
 	}

+ 3 - 2
packages/ckeditor5-font/src/fontsize/fontsizeediting.js

@@ -8,10 +8,10 @@
  */
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import { attributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/two-way-converters';
 
 import FontSizeCommand from './fontsizecommand';
 import { normalizeOptions } from './utils';
+import { buildDefinition } from '../utils';
 
 const FONT_SIZE = 'fontSize';
 
@@ -48,9 +48,10 @@ export default class FontSizeEditing extends Plugin {
 
 		// Define view to model conversion.
 		const options = normalizeOptions( this.editor.config.get( 'fontSize.options' ) ).filter( item => item.model );
+		const definition = buildDefinition( FONT_SIZE, options );
 
 		// Set-up the two-way conversion.
-		attributeToElement( editor.conversion, FONT_SIZE, options );
+		editor.conversion.attributeToElement( definition );
 
 		// Add FontSize command.
 		editor.commands.add( FONT_SIZE, new FontSizeCommand( editor ) );

+ 37 - 0
packages/ckeditor5-font/src/utils.js

@@ -0,0 +1,37 @@
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * @module font/utils
+ */
+
+/**
+ * Builds a proper {@link module:engine/conversion/Conversion~ConverterDefinition converter definition} out of input data.
+ *
+ * @param {String} modelAttributeKey Key
+ * @param {Array.<module:font/fontsize~FontFamilyOption>|Array.<module:font/fontsize~FontSizeOption>} options
+ * @returns {module:engine/conversion/Conversion~ConverterDefinition}
+ */
+export function buildDefinition( modelAttributeKey, options ) {
+	const definition = {
+		model: {
+			key: modelAttributeKey,
+			values: []
+		},
+		view: {},
+		upcastAlso: {}
+	};
+
+	for ( const option of options ) {
+		definition.model.values.push( option.model );
+		definition.view[ option.model ] = option.view;
+
+		if ( option.upcastAlso ) {
+			definition.upcastAlso[ option.model ] = option.upcastAlso;
+		}
+	}
+
+	return definition;
+}