Clean up API

This commit is contained in:
Dolan
2018-08-07 01:25:28 +01:00
parent ca8f331eec
commit 12c8cb93f6
21 changed files with 95 additions and 49 deletions

View File

@ -97,7 +97,7 @@ export class Compiler {
name: "_rels/.rels",
});
for (const data of this.file.Media.array) {
for (const data of this.file.Media.Array) {
this.archive.append(data.stream, {
name: `word/media/${data.fileName}`,
});

View File

@ -98,12 +98,12 @@ export class File {
sectionPropertiesOptions = {
footerType: FooterReferenceType.DEFAULT,
headerType: HeaderReferenceType.DEFAULT,
headerId: header.Header.referenceId,
footerId: footer.Footer.referenceId,
headerId: header.Header.ReferenceId,
footerId: footer.Footer.ReferenceId,
};
} else {
sectionPropertiesOptions.headerId = header.Header.referenceId;
sectionPropertiesOptions.footerId = footer.Footer.referenceId;
sectionPropertiesOptions.headerId = header.Header.ReferenceId;
sectionPropertiesOptions.footerId = footer.Footer.ReferenceId;
}
this.document = new Document(sectionPropertiesOptions);
}
@ -131,7 +131,7 @@ export class File {
return image;
}
public insertImage(image: Image): File {
public addImage(image: Image): File {
this.document.addParagraph(image);
return this;
}
@ -181,7 +181,7 @@ export class File {
const header = new HeaderWrapper(this.media, this.currentRelationshipId++);
this.headerWrapper.push(header);
this.docRelationships.createRelationship(
header.Header.referenceId,
header.Header.ReferenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
`header${this.headerWrapper.length}.xml`,
);
@ -193,7 +193,7 @@ export class File {
const footer = new FooterWrapper(this.media, this.currentRelationshipId++);
this.footerWrapper.push(footer);
this.docRelationships.createRelationship(
footer.Footer.referenceId,
footer.Footer.ReferenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
`footer${this.footerWrapper.length}.xml`,
);
@ -207,7 +207,7 @@ export class File {
this.document.Body.DefaultSection.addChildElement(
new HeaderReference({
headerType: HeaderReferenceType.FIRST,
headerId: headerWrapper.Header.referenceId,
headerId: headerWrapper.Header.ReferenceId,
}),
);
@ -251,7 +251,7 @@ export class File {
}
public HeaderByRefNumber(refId: number): HeaderWrapper {
const entry = this.headerWrapper.find((h) => h.Header.referenceId === refId);
const entry = this.headerWrapper.find((h) => h.Header.ReferenceId === refId);
if (entry) {
return entry;
}
@ -267,7 +267,7 @@ export class File {
}
public FooterByRefNumber(refId: number): FooterWrapper {
const entry = this.footerWrapper.find((h) => h.Footer.referenceId === refId);
const entry = this.footerWrapper.find((h) => h.Footer.ReferenceId === refId);
if (entry) {
return entry;
}

View File

@ -43,10 +43,10 @@ export class FooterWrapper {
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
`media/${mediaData.fileName}`,
);
this.insertImage(new Image(mediaData));
this.addImage(new Image(mediaData));
}
public insertImage(image: Image): FooterWrapper {
public addImage(image: Image): FooterWrapper {
this.footer.addParagraph(image);
return this;
}

View File

@ -31,7 +31,7 @@ export class Footer extends XmlComponent {
);
}
public get referenceId(): number {
public get ReferenceId(): number {
return this.refId;
}

View File

@ -43,10 +43,10 @@ export class HeaderWrapper {
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
`media/${mediaData.fileName}`,
);
this.insertImage(new Image(mediaData));
this.addImage(new Image(mediaData));
}
public insertImage(image: Image): HeaderWrapper {
public addImage(image: Image): HeaderWrapper {
this.header.addParagraph(image);
return this;
}

View File

@ -31,7 +31,7 @@ export class Header extends XmlComponent {
);
}
public get referenceId(): number {
public get ReferenceId(): number {
return this.refId;
}

View File

@ -120,7 +120,7 @@ export class Media {
return imageData;
}
public get array(): IMediaData[] {
public get Array(): IMediaData[] {
const array = new Array<IMediaData>();
this.map.forEach((data) => {

View File

@ -56,7 +56,7 @@ export class LevelOverride extends XmlComponent {
}
}
public get level(): LevelForOverride {
public get Level(): LevelForOverride {
let lvl: LevelForOverride;
if (!this.lvl) {
lvl = new LevelForOverride(this.levelNum);

View File

@ -387,9 +387,9 @@ describe("concrete numbering", () => {
});
});
it("sets the lvl element if overrideLevel.level is accessed", () => {
it("sets the lvl element if overrideLevel.Level is accessed", () => {
const ol = concreteNumbering.overrideLevel(1);
expect(ol.level).to.be.instanceof(LevelForOverride);
expect(ol.Level).to.be.instanceof(LevelForOverride);
const tree = new Formatter().format(concreteNumbering);
expect(tree["w:num"]).to.include({
"w:lvlOverride": [

View File

@ -22,9 +22,9 @@ describe("TableProperties", () => {
});
});
describe("#fixedWidthLayout", () => {
describe("#setFixedWidthLayout", () => {
it("sets the table to fixed width layout", () => {
const tp = new TableProperties().fixedWidthLayout();
const tp = new TableProperties().setFixedWidthLayout();
const tree = new Formatter().format(tp);
expect(tree).to.deep.equal({
"w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],

View File

@ -12,7 +12,7 @@ export class TableProperties extends XmlComponent {
return this;
}
public fixedWidthLayout(): TableProperties {
public setFixedWidthLayout(): TableProperties {
this.root.push(new TableLayout("fixed"));
return this;
}

View File

@ -186,9 +186,9 @@ describe("Table", () => {
});
});
describe("#fixedWidthLayout", () => {
describe("#setFixedWidthLayout", () => {
it("sets the table to fixed width layout", () => {
const table = new Table(2, 2).fixedWidthLayout();
const table = new Table(2, 2).setFixedWidthLayout();
const tree = new Formatter().format(table);
expect(tree)
.to.have.property("w:tbl")

View File

@ -72,8 +72,8 @@ export class Table extends XmlComponent {
return this;
}
public fixedWidthLayout(): Table {
this.properties.fixedWidthLayout();
public setFixedWidthLayout(): Table {
this.properties.setFixedWidthLayout();
return this;
}
}
@ -94,7 +94,7 @@ export class TableRow extends XmlComponent {
public addGridSpan(ix: number, cellSpan: number): TableCell {
const remainCell = this.cells[ix];
remainCell.cellProperties.addGridSpan(cellSpan);
remainCell.CellProperties.addGridSpan(cellSpan);
this.cells.splice(ix + 1, cellSpan - 1);
this.root.splice(ix + 2, cellSpan - 1);
@ -138,7 +138,7 @@ export class TableCell extends XmlComponent {
return para;
}
public get cellProperties(): TableCellProperties {
public get CellProperties(): TableCellProperties {
return this.properties;
}
}
@ -151,7 +151,7 @@ export class TableCellProperties extends XmlComponent {
this.root.push(this.cellBorder);
}
public get borders(): TableCellBorders {
public get Borders(): TableCellBorders {
return this.cellBorder;
}
@ -167,8 +167,8 @@ export class TableCellProperties extends XmlComponent {
return this;
}
public setVerticalAlign(vAlignType: VerticalAlign): TableCellProperties {
this.root.push(new VAlign(vAlignType));
public setVerticalAlign(type: VerticalAlign): TableCellProperties {
this.root.push(new VAlign(type));
return this;
}

View File

@ -10,7 +10,7 @@ export abstract class BaseXmlComponent {
public abstract prepForXml(): IXmlableObject;
public get isDeleted(): boolean {
public get IsDeleted(): boolean {
return this.deleted;
}
}

View File

@ -14,7 +14,7 @@ export abstract class XmlComponent extends BaseXmlComponent {
const children = this.root
.filter((c) => {
if (c instanceof BaseXmlComponent) {
return !c.isDeleted;
return !c.IsDeleted;
}
return true;
})