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

T/1295 Further improvements to conversion helpers #1302

Merged
merged 8 commits into from
Feb 19, 2018
Merged

T/1295 Further improvements to conversion helpers #1302

merged 8 commits into from
Feb 19, 2018

Conversation

scofalik
Copy link
Contributor

@scofalik scofalik commented Feb 16, 2018

Suggested merge commit message (convention)

Other: Introduced several improvements to conversion helpers. Closes ckeditor/ckeditor5#4275. Closes ckeditor/ckeditor5#4273. Closes ckeditor/ckeditor5#4272. Closes ckeditor/ckeditor5#4271. Closes ckeditor/ckeditor5#4270. Closes ckeditor/ckeditor5#4280.


Additional information

Basing and waiting for #1296. After #1296 is closed, I'll make PRs in other repositories related to this PR.

… converters do not handle passing element instance.
Fixed: Classes and styles are properly handled in downcast converters.
Docs: Fixed converters docs.
Changed: Support for passing element name in `downcastAttributeToAttribute` converter.
Added: Introduced `conversion.ConverterDefinition` type.
Added: Added priority handling in `conversion.Conversion` converters.
Changed: Cleaned low-level converters after they can receive only element creator function as a parameter.
* Sets up converters between the model and the view which convert a model element to a view element (and vice versa).
* For example, model `<paragraph>Foo</paragraph>` is `<p>Foo</p>` in the view.
*
* `definition.model` is a `String` with a model element name to converter from/to.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put it togheter with the parameter desctription. When it is here, I ask myself why you tell me what model is, but not what view is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's here because in the parameter definition specifies that input parameter is ConverterDefinition. I am not sure if it will be readable if such a long description would be put there.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but users will not know it. You can write that all other parameters are defined in ConverterDefinition, or move it after samples close to the parameter definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will move it lower.

* For example, model text node with data `"Foo"` and `bold` attribute is `<strong>Foo</strong>` in the view.
*
* `definition.model` parameter specifies what model attribute should be converted from/to. It can be a `{ key, value }` object
* describing attribute key and value to convert or a `String` specifying just attribute key (then `value` is set to `true`).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

* 'div',
* {
* // Any element with `display: block` style.
* name: /./,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should improve it, like we did for attributes in https://github.com/ckeditor/ckeditor5-engine/issues/1239. It should be no name in this case.

Copy link
Contributor Author

@scofalik scofalik Feb 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tricky example, actually.

First of all, for Matcher purposes, specifying something like:

{
	name: true,
	class: ...
}

is just stupid, cause the name could be omitted. It says "any name" and every element has a name.

OTOH, the name is in upcast definition intentionally, so that name is returned in a match so it will be consumed.

I think that if we want to improve that, we should add name to matches object (the one returned by Matcher#match) in elementToElement and attributeToElement (so whenever a view element is converted).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I did as described above ☝️

* const size = Number( match[ 1 ] );
*
* if ( size > 26 ) {
* return { name: true, style: [ 'font-size' ] };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a comment that this is information what should be consumed with the link to the full documentation. name: true looks complcated with no explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment might be helpful. I haven't added it cause, AFAIR, it is commented in MatcherPattern description.

*
* if ( viewElement.is( 'span' ) && fontWeight && /\d+/.test() && Number( fontWeight ) > 500 ) {
* return {
* name: true,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

* return null;
* }
* }
* } );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thumbs up for...? :P

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a very nice structure :)

* For example, `<image src='foo.jpg'></image>` is converted to `<img src='foo.jpg'></img>` (same attribute key and value).
*
* `definition.model` parameter specifies what model attribute should be converted from/to.
* It can be a `{ key, values, [ name ] }` object or a `String`, which will be treated like `{ key: definition.model }`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ key, [ values ], [ name ] } (value is optional too)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are at it, I wanted to ask you, whether it is better to name that property values or value (it is always an array).

@scofalik
Copy link
Contributor Author

IDK why this build: https://travis-ci.org/ckeditor/ckeditor5/builds/343343886 is still failing on docs, I've fixed all docs problems and pushed commits and I am clean on my local machine.

# for free to subscribe to this conversation on GitHub. Already have an account? #.