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

Commit

Permalink
Renamed singular parameters names to plural.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Piechaczek committed Mar 29, 2018
1 parent 954c0d7 commit ff6d8de
Show file tree
Hide file tree
Showing 14 changed files with 403 additions and 395 deletions.
30 changes: 15 additions & 15 deletions src/conversion/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class Conversion {
* model: 'fancyParagraph',
* view: {
* name: 'p',
* class: 'fancy'
* classes: 'fancy'
* }
* } );
*
Expand All @@ -145,7 +145,7 @@ export default class Conversion {
* 'div',
* {
* // Any element with `display: block` style.
* style: {
* styles: {
* display: 'block'
* }
* }
Expand Down Expand Up @@ -177,7 +177,7 @@ export default class Conversion {
* // Those properties will be "consumed" during conversion.
* // See `engine.view.Matcher~MatcherPattern` and `engine.view.Matcher#match` for more.
*
* return { name: true, style: [ 'font-size' ] };
* return { name: true, styles: [ 'font-size' ] };
* }
*
* return null;
Expand Down Expand Up @@ -220,7 +220,7 @@ export default class Conversion {
* model: 'bold',
* view: {
* name: 'span',
* class: 'bold'
* classes: 'bold'
* }
* } );
*
Expand All @@ -235,13 +235,13 @@ export default class Conversion {
* view: {
* underline: {
* name: 'span',
* style: {
* styles: {
* 'text-decoration': 'underline'
* }
* },
* lineThrough: {
* name: 'span',
* style: {
* styles: {
* 'text-decoration': 'line-through'
* }
* }
Expand All @@ -256,11 +256,11 @@ export default class Conversion {
* 'b',
* {
* name: 'span',
* class: 'bold'
* classes: 'bold'
* },
* {
* name: 'span',
* style: {
* styles: {
* 'font-weight': 'bold'
* }
* },
Expand All @@ -274,7 +274,7 @@ export default class Conversion {
*
* return {
* name: true,
* style: [ 'font-weight' ]
* styles: [ 'font-weight' ]
* };
* }
* }
Expand All @@ -291,13 +291,13 @@ export default class Conversion {
* view: {
* big: {
* name: 'span',
* style: {
* styles: {
* 'font-size': '1.2em'
* }
* },
* small: {
* name: 'span',
* style: {
* styles: {
* 'font-size': '0.8em'
* }
* }
Expand All @@ -323,7 +323,7 @@ export default class Conversion {
* // Those properties will be "consumed" during conversion.
* // See `engine.view.Matcher~MatcherPattern` and `engine.view.Matcher#match` for more.
*
* return { name: true, style: [ 'font-size' ] };
* return { name: true, styles: [ 'font-size' ] };
* }
*
* return null;
Expand All @@ -348,7 +348,7 @@ export default class Conversion {
* // Those properties will be "consumed" during conversion.
* // See `engine.view.Matcher~MatcherPattern` and `engine.view.Matcher#match` for more.
*
* return { name: true, style: [ 'font-size' ] };
* return { name: true, styles: [ 'font-size' ] };
* }
*
* return null;
Expand Down Expand Up @@ -440,12 +440,12 @@ export default class Conversion {
* },
* upcastAlso: {
* right: {
* style: {
* styles: {
* 'text-align': 'right'
* }
* },
* center: {
* style: {
* styles: {
* 'text-align': 'center'
* }
* }
Expand Down
40 changes: 20 additions & 20 deletions src/conversion/downcast-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import cloneDeep from '@ckeditor/ckeditor5-utils/src/lib/lodash/cloneDeep';
* model: 'fancyParagraph',
* view: {
* name: 'p',
* class: 'fancy'
* classes: 'fancy'
* }
* } );
*
Expand Down Expand Up @@ -73,7 +73,7 @@ export function downcastElementToElement( config ) {
* model: 'invert',
* view: {
* name: 'span',
* class: [ 'font-light', 'bg-dark' ]
* classes: [ 'font-light', 'bg-dark' ]
* }
* } );
*
Expand All @@ -85,13 +85,13 @@ export function downcastElementToElement( config ) {
* view: {
* big: {
* name: 'span',
* style: {
* styles: {
* 'font-size': '1.2em'
* }
* },
* small: {
* name: 'span',
* style: {
* styles: {
* 'font-size': '0.8em'
* }
* }
Expand Down Expand Up @@ -244,7 +244,7 @@ export function downcastAttributeToAttribute( config ) {
* model: 'search',
* view: {
* name: 'span',
* attribute: {
* attributes: {
* 'data-marker': 'search'
* }
* }
Expand Down Expand Up @@ -305,9 +305,9 @@ export function downcastMarkerToElement( config ) {
* to a container element, it is the container element instance itself which applies values from highlight descriptor.
* So, in a sense, converter takes care of stating what should be applied on what, while element decides how to apply that.
*
* downcastMarkerToHighlight( { model: 'comment', view: { class: 'comment' } } );
* downcastMarkerToHighlight( { model: 'comment', view: { classes: 'comment' } } );
*
* downcastMarkerToHighlight( { model: 'comment', view: { class: 'new-comment' }, priority: 'high' } );
* downcastMarkerToHighlight( { model: 'comment', view: { classes: 'new-comment' }, priority: 'high' } );
*
* downcastMarkerToHighlight( {
* model: 'comment',
Expand All @@ -316,7 +316,7 @@ export function downcastMarkerToElement( config ) {
* const commentType = data.markerName.split( ':' )[ 1 ];
*
* return {
* class: [ 'comment', 'comment-' + commentType ]
* classes: [ 'comment', 'comment-' + commentType ]
* };
* }
* } );
Expand Down Expand Up @@ -372,24 +372,24 @@ function _createViewElementFromDefinition( viewElementDefinition, viewWriter, vi
let element;

if ( viewElementType == 'container' ) {
element = viewWriter.createContainerElement( viewElementDefinition.name, Object.assign( {}, viewElementDefinition.attribute ) );
element = viewWriter.createContainerElement( viewElementDefinition.name, Object.assign( {}, viewElementDefinition.attributes ) );
} else if ( viewElementType == 'attribute' ) {
element = viewWriter.createAttributeElement( viewElementDefinition.name, Object.assign( {}, viewElementDefinition.attribute ) );
element = viewWriter.createAttributeElement( viewElementDefinition.name, Object.assign( {}, viewElementDefinition.attributes ) );
} else {
// 'ui'.
element = viewWriter.createUIElement( viewElementDefinition.name, Object.assign( {}, viewElementDefinition.attribute ) );
element = viewWriter.createUIElement( viewElementDefinition.name, Object.assign( {}, viewElementDefinition.attributes ) );
}

if ( viewElementDefinition.style ) {
const keys = Object.keys( viewElementDefinition.style );
if ( viewElementDefinition.styles ) {
const keys = Object.keys( viewElementDefinition.styles );

for ( const key of keys ) {
viewWriter.setStyle( key, viewElementDefinition.style[ key ], element );
viewWriter.setStyle( key, viewElementDefinition.styles[ key ], element );
}
}

if ( viewElementDefinition.class ) {
const classes = viewElementDefinition.class;
if ( viewElementDefinition.classes ) {
const classes = viewElementDefinition.classes;

if ( typeof classes == 'string' ) {
viewWriter.addClass( classes, element );
Expand Down Expand Up @@ -638,7 +638,7 @@ export function removeUIElement() {
* The converter automatically consumes corresponding value from consumables list and stops the event (see
* {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}).
*
* modelDispatcher.on( 'attribute:customAttr:myElem', changeAttribute( ( value, data ) => {
* modelDispatcher.on( 'attributes:customAttr:myElem', changeAttribute( ( value, data ) => {
* // Change attribute key from `customAttr` to `class` in view.
* const key = 'class';
* let value = data.attributeNewValue;
Expand Down Expand Up @@ -738,7 +738,7 @@ export function changeAttribute( attributeCreator ) {
* The converter automatically consumes corresponding value from consumables list, stops the event (see
* {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}).
*
* modelDispatcher.on( 'attribute:bold', wrapItem( ( modelAttributeValue, viewWriter ) => {
* modelDispatcher.on( 'attributes:bold', wrapItem( ( modelAttributeValue, viewWriter ) => {
* return viewWriter.createAttributeElement( 'strong' );
* } );
*
Expand Down Expand Up @@ -1000,8 +1000,8 @@ function _prepareDescriptor( highlightDescriptor, data, conversionApi ) {
export function createViewElementFromHighlightDescriptor( descriptor ) {
const viewElement = new ViewAttributeElement( 'span', descriptor.attributes );

if ( descriptor.class ) {
viewElement._addClass( descriptor.class );
if ( descriptor.classes ) {
viewElement._addClass( descriptor.classes );
}

if ( descriptor.priority ) {
Expand Down
6 changes: 3 additions & 3 deletions src/conversion/modelconsumable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import TextProxy from '../model/textproxy';
* during conversion, when given part of model item is converted (i.e. the view element has been inserted into the view,
* but without attributes), consumable value is removed from `ModelConsumable`.
*
* For model items, `ModelConsumable` stores consumable values of one of following types: `insert`, `addAttribute:<attributeKey>`,
* `changeAttribute:<attributeKey>`, `removeAttribute:<attributeKey>`.
* For model items, `ModelConsumable` stores consumable values of one of following types: `insert`, `addattributes:<attributeKey>`,
* `changeattributes:<attributeKey>`, `removeattributes:<attributeKey>`.
*
* In most cases, it is enough to let {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}
* gather consumable values, so there is no need to use
Expand Down Expand Up @@ -312,7 +312,7 @@ export default class ModelConsumable {

// Returns a normalized consumable type name from given string. A normalized consumable type name is a string that has
// at most one colon, for example: `insert` or `addMarker:highlight`. If string to normalize has more "parts" (more colons),
// the other parts are dropped, for example: `addAttribute:bold:$text` -> `addAttribute:bold`.
// the other parts are dropped, for example: `addattributes:bold:$text` -> `addattributes:bold`.
//
// @param {String} type Consumable type.
// @returns {String} Normalized consumable type.
Expand Down
20 changes: 11 additions & 9 deletions src/conversion/upcast-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ import cloneDeep from '@ckeditor/ckeditor5-utils/src/lib/lodash/cloneDeep';
* upcastElementToElement( {
* view: {
* name: 'p',
* class: 'fancy'
* classes: 'fancy'
* },
* model: 'fancyParagraph'
* } );
*
* upcastElementToElement( {
* view: {
* name: 'p',
* class: 'heading'
* classes: 'heading'
* },
* model: ( viewElement, modelWriter ) => {
* return modelWriter.createElement( 'heading', { level: viewElement.getAttribute( 'data-level' ) } );
Expand Down Expand Up @@ -83,15 +83,15 @@ export function upcastElementToElement( config ) {
* upcastElementToAttribute( {
* view: {
* name: 'span',
* class: 'bold'
* classes: 'bold'
* },
* model: 'bold'
* } );
*
* upcastElementToAttribute( {
* view: {
* name: 'span',
* class: [ 'styled', 'styled-dark' ]
* classes: [ 'styled', 'styled-dark' ]
* },
* model: {
* key: 'styled',
Expand All @@ -102,7 +102,7 @@ export function upcastElementToElement( config ) {
* upcastElementToAttribute( {
* view: {
* name: 'span',
* style: {
* styles: {
* 'font-size': /[\s\S]+/
* }
* },
Expand Down Expand Up @@ -250,7 +250,7 @@ export function upcastAttributeToAttribute( config ) {
* upcastElementToMarker( {
* view: {
* name: 'span',
* attribute: {
* attributes: {
* 'data-marker': 'search'
* }
* },
Expand Down Expand Up @@ -397,14 +397,16 @@ function _normalizeViewAttributeKeyValueConfig( config ) {
let normalized;

if ( key == 'class' || key == 'style' ) {
const keyName = key == 'class' ? 'classes' : 'styles';

normalized = {
[ key ]: config.view.value
[ keyName ]: config.view.value
};
} else {
const value = typeof config.view.value == 'undefined' ? /[\s\S]*/ : config.view.value;

normalized = {
attribute: {
attributes: {
[ key ]: value
}
};
Expand Down Expand Up @@ -498,7 +500,7 @@ function _onlyViewNameIsDefined( config ) {
return false;
}

return !config.view.class && !config.view.attribute && !config.view.style;
return !config.view.classes && !config.view.attributes && !config.view.styles;
}

// Helper function for to-model-attribute converter. Sets model attribute on given range. Checks {@link module:engine/model/schema~Schema}
Expand Down
Loading

0 comments on commit ff6d8de

Please sign in to comment.