Fix linting errors

This commit is contained in:
Dolan
2018-09-07 21:48:59 +01:00
parent 571f8b526b
commit 385ad92331
10 changed files with 88 additions and 75 deletions

View File

@ -59,13 +59,13 @@ export class Compiler {
}
for (const header of file.Headers) {
for (const data of header.media.Array) {
for (const data of header.Media.Array) {
zip.file(`word/media/${data.fileName}`, data.stream);
}
}
for (const footer of file.Footers) {
for (const data of footer.media.Array) {
for (const data of footer.Media.Array) {
zip.file(`word/media/${data.fileName}`, data.stream);
}
}

View File

@ -19,8 +19,8 @@ describe("SectionProperties", () => {
gutter: 0,
space: 708,
linePitch: 360,
headers: [{headerId: 100, headerType: HeaderReferenceType.DEFAULT}],
footers: [{footerId: 200, footerType: FooterReferenceType.EVEN}],
headers: [{ headerId: 100, headerType: HeaderReferenceType.DEFAULT }],
footers: [{ footerId: 200, footerType: FooterReferenceType.EVEN }],
pageNumberStart: 10,
pageNumberFormatType: PageNumberFormat.CARDINAL_TEXT,
});

View File

@ -13,8 +13,13 @@ import { PageSize } from "./page-size/page-size";
import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attributes";
import { TitlePage } from "./title-page/title-page";
type IHeadersOptions = {headers? : IHeaderOptions[]}
type IFootersOptions = {footers? : IFooterOptions[]}
interface IHeadersOptions {
headers?: IHeaderOptions[];
}
interface IFootersOptions {
footers?: IFooterOptions[];
}
export type SectionPropertiesOptions = IPageSizeAttributes &
IPageMarginAttributes &
@ -53,7 +58,7 @@ export class SectionProperties extends XmlComponent {
pageBorderRight: undefined,
pageBorderBottom: undefined,
pageBorderLeft: undefined,
titlePage : true
titlePage: true,
};
const mergedOptions = {
@ -61,7 +66,6 @@ export class SectionProperties extends XmlComponent {
...options,
};
this.root.push(new PageSize(mergedOptions.width, mergedOptions.height, mergedOptions.orientation));
this.root.push(
new PageMargin(
@ -77,7 +81,7 @@ export class SectionProperties extends XmlComponent {
this.root.push(new Columns(mergedOptions.space));
this.root.push(new DocumentGrid(mergedOptions.linePitch));
for (let header of mergedOptions.headers) {
for (const header of mergedOptions.headers) {
this.root.push(
new HeaderReference({
headerType: header.headerType,
@ -86,7 +90,7 @@ export class SectionProperties extends XmlComponent {
);
}
for (let footer of mergedOptions.footers) {
for (const footer of mergedOptions.footers) {
this.root.push(
new FooterReference({
footerType: footer.footerType,

View File

@ -224,32 +224,12 @@ export class File {
return header;
}
private addHeaderToDocument(header: HeaderWrapper, type: HeaderReferenceType = HeaderReferenceType.DEFAULT): void {
this.documentHeaders.push({ header, type });
this.docRelationships.createRelationship(
header.Header.ReferenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
`header${this.documentHeaders.length}.xml`,
);
this.contentTypes.addHeader(this.documentHeaders.length);
}
public createFooter(): FooterWrapper {
const footer = new FooterWrapper(this.currentRelationshipId++);
this.addFooterToDocument(footer);
return footer;
}
private addFooterToDocument(footer: FooterWrapper, type: FooterReferenceType = FooterReferenceType.DEFAULT): void {
this.documentFooters.push({ footer, type });
this.docRelationships.createRelationship(
footer.Footer.ReferenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
`footer${this.documentFooters.length}.xml`,
);
this.contentTypes.addFooter(this.documentFooters.length);
}
public createFirstPageHeader(): HeaderWrapper {
const headerWrapper = this.createHeader();
@ -263,6 +243,42 @@ export class File {
return headerWrapper;
}
public getFooterByRefNumber(refId: number): FooterWrapper {
const entry = this.documentFooters.map((item) => item.footer).find((h) => h.Footer.ReferenceId === refId);
if (entry) {
return entry;
}
throw new Error(`There is no footer with given reference id ${refId}`);
}
public getHeaderByRefNumber(refId: number): HeaderWrapper {
const entry = this.documentHeaders.map((item) => item.header).find((h) => h.Header.ReferenceId === refId);
if (entry) {
return entry;
}
throw new Error(`There is no header with given reference id ${refId}`);
}
private addHeaderToDocument(header: HeaderWrapper, type: HeaderReferenceType = HeaderReferenceType.DEFAULT): void {
this.documentHeaders.push({ header, type });
this.docRelationships.createRelationship(
header.Header.ReferenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
`header${this.documentHeaders.length}.xml`,
);
this.contentTypes.addHeader(this.documentHeaders.length);
}
private addFooterToDocument(footer: FooterWrapper, type: FooterReferenceType = FooterReferenceType.DEFAULT): void {
this.documentFooters.push({ footer, type });
this.docRelationships.createRelationship(
footer.Footer.ReferenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
`footer${this.documentFooters.length}.xml`,
);
this.contentTypes.addFooter(this.documentFooters.length);
}
public get Document(): Document {
return this.document;
}
@ -299,14 +315,6 @@ export class File {
return this.documentHeaders.map((item) => item.header);
}
public HeaderByRefNumber(refId: number): HeaderWrapper {
const entry = this.documentHeaders.map((item) => item.header).find((h) => h.Header.ReferenceId === refId);
if (entry) {
return entry;
}
throw new Error(`There is no header with given reference id ${refId}`);
}
public get Footer(): FooterWrapper {
return this.documentFooters[0].footer;
}
@ -315,14 +323,6 @@ export class File {
return this.documentFooters.map((item) => item.footer);
}
public FooterByRefNumber(refId: number): FooterWrapper {
const entry = this.documentFooters.map((item) => item.footer).find((h) => h.Footer.ReferenceId === refId);
if (entry) {
return entry;
}
throw new Error(`There is no footer with given reference id ${refId}`);
}
public get ContentTypes(): ContentTypes {
return this.contentTypes;
}

View File

@ -1,20 +1,19 @@
import { IMediaData } from "file/media";
import { XmlComponent } from "file/xml-components";
import { Footer } from "./footer/footer";
import { Image, Media } from "./media";
import { ImageParagraph, Paragraph } from "./paragraph";
import { Relationships } from "./relationships";
import { Table } from "./table";
import { IMediaData } from 'file/media';
export class FooterWrapper {
private readonly footer: Footer;
private readonly relationships: Relationships;
public readonly media = new Media();
private readonly media = new Media();
constructor(referenceId: number, initContent? : XmlComponent) {
constructor(referenceId: number, initContent?: XmlComponent) {
this.footer = new Footer(referenceId, initContent);
this.relationships = new Relationships();
}
public addParagraph(paragraph: Paragraph): void {
@ -39,7 +38,7 @@ export class FooterWrapper {
this.footer.addChildElement(childElement);
}
public addImageRelation(image: Buffer, refId : number, width?: number, height?: number) : IMediaData {
public addImageRelation(image: Buffer, refId: number, width?: number, height?: number): IMediaData {
const mediaData = this.media.addMedia(image, refId, width, height);
this.relationships.createRelationship(
refId,
@ -50,11 +49,10 @@ export class FooterWrapper {
}
public createImage(image: Buffer, width?: number, height?: number): void {
let mediaData = this.addImageRelation(image, this.relationships.RelationshipCount, width, height);
const mediaData = this.addImageRelation(image, this.relationships.RelationshipCount, width, height);
this.addImage(new Image(new ImageParagraph(mediaData)));
}
public addImage(image: Image): FooterWrapper {
this.footer.addParagraph(image.Paragraph);
return this;
@ -67,4 +65,8 @@ export class FooterWrapper {
public get Relationships(): Relationships {
return this.relationships;
}
public get Media(): Media {
return this.media;
}
}

View File

@ -7,7 +7,7 @@ import { FooterAttributes } from "./footer-attributes";
export class Footer extends XmlComponent {
private readonly refId: number;
constructor(referenceNumber: number, initContent? : XmlComponent) {
constructor(referenceNumber: number, initContent?: XmlComponent) {
super("w:ftr", initContent);
this.refId = referenceNumber;
this.root.push(

View File

@ -9,7 +9,7 @@ import { Table } from "./table";
export class HeaderWrapper {
private readonly header: Header;
private readonly relationships: Relationships;
public readonly media = new Media();
private readonly media = new Media();
// constructor(private readonly media: Media, referenceId: number, initContent? : XmlComponent) {
constructor(referenceId: number, initContent?: XmlComponent) {
@ -66,4 +66,8 @@ export class HeaderWrapper {
public get Relationships(): Relationships {
return this.relationships;
}
public get Media(): Media {
return this.media;
}
}

View File

@ -23,17 +23,17 @@ export interface IHeaderAttributesProperties {
dcmitype?: string;
xsi?: string;
type?: string;
cx? : string,
cx1? : string,
cx2? : string,
cx3? : string,
cx4? : string,
cx5? : string,
cx6? : string,
cx7? : string,
cx8? : string,
w16cid: string,
w16se: string
cx?: string;
cx1?: string;
cx2?: string;
cx3?: string;
cx4?: string;
cx5?: string;
cx6?: string;
cx7?: string;
cx8?: string;
w16cid: string;
w16se: string;
}
export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesProperties> {
@ -60,7 +60,7 @@ export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesPro
dcmitype: "xmlns:dcmitype",
xsi: "xmlns:xsi",
type: "xsi:type",
cx : "xmlns:cx",
cx: "xmlns:cx",
cx1: "xmlns:cx1",
cx2: "xmlns:cx2",
cx3: "xmlns:cx3",
@ -70,6 +70,6 @@ export class HeaderAttributes extends XmlAttributeComponent<IHeaderAttributesPro
cx7: "xmlns:cx7",
cx8: "xmlns:cx8",
w16cid: "xmlns:w16cid",
w16se: "xmlns:w16se"
w16se: "xmlns:w16se",
};
}

View File

@ -7,8 +7,8 @@ export const parseOptions = {
ignoreAttributes: false,
attributeNamePrefix: "",
attrNodeName: "_attr",
textNodeName: '',
trimValues: false
textNodeName: "",
trimValues: false,
};
/**
@ -59,7 +59,6 @@ export class ImportedXmlComponent extends XmlComponent {
private _attr: any;
constructor(rootKey: string, _attr?: any) {
super(rootKey);
if (_attr) {
this._attr = _attr;

View File

@ -87,7 +87,11 @@ export class ImportDocx {
return templateDocument;
}
public async addImagesToWrapper(relationFile: IRelationFileInfo, zipContent: JSZip, wrapper: HeaderWrapper | FooterWrapper): Promise<void> {
public async addImagesToWrapper(
relationFile: IRelationFileInfo,
zipContent: JSZip,
wrapper: HeaderWrapper | FooterWrapper,
): Promise<void> {
let wrapperImagesReferences: IRelationFileInfo[] = [];
const refFile = zipContent.files[`word/_rels/${relationFile.targetFile}.rels`];
if (refFile) {