浏览代码

Merge branch 't/202'. Closes #202.

Aleksander Nowodzinski 9 年之前
父节点
当前提交
89fcea4bbf
共有 2 个文件被更改,包括 20 次插入7 次删除
  1. 12 3
      packages/ckeditor5-engine/src/ui/template.js
  2. 8 4
      packages/ckeditor5-engine/tests/ui/template.js

+ 12 - 3
packages/ckeditor5-engine/src/ui/template.js

@@ -75,11 +75,20 @@ export default class Template {
 	 */
 	_renderNode( def, applyNode, intoFragment ) {
 		const isText = def.text || typeof def == 'string';
+		let isInvalid;
 
-		// !XOR( def.tag, isText )
-		if ( def.tag ? isText : !isText ) {
+		if ( applyNode ) {
+			// When applying, a definition cannot have "tag" and "text" at the same time.
+			isInvalid = def.tag && isText;
+		} else {
+			// When rendering, a definition must have either "tag" or "text": XOR( def.tag, isText ).
+			isInvalid = def.tag ? isText : !isText;
+		}
+
+		if ( isInvalid ) {
 			/**
-			 * Node definition must have either "tag" or "text" property.
+			 * Node definition cannot have "tag" and "text" properties at the same time.
+			 * Node definition must have either "tag" or "text" when rendering new Node.
 			 *
 			 * @error ui-template-wrong-syntax
 			 */

+ 8 - 4
packages/ckeditor5-engine/tests/ui/template.js

@@ -260,10 +260,6 @@ describe( 'Template', () => {
 
 		it( 'throws when wrong template definition', () => {
 			expect( () => {
-				new Template( {} ).apply( el );
-			} ).to.throw( CKEditorError, /ui-template-wrong-syntax/ );
-
-			expect( () => {
 				new Template( {
 					tag: 'p',
 					text: 'foo'
@@ -279,6 +275,14 @@ describe( 'Template', () => {
 			} ).to.throw( CKEditorError, /ui-template-wrong-node/ );
 		} );
 
+		it( 'accepts empty template definition', () => {
+			new Template( {} ).apply( el );
+			new Template( {} ).apply( text );
+
+			expect( el.outerHTML ).to.be.equal( '<div></div>' );
+			expect( text.textContent ).to.be.equal( '' );
+		} );
+
 		it( 'applies textContent to a Text Node', () => {
 			new Template( {
 				text: 'abc'