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

Commit

Permalink
Changed: ViewConverterBuilder#toAttribute now passes `model.Documen…
Browse files Browse the repository at this point in the history
…tFragment` to `data.output` if was converter from view element.
  • Loading branch information
scofalik committed Apr 24, 2017
1 parent 83509df commit 8267b4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/conversion/buildviewconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import Matcher from '../view/matcher';
import ModelDocumentFragment from '../model/documentfragment';
import ModelElement from '../model/element';
import ModelPosition from '../model/position';
import modelWriter from '../model/writer';
Expand Down Expand Up @@ -366,7 +367,8 @@ class ViewConverterBuilder {
// Since we are converting to attribute we need an output on which we will set the attribute.
// If the output is not created yet, we will create it.
if ( !data.output ) {
data.output = conversionApi.convertChildren( data.input, consumable, data );
const children = conversionApi.convertChildren( data.input, consumable, data );
data.output = new ModelDocumentFragment( children );
}

// Use attribute creator function, if provided.
Expand Down
10 changes: 10 additions & 0 deletions tests/conversion/buildviewconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ describe( 'View converter builder', () => {
expect( modelToString( conversionResult ) ).to.equal( '<span transformer="megatron">foo</span>' );
} );

it( 'should return model document fragment when converting attributes on text', () => {
buildViewConverter().for( dispatcher ).fromElement( 'strong' ).toAttribute( 'bold', true );

let viewElement = new ViewAttributeElement( 'strong', null, new ViewText( 'foo' ) );

let conversionResult = dispatcher.convert( viewElement, objWithContext );

expect( conversionResult.is( 'documentFragment' ) ).to.be.true;
} );

it( 'should set different priorities for `toElement` and `toAttribute` conversion', () => {
buildViewConverter().for( dispatcher )
.fromAttribute( 'class' )
Expand Down

0 comments on commit 8267b4c

Please sign in to comment.