more listing

This commit is contained in:
Dolan
2017-03-08 21:54:52 +00:00
parent 946a222d37
commit d2f777c4e5
5 changed files with 40 additions and 38 deletions

View File

@ -3,10 +3,10 @@ import {XmlComponent} from "../docx/xml-components";
export class Formatter { export class Formatter {
format(input: any): Object { public format(input: any): Object {
input.clearVariables(); input.clearVariables();
this.replaceKeys(input); this.replaceKeys(input);
let newJson = this.clense(input); const newJson = this.clense(input);
// console.log(JSON.stringify(newJson, null, " ")); // console.log(JSON.stringify(newJson, null, " "));
return newJson; return newJson;
} }
@ -18,7 +18,7 @@ export class Formatter {
} }
private clense(input: any): Object { private clense(input: any): Object {
let newJson = this.jsonify(input); const newJson = this.jsonify(input);
this.deepTraverseJson(newJson, (parent, value, key) => { this.deepTraverseJson(newJson, (parent, value, key) => {
if (key === "properties") { if (key === "properties") {

View File

@ -1,2 +1,2 @@
export {LocalPacker} from "./packer/local"; export { LocalPacker } from "./packer/local";
export {ExpressPacker} from "./packer/express"; export { ExpressPacker } from "./packer/express";

View File

@ -1,9 +1,10 @@
import {Packer} from "./packer";
import * as fs from "fs";
import * as express from "express"; import * as express from "express";
import {Document} from "../../docx/document"; import * as fs from "fs";
import {Properties} from "../../properties"; import { Document } from "../../docx/document";
import {Numbering} from "../../numbering"; import { Numbering } from "../../numbering";
import { Properties } from "../../properties";
import { Packer } from "./packer";
export class ExpressPacker extends Packer { export class ExpressPacker extends Packer {
private res: express.Response; private res: express.Response;
@ -17,8 +18,8 @@ export class ExpressPacker extends Packer {
}); });
} }
pack(name: string): void { public pack(name: string): void {
this.res.attachment(name + ".docx"); this.res.attachment(name + ".docx");
super.pack(this.res); super.pack(this.res);
} }
} }

View File

@ -1,8 +1,9 @@
import {Packer} from "./packer";
import * as fs from "fs"; import * as fs from "fs";
import {Document} from "../../docx/document"; import { Document } from "../../docx/document";
import {Properties} from "../../properties"; import { Numbering } from "../../numbering";
import {Numbering} from "../../numbering"; import { Properties } from "../../properties";
import { Packer } from "./packer";
export class LocalPacker extends Packer { export class LocalPacker extends Packer {
private stream: fs.WriteStream; private stream: fs.WriteStream;
@ -11,8 +12,8 @@ export class LocalPacker extends Packer {
super(document, styles, properties, numbering); super(document, styles, properties, numbering);
} }
pack(path: string): void { public pack(path: string): void {
this.stream = fs.createWriteStream(path); this.stream = fs.createWriteStream(path);
super.pack(this.stream); super.pack(this.stream);
} }
} }

View File

@ -1,19 +1,19 @@
import * as archiver from "archiver"; import * as archiver from "archiver";
import * as fs from "fs"; import * as fs from "fs";
import * as xml from "xml"; import * as xml from "xml";
import {Formatter} from "../formatter"; import { Document } from "../../docx";
import {Document} from "../../docx"; import { Numbering } from "../../numbering";
import {Styles} from "../../styles"; import { Properties } from "../../properties";
import {Properties} from "../../properties"; import { Styles } from "../../styles";
import {Numbering} from "../../numbering"; import { DefaultStylesFactory } from "../../styles/factory";
import {DefaultStylesFactory} from "../../styles/factory"; import { Formatter } from "../formatter";
let appRoot = require("app-root-path"); const appRoot = require("app-root-path");
export abstract class Packer { export abstract class Packer {
protected archive: any; protected archive: any;
private formatter: Formatter;
protected document: Document; protected document: Document;
private formatter: Formatter;
private style: Styles; private style: Styles;
private properties: Properties; private properties: Properties;
private numbering: Numbering; private numbering: Numbering;
@ -27,7 +27,7 @@ export abstract class Packer {
this.archive = archiver.create("zip", {}); this.archive = archiver.create("zip", {});
if (!style) { if (!style) {
let stylesFactory = new DefaultStylesFactory(); const stylesFactory = new DefaultStylesFactory();
this.style = stylesFactory.newInstance(); this.style = stylesFactory.newInstance();
} }
@ -35,7 +35,7 @@ export abstract class Packer {
this.properties = new Properties({ this.properties = new Properties({
creator: "Un-named", creator: "Un-named",
revision: "1", revision: "1",
lastModifiedBy: "Un-named" lastModifiedBy: "Un-named",
}); });
} }
@ -48,7 +48,7 @@ export abstract class Packer {
}); });
} }
pack(output: any): void { public pack(output: any): void {
this.archive.pipe(output); this.archive.pipe(output);
console.log(appRoot.path + "/template"); console.log(appRoot.path + "/template");
this.archive.glob("**", { this.archive.glob("**", {
@ -69,28 +69,28 @@ export abstract class Packer {
name: "/root/g.txt", name: "/root/g.txt",
prefix: "root" prefix: "root"
});*/ });*/
let xmlDocument = xml(this.formatter.format(this.document)); const xmlDocument = xml(this.formatter.format(this.document));
let xmlStyles = xml(this.formatter.format(this.style)); const xmlStyles = xml(this.formatter.format(this.style));
let xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: "yes", encoding: "UTF-8" } }); const xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: "yes", encoding: "UTF-8" } });
let xmlNumbering = xml(this.formatter.format(this.numbering)); const xmlNumbering = xml(this.formatter.format(this.numbering));
// console.log(JSON.stringify(this.numbering, null, " ")); // console.log(JSON.stringify(this.numbering, null, " "));
console.log(xmlNumbering); console.log(xmlNumbering);
this.archive.append(xmlDocument, { this.archive.append(xmlDocument, {
name: "word/document.xml" name: "word/document.xml",
}); });
this.archive.append(xmlStyles, { this.archive.append(xmlStyles, {
name: "word/styles.xml" name: "word/styles.xml",
}); });
this.archive.append(xmlProperties, { this.archive.append(xmlProperties, {
name: "docProps/core.xml" name: "docProps/core.xml",
}); });
this.archive.append(xmlNumbering, { this.archive.append(xmlNumbering, {
name: "word/numbering.xml" name: "word/numbering.xml",
}); });
this.archive.finalize(); this.archive.finalize();
} }
} }