浏览代码

Second batch of changes updating schema use to match the new API.

Piotrek Koszuliński 8 年之前
父节点
当前提交
01f2749930

+ 2 - 10
packages/ckeditor5-image/src/image/converters.js

@@ -31,7 +31,7 @@ export function viewFigureToModel() {
 		}
 
 		// Do not convert if image cannot be placed in model at this context.
-		if ( !conversionApi.schema.check( { name: 'image', inside: data.context, attributes: 'src' } ) ) {
+		if ( !conversionApi.schema.checkChild( data.context, 'image' ) ) {
 			return;
 		}
 
@@ -197,16 +197,8 @@ function _findAllowedContext( modelData, context, schema ) {
 	// Copy context array so we won't modify original array.
 	context = context.slice();
 
-	// Prepare schema query to check with schema.
-	// Since `inside` property is passed as reference to `context` variable, we don't need to modify `schemaQuery`.
-	const schemaQuery = {
-		name: modelData.name,
-		attributes: modelData.attributes,
-		inside: context
-	};
-
 	// Try out all possible contexts.
-	while ( context.length && !schema.check( schemaQuery ) ) {
+	while ( context.length && !schema.checkChild( context, modelData.name ) ) {
 		const parent = context.pop();
 		const parentName = typeof parent === 'string' ? parent : parent.name;
 

+ 1 - 4
packages/ckeditor5-image/src/imagestyle/converters.js

@@ -80,10 +80,7 @@ function viewToModelImageStyle( style, data, consumable, conversionApi ) {
 		return;
 	}
 
-	// Check if image element can be placed in current context wit additional attribute.
-	const attributes = [ ...modelImageElement.getAttributeKeys(), 'imageStyle' ];
-
-	if ( !conversionApi.schema.check( { name: 'image', inside: data.context, attributes } ) ) {
+	if ( !conversionApi.schema.checkAttribute( [ ...data.context, 'image' ], 'imageStyle' ) ) {
 		return;
 	}
 

+ 1 - 1
packages/ckeditor5-image/tests/image/converters.js

@@ -198,7 +198,7 @@ describe( 'Image converters', () => {
 
 			dispatcher = editor.data.viewToModel;
 			dispatcher.on( 'element:img', ( evt, data, consumable ) => {
-				if ( !schema.check( { name: 'image', attributes: [ 'src' ], inside: data.context } ) ) {
+				if ( !schema.checkChild( data.context, 'image' ) ) {
 					return;
 				}
 

+ 8 - 1
packages/ckeditor5-image/tests/image/imageengine.js

@@ -33,8 +33,15 @@ describe( 'ImageEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.check( { name: 'image', attributes: [ 'src', 'alt' ], inside: '$root' } ) ).to.be.true;
+		expect( model.schema.checkChild( [ '$root' ], 'image' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$root', 'image' ], 'src' ) ).to.be.true;
+		expect( model.schema.checkAttribute( [ '$root', 'image' ], 'alt' ) ).to.be.true;
+
 		expect( model.schema.isObject( 'image' ) ).to.be.true;
+
+		expect( model.schema.checkChild( [ '$root', 'image' ], 'image' ) ).to.be.false;
+		expect( model.schema.checkChild( [ '$root', 'image' ], '$text' ) ).to.be.false;
+		expect( model.schema.checkChild( [ '$root', '$block' ], 'image' ) ).to.be.false;
 	} );
 
 	describe( 'conversion in data pipeline', () => {

+ 6 - 4
packages/ckeditor5-image/tests/imagecaption/imagecaptionengine.js

@@ -57,22 +57,24 @@ describe( 'ImageCaptionEngine', () => {
 	} );
 
 	it( 'should set proper schema rules', () => {
-		expect( model.schema.check( { name: 'caption', iniside: 'image' } ) ).to.be.true;
-		expect( model.schema.check( { name: '$text', inside: 'caption' } ) ).to.be.true;
+		expect( model.schema.checkChild( [ '$root', 'image' ], 'caption' ) ).to.be.true;
+		expect( model.schema.checkChild( [ '$root', 'image', 'caption' ], '$text' ) ).to.be.true;
 		expect( model.schema.isLimit( 'caption' ) ).to.be.true;
+
+		expect( model.schema.checkChild( [ '$root', 'image', 'caption' ], 'caption' ) ).to.be.false;
 	} );
 
 	describe( 'data pipeline', () => {
 		describe( 'view to model', () => {
 			it( 'should convert figcaption inside image figure', () => {
-				editor.setData( '<figure class="image"><img src="foo.png"/><figcaption>foo bar</figcaption></figure>' );
+				editor.setData( '<figure class="image"><img src="foo.png" /><figcaption>foo bar</figcaption></figure>' );
 
 				expect( getModelData( model, { withoutSelection: true } ) )
 					.to.equal( '<image src="foo.png"><caption>foo bar</caption></image>' );
 			} );
 
 			it( 'should add empty caption if there is no figcaption', () => {
-				editor.setData( '<figure class="image"><img src="foo.png"/></figure>' );
+				editor.setData( '<figure class="image"><img src="foo.png" /></figure>' );
 
 				expect( getModelData( model, { withoutSelection: true } ) )
 					.to.equal( '<image src="foo.png"><caption></caption></image>' );

+ 1 - 1
packages/ckeditor5-image/tests/imagestyle/imagestyleengine.js

@@ -84,7 +84,7 @@ describe( 'ImageStyleEngine', () => {
 		it( 'should set schema rules for image style', () => {
 			const schema = model.schema;
 
-			expect( schema.check( { name: 'image', attributes: [ 'imageStyle', 'src' ], inside: '$root' } ) ).to.be.true;
+			expect( schema.checkAttribute( [ '$root', 'image' ], 'imageStyle' ) ).to.be.true;
 		} );
 
 		it( 'should register separate command for each style', () => {