Merge pull request #310 from nickgeorgiou/feat/margin-spelling-fix

Fix spelling of "margin"
This commit is contained in:
Dolan
2019-04-18 17:10:00 +01:00
committed by GitHub
11 changed files with 80 additions and 80 deletions

View File

@ -25,7 +25,7 @@ table = doc.createTable({
table
.getCell(0, 0)
.addParagraph(new Paragraph("World"))
.setMargains({
.setMargins({
top: 1000,
bottom: 1000,
left: 1000,
@ -40,7 +40,7 @@ table = doc.createTable({
columns: 4,
width: 7000,
widthUnitType: WidthType.DXA,
margains: {
margins: {
top: 400,
bottom: 400,
right: 400,

View File

@ -112,7 +112,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.ts_
## Margins
Example showing how to set custom margains
Example showing how to set custom margins
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include')

View File

@ -1,21 +0,0 @@
// http://officeopenxml.com/WPtableCellProperties-Margins.php
import { XmlComponent } from "file/xml-components";
import { BottomCellMargain, LeftCellMargain, RightCellMargain, TopCellMargain } from "./cell-margain";
export interface ITableCellMargainOptions {
readonly top?: number;
readonly left?: number;
readonly bottom?: number;
readonly right?: number;
}
export class TableCellMargain extends XmlComponent {
constructor({ top = 0, left = 0, right = 0, bottom = 0 }: ITableCellMargainOptions) {
super("w:tcMar");
this.root.push(new TopCellMargain(top));
this.root.push(new BottomCellMargain(bottom));
this.root.push(new RightCellMargain(right));
this.root.push(new LeftCellMargain(left));
}
}

View File

@ -2,13 +2,13 @@ import { expect } from "chai";
import { Formatter } from "export/formatter";
import { BottomCellMargain, LeftCellMargain, RightCellMargain, TopCellMargain } from "./cell-margain";
import { BottomCellMargin, LeftCellMargin, RightCellMargin, TopCellMargin } from "./cell-margin";
describe("TopCellMargain", () => {
describe("TopCellMargin", () => {
describe("#constructor", () => {
it("should create", () => {
const cellMargain = new TopCellMargain(1);
const tree = new Formatter().format(cellMargain);
const cellMargin = new TopCellMargin(1);
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({
"w:top": {
_attr: {
@ -21,11 +21,11 @@ describe("TopCellMargain", () => {
});
});
describe("BottomCellMargain", () => {
describe("BottomCellMargin", () => {
describe("#constructor", () => {
it("should create", () => {
const cellMargain = new BottomCellMargain(1);
const tree = new Formatter().format(cellMargain);
const cellMargin = new BottomCellMargin(1);
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({
"w:bottom": {
_attr: {
@ -38,11 +38,11 @@ describe("BottomCellMargain", () => {
});
});
describe("LeftCellMargain", () => {
describe("LeftCellMargin", () => {
describe("#constructor", () => {
it("should create", () => {
const cellMargain = new LeftCellMargain(1);
const tree = new Formatter().format(cellMargain);
const cellMargin = new LeftCellMargin(1);
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({
"w:start": {
_attr: {
@ -55,11 +55,11 @@ describe("LeftCellMargain", () => {
});
});
describe("RightCellMargain", () => {
describe("RightCellMargin", () => {
describe("#constructor", () => {
it("should create", () => {
const cellMargain = new RightCellMargain(1);
const tree = new Formatter().format(cellMargain);
const cellMargin = new RightCellMargin(1);
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({
"w:end": {
_attr: {

View File

@ -1,21 +1,21 @@
// http://officeopenxml.com/WPtableCellProperties-Margins.php
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export interface ICellMargainProperties {
export interface ICellMarginProperties {
readonly type: string;
readonly width: number;
}
class CellMargainAttributes extends XmlAttributeComponent<ICellMargainProperties> {
class CellMarginAttributes extends XmlAttributeComponent<ICellMarginProperties> {
protected readonly xmlKeys = { width: "w:w", type: "w:type" };
}
export class TopCellMargain extends XmlComponent {
export class TopCellMargin extends XmlComponent {
constructor(value: number) {
super("w:top");
this.root.push(
new CellMargainAttributes({
new CellMarginAttributes({
width: value,
type: "dxa",
}),
@ -23,12 +23,12 @@ export class TopCellMargain extends XmlComponent {
}
}
export class BottomCellMargain extends XmlComponent {
export class BottomCellMargin extends XmlComponent {
constructor(value: number) {
super("w:bottom");
this.root.push(
new CellMargainAttributes({
new CellMarginAttributes({
width: value,
type: "dxa",
}),
@ -36,12 +36,12 @@ export class BottomCellMargain extends XmlComponent {
}
}
export class LeftCellMargain extends XmlComponent {
export class LeftCellMargin extends XmlComponent {
constructor(value: number) {
super("w:start");
this.root.push(
new CellMargainAttributes({
new CellMarginAttributes({
width: value,
type: "dxa",
}),
@ -49,12 +49,12 @@ export class LeftCellMargain extends XmlComponent {
}
}
export class RightCellMargain extends XmlComponent {
export class RightCellMargin extends XmlComponent {
constructor(value: number) {
super("w:end");
this.root.push(
new CellMargainAttributes({
new CellMarginAttributes({
width: value,
type: "dxa",
}),

View File

@ -2,13 +2,13 @@ import { expect } from "chai";
import { Formatter } from "export/formatter";
import { TableCellMargain } from "./table-cell-margains";
import { TableCellMargin } from "./table-cell-margins";
describe("TableCellMargain", () => {
describe("TableCellMargin", () => {
describe("#constructor", () => {
it("should create with default values", () => {
const cellMargain = new TableCellMargain({});
const tree = new Formatter().format(cellMargain);
const cellMargin = new TableCellMargin({});
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({
"w:tcMar": [
{
@ -48,13 +48,13 @@ describe("TableCellMargain", () => {
});
it("should create with values", () => {
const cellMargain = new TableCellMargain({
const cellMargin = new TableCellMargin({
top: 5,
bottom: 5,
left: 5,
right: 5,
});
const tree = new Formatter().format(cellMargain);
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({
"w:tcMar": [
{

View 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));
}
}

View File

@ -1,7 +1,7 @@
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
import { ITableShadingAttributesProperties, TableShading } from "../shading";
import { ITableCellMargainOptions, TableCellMargain } from "./cell-margain/table-cell-margains";
import { ITableCellMarginOptions, TableCellMargin } from "./cell-margin/table-cell-margins";
import { GridSpan, TableCellBorders, TableCellWidth, VAlign, VerticalAlign, VMerge, VMergeType, WidthType } from "./table-cell-components";
export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
@ -47,8 +47,8 @@ export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
return this;
}
public addMargains(options: ITableCellMargainOptions): TableCellProperties {
this.root.push(new TableCellMargain(options));
public addMargins(options: ITableCellMarginOptions): TableCellProperties {
this.root.push(new TableCellMargin(options));
return this;
}

View File

@ -4,7 +4,7 @@ import { IXmlableObject, XmlComponent } from "file/xml-components";
import { ITableShadingAttributesProperties } from "../shading";
import { Table } from "../table";
import { ITableCellMargainOptions } from "./cell-margain/table-cell-margains";
import { ITableCellMarginOptions } from "./cell-margin/table-cell-margins";
import { TableCellBorders, VerticalAlign, VMergeType } from "./table-cell-components";
import { TableCellProperties } from "./table-cell-properties";
@ -61,8 +61,8 @@ export class TableCell extends XmlComponent {
return this;
}
public setMargains(margains: ITableCellMargainOptions): TableCell {
this.properties.addMargains(margains);
public setMargins(margins: ITableCellMarginOptions): TableCell {
this.properties.addMargins(margins);
return this;
}

View File

@ -8,43 +8,43 @@ import { TableCellMargin } from "./table-cell-margin";
describe("TableCellMargin", () => {
describe("#constructor", () => {
it("should throw an error if theres no child elements", () => {
const cellMargain = new TableCellMargin();
expect(() => new Formatter().format(cellMargain)).to.throw();
const cellMargin = new TableCellMargin();
expect(() => new Formatter().format(cellMargin)).to.throw();
});
});
describe("#addTopMargin", () => {
it("adds a table cell top margin", () => {
const cellMargain = new TableCellMargin();
cellMargain.addTopMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargain);
const cellMargin = new TableCellMargin();
cellMargin.addTopMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
});
});
describe("#addLeftMargin", () => {
it("adds a table cell left margin", () => {
const cellMargain = new TableCellMargin();
cellMargain.addLeftMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargain);
const cellMargin = new TableCellMargin();
cellMargin.addLeftMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
});
});
describe("#addBottomMargin", () => {
it("adds a table cell bottom margin", () => {
const cellMargain = new TableCellMargin();
cellMargain.addBottomMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargain);
const cellMargin = new TableCellMargin();
cellMargin.addBottomMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
});
});
describe("#addRightMargin", () => {
it("adds a table cell right margin", () => {
const cellMargain = new TableCellMargin();
cellMargain.addRightMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargain);
const cellMargin = new TableCellMargin();
cellMargin.addRightMargin(1234, WidthType.DXA);
const tree = new Formatter().format(cellMargin);
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
});
});

View File

@ -22,8 +22,8 @@ export interface ITableOptions {
readonly width?: number;
readonly widthUnitType?: WidthType;
readonly columnWidths?: number[];
readonly margains?: {
readonly margainUnitType?: WidthType;
readonly margins?: {
readonly marginUnitType?: WidthType;
readonly top?: number;
readonly bottom?: number;
readonly right?: number;
@ -42,7 +42,7 @@ export class Table extends XmlComponent {
width = 100,
widthUnitType = WidthType.AUTO,
columnWidths = Array<number>(columns).fill(100),
margains: { margainUnitType, top, bottom, right, left } = { margainUnitType: WidthType.AUTO, top: 0, bottom: 0, right: 0, left: 0 },
margins: { marginUnitType, top, bottom, right, left } = { marginUnitType: WidthType.AUTO, top: 0, bottom: 0, right: 0, left: 0 },
float,
}: ITableOptions) {
super("w:tbl");
@ -50,10 +50,10 @@ export class Table extends XmlComponent {
this.root.push(this.properties);
this.properties.setBorder();
this.properties.setWidth(width, widthUnitType);
this.properties.CellMargin.addBottomMargin(bottom || 0, margainUnitType);
this.properties.CellMargin.addTopMargin(top || 0, margainUnitType);
this.properties.CellMargin.addLeftMargin(left || 0, margainUnitType);
this.properties.CellMargin.addRightMargin(right || 0, margainUnitType);
this.properties.CellMargin.addBottomMargin(bottom || 0, marginUnitType);
this.properties.CellMargin.addTopMargin(top || 0, marginUnitType);
this.properties.CellMargin.addLeftMargin(left || 0, marginUnitType);
this.properties.CellMargin.addRightMargin(right || 0, marginUnitType);
const grid = new TableGrid(columnWidths);
this.root.push(grid);