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

Commit

Permalink
Refactor and add docs for styles processing rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Jan 15, 2020
1 parent 6535fc2 commit a70c8ff
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/view/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export default class Element extends Node {
* For an element with style set to: 'margin:1px
*
* // Enable 'margin' shorthand processing:
* editor.editing.view.document.addStyleProcessorRules( addMarginStylesProcessor );
* editor.editing.view.document.addStyleProcessorRules( addMarginRules );
*
* const element = view.change( writer => {
* const element = writer.createElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/**
* @module engine/view/styles/background
*/

import { isAttachment, isColor, isPosition, isRepeat, isURL } from './utils';

/**
* @module engine/view/styles
* Adds a background CSS styles processing rules.
*
* editor.editing.view.document.addStyleProcessorRules( addBackgroundRules );
*
* @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor
*/

export function addBackgroundStylesProcessor( stylesProcessor ) {
export function addBackgroundRules( stylesProcessor ) {
stylesProcessor.setNormalizer( 'background', normalizeBackground );
stylesProcessor.setNormalizer( 'background-color', value => ( { path: 'background.color', value } ) );
stylesProcessor.setReducer( 'background', value => {
Expand Down
13 changes: 10 additions & 3 deletions src/view/styles/borderstyles.js → src/view/styles/border.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/**
* @module engine/view/styles/border
*/

import { getShorthandValues, getTopRightBottomLeftValueReducer, getTopRightBottomLeftValues, isLength, isLineStyle } from './utils';

/**
* @module engine/view/styles/borderstyle
* Adds a border CSS styles processing rules.
*
* editor.editing.view.document.addStyleProcessorRules( addBorderRules );
*
* @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor
*/

export function addBorderStylesProcessor( stylesProcessor ) {
export function addBorderRules( stylesProcessor ) {
stylesProcessor.setNormalizer( 'border', borderNormalizer );

// Border-position shorthands.
Expand Down
13 changes: 10 additions & 3 deletions src/view/styles/marginstyles.js → src/view/styles/margin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/**
* @module engine/view/styles/margin
*/

import { getPositionShorthandNormalizer, getTopRightBottomLeftValueReducer } from './utils';

/**
* @module engine/view/styles
* Adds a margin CSS styles processing rules.
*
* editor.editing.view.document.addStyleProcessorRules( addMarginRules );
*
* @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor
*/

export function addMarginStylesProcessor( stylesProcessor ) {
export function addMarginRules( stylesProcessor ) {
stylesProcessor.setNormalizer( 'margin', getPositionShorthandNormalizer( 'margin' ) );

stylesProcessor.setNormalizer( 'margin-top', value => ( { path: 'margin.top', value } ) );
Expand Down
13 changes: 10 additions & 3 deletions src/view/styles/paddingstyles.js → src/view/styles/padding.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/**
* @module engine/view/styles/padding
*/

import { getPositionShorthandNormalizer, getTopRightBottomLeftValueReducer } from './utils';

/**
* @module engine/view/styles
* Adds a margin CSS styles processing rules.
*
* editor.editing.view.document.addStyleProcessorRules( addPaddingRules );
*
* @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor
*/

export function addPaddingStylesProcessor( stylesProcessor ) {
export function addPaddingRules( stylesProcessor ) {
stylesProcessor.setNormalizer( 'padding', getPositionShorthandNormalizer( 'padding' ) );
stylesProcessor.setNormalizer( 'padding-top', value => ( { path: 'padding.top', value } ) );
stylesProcessor.setNormalizer( 'padding-right', value => ( { path: 'padding.right', value } ) );
Expand Down
12 changes: 6 additions & 6 deletions src/view/stylesmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class StylesMap {
* *Note:* This check supports normalized style names.
*
* // Enable 'margin' shorthand processing:
* editor.editing.view.document.addStyleProcessorRules( addMarginStylesProcessor );
* editor.editing.view.document.addStyleProcessorRules( addMarginRules );
*
* styles.setTo( 'margin:2px;' );
*
Expand Down Expand Up @@ -142,7 +142,7 @@ export default class StylesMap {
* *Note:* This method supports normalized styles if defined.
*
* // Enable 'margin' shorthand processing:
* editor.editing.view.document.addStyleProcessorRules( addMarginStylesProcessor );
* editor.editing.view.document.addStyleProcessorRules( addMarginRules );
*
* styles.set( 'margin', '2px' );
*
Expand Down Expand Up @@ -185,7 +185,7 @@ export default class StylesMap {
* *Note:* This method supports normalized styles if defined.
*
* // Enable 'margin' shorthand processing:
* editor.editing.view.document.addStyleProcessorRules( addMarginStylesProcessor );
* editor.editing.view.document.addStyleProcessorRules( addMarginRules );
*
* styles.setTo( 'margin:1px' );
*
Expand All @@ -205,7 +205,7 @@ export default class StylesMap {
* Returns a normalized style object or a single value.
*
* // Enable 'margin' shorthand processing:
* editor.editing.view.document.addStyleProcessorRules( addMarginStylesProcessor );
* editor.editing.view.document.addStyleProcessorRules( addMarginRules );
*
* const styles = new Styles();
* styles.setTo( 'margin:1px 2px 3em;' );
Expand Down Expand Up @@ -242,7 +242,7 @@ export default class StylesMap {
* *Note:* This method supports normalized styles if defined.
*
* // Enable 'margin' shorthand processing:
* editor.editing.view.document.addStyleProcessorRules( addMarginStylesProcessor );
* editor.editing.view.document.addStyleProcessorRules( addMarginRules );
*
* styles.set( 'margin' , '1px' );
* styles.set( 'background', '#f00' );
Expand All @@ -269,7 +269,7 @@ export default class StylesMap {
* Returns property as a value string or undefined if property is not set.
*
* // Enable 'margin' shorthand processing:
* editor.editing.view.document.addStyleProcessorRules( addMarginStylesProcessor );
* editor.editing.view.document.addStyleProcessorRules( addMarginRules );
*
* const styles = new Styles();
* styles.setTo( 'margin:1px;' );
Expand Down
4 changes: 2 additions & 2 deletions tests/view/styles/backgroundstyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/

import StylesMap, { StylesProcessor } from '../../../src/view/stylesmap';
import { addBackgroundStylesProcessor } from '../../../src/view/styles/backgroundstyles';
import { addBackgroundRules } from '../../../src/view/styles/background';

describe( 'Background styles normalization', () => {
let styles;

before( () => {
const stylesProcessor = new StylesProcessor();
StylesMap._setProcessor( stylesProcessor );
addBackgroundStylesProcessor( stylesProcessor );
addBackgroundRules( stylesProcessor );
} );

beforeEach( () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/view/styles/borderstyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/

import StylesMap, { StylesProcessor } from '../../../src/view/stylesmap';
import { addBorderStylesProcessor } from '../../../src/view/styles/borderstyles';
import { addBorderRules } from '../../../src/view/styles/border';

describe( 'Border styles normalization', () => {
let styles;

before( () => {
const stylesProcessor = new StylesProcessor();
StylesMap._setProcessor( stylesProcessor );
addBorderStylesProcessor( stylesProcessor );
addBorderRules( stylesProcessor );
} );

beforeEach( () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/view/styles/marginstyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/

import StylesMap, { StylesProcessor } from '../../../src/view/stylesmap';
import { addMarginStylesProcessor } from '../../../src/view/styles/marginstyles';
import { addMarginRules } from '../../../src/view/styles/margin';

describe( 'Margin styles normalizer', () => {
let styles;

before( () => {
const stylesProcessor = new StylesProcessor();
StylesMap._setProcessor( stylesProcessor );
addMarginStylesProcessor( stylesProcessor );
addMarginRules( stylesProcessor );
} );

beforeEach( () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/view/styles/paddingstyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/

import StylesMap, { StylesProcessor } from '../../../src/view/stylesmap';
import { addPaddingStylesProcessor } from '../../../src/view/styles/paddingstyles';
import { addPaddingRules } from '../../../src/view/styles/padding';

describe( 'Padding styles normalization', () => {
let styles;

before( () => {
const stylesProcessor = new StylesProcessor();
StylesMap._setProcessor( stylesProcessor );
addPaddingStylesProcessor( stylesProcessor );
addPaddingRules( stylesProcessor );
} );

beforeEach( () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/view/stylesmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import StylesMap, { StylesProcessor } from '../../src/view/stylesmap';
import encodedImage from './_utils/encodedimage.txt';
import { addPaddingStylesProcessor } from '../../src/view/styles/paddingstyles';
import { addPaddingRules } from '../../src/view/styles/padding';
import { getTopRightBottomLeftValueReducer } from '../../src/view/styles/utils';

describe( 'StylesMap', () => {
Expand All @@ -25,7 +25,7 @@ describe( 'StylesMap', () => {
} ) );
stylesProcessor.setReducer( 'foo', getTopRightBottomLeftValueReducer( 'foo' ) );

addPaddingStylesProcessor( stylesProcessor );
addPaddingRules( stylesProcessor );
StylesMap._setProcessor( stylesProcessor );
stylesMap = new StylesMap();
} );
Expand Down

0 comments on commit a70c8ff

Please sign in to comment.