Fix spelling of "margin"
This commit is contained in:
73
src/file/table/table-cell/cell-margin/cell-margin.spec.ts
Normal file
73
src/file/table/table-cell/cell-margin/cell-margin.spec.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { BottomCellMargin, LeftCellMargin, RightCellMargin, TopCellMargin } from "./cell-margin";
|
||||
|
||||
describe("TopCellMargin", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should create", () => {
|
||||
const cellMargin = new TopCellMargin(1);
|
||||
const tree = new Formatter().format(cellMargin);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("BottomCellMargin", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should create", () => {
|
||||
const cellMargin = new BottomCellMargin(1);
|
||||
const tree = new Formatter().format(cellMargin);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("LeftCellMargin", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should create", () => {
|
||||
const cellMargin = new LeftCellMargin(1);
|
||||
const tree = new Formatter().format(cellMargin);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:start": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("RightCellMargin", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should create", () => {
|
||||
const cellMargin = new RightCellMargin(1);
|
||||
const tree = new Formatter().format(cellMargin);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:end": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
63
src/file/table/table-cell/cell-margin/cell-margin.ts
Normal file
63
src/file/table/table-cell/cell-margin/cell-margin.ts
Normal file
@ -0,0 +1,63 @@
|
||||
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export interface ICellMarginProperties {
|
||||
readonly type: string;
|
||||
readonly width: number;
|
||||
}
|
||||
|
||||
class CellMarginAttributes extends XmlAttributeComponent<ICellMarginProperties> {
|
||||
protected readonly xmlKeys = { width: "w:w", type: "w:type" };
|
||||
}
|
||||
|
||||
export class TopCellMargin extends XmlComponent {
|
||||
constructor(value: number) {
|
||||
super("w:top");
|
||||
|
||||
this.root.push(
|
||||
new CellMarginAttributes({
|
||||
width: value,
|
||||
type: "dxa",
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class BottomCellMargin extends XmlComponent {
|
||||
constructor(value: number) {
|
||||
super("w:bottom");
|
||||
|
||||
this.root.push(
|
||||
new CellMarginAttributes({
|
||||
width: value,
|
||||
type: "dxa",
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class LeftCellMargin extends XmlComponent {
|
||||
constructor(value: number) {
|
||||
super("w:start");
|
||||
|
||||
this.root.push(
|
||||
new CellMarginAttributes({
|
||||
width: value,
|
||||
type: "dxa",
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class RightCellMargin extends XmlComponent {
|
||||
constructor(value: number) {
|
||||
super("w:end");
|
||||
|
||||
this.root.push(
|
||||
new CellMarginAttributes({
|
||||
width: value,
|
||||
type: "dxa",
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "export/formatter";
|
||||
|
||||
import { TableCellMargin } from "./table-cell-margins";
|
||||
|
||||
describe("TableCellMargin", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should create with default values", () => {
|
||||
const cellMargin = new TableCellMargin({});
|
||||
const tree = new Formatter().format(cellMargin);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcMar": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:end": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:start": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create with values", () => {
|
||||
const cellMargin = new TableCellMargin({
|
||||
top: 5,
|
||||
bottom: 5,
|
||||
left: 5,
|
||||
right: 5,
|
||||
});
|
||||
const tree = new Formatter().format(cellMargin);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:tcMar": [
|
||||
{
|
||||
"w:top": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:end": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:start": {
|
||||
_attr: {
|
||||
"w:type": "dxa",
|
||||
"w:w": 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
21
src/file/table/table-cell/cell-margin/table-cell-margins.ts
Normal file
21
src/file/table/table-cell/cell-margin/table-cell-margins.ts
Normal file
@ -0,0 +1,21 @@
|
||||
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
import { BottomCellMargin, LeftCellMargin, RightCellMargin, TopCellMargin } from "./cell-margin";
|
||||
|
||||
export interface ITableCellMarginOptions {
|
||||
readonly top?: number;
|
||||
readonly left?: number;
|
||||
readonly bottom?: number;
|
||||
readonly right?: number;
|
||||
}
|
||||
|
||||
export class TableCellMargin extends XmlComponent {
|
||||
constructor({ top = 0, left = 0, right = 0, bottom = 0 }: ITableCellMarginOptions) {
|
||||
super("w:tcMar");
|
||||
this.root.push(new TopCellMargin(top));
|
||||
this.root.push(new BottomCellMargin(bottom));
|
||||
this.root.push(new RightCellMargin(right));
|
||||
this.root.push(new LeftCellMargin(left));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user