fixed all tslint errors

This commit is contained in:
Dolan Miu
2016-05-26 15:08:34 +01:00
parent f075d3b719
commit a2284df881
42 changed files with 253 additions and 254 deletions

View File

@ -5,11 +5,11 @@ export class Body extends XmlComponent {
constructor() {
super("w:body");
//this.root.push(new SectionProperties()); not actually needed
// this.root.push(new SectionProperties()); not actually needed
}
push(component: XmlComponent) {
//this.root.splice(this.body.length - 1, 0, component);
// this.root.splice(this.body.length - 1, 0, component);
this.root.push(component);
}
}

View File

@ -54,8 +54,8 @@ export class DocumentAttributes extends XmlAttributeComponent {
xsi: "xmlns:xsi",
type: "xsi:type"
}, properties);
this.root = properties
this.root = properties;
if (!properties) {
this.root = {};

View File

@ -1,5 +1,5 @@
import {XmlComponent} from "../xml-components";
import {DocumentAttributes} from "./document-attributes"
import {DocumentAttributes} from "./document-attributes";
import {Body} from "./body";
import {Paragraph} from "../paragraph";
@ -34,7 +34,7 @@ export class Document extends XmlComponent {
addParagraph(paragraph: Paragraph): void {
this.body.push(paragraph);
}
clearVariables(): void {
this.body.clearVariables();
delete this.body;

View File

@ -14,7 +14,7 @@ class Border extends XmlComponent {
}
export class ThematicBreak extends XmlComponent {
constructor() {
super("w:pBdr");
this.root.push(new Border());

View File

@ -98,9 +98,9 @@ export class Paragraph extends XmlComponent {
this.properties.push(new MaxRightTabStop());
return this;
}
leftTabStop(position: number): Paragraph {
this.properties.push(new LeftTabStop(position))
this.properties.push(new LeftTabStop(position));
return this;
}

View File

@ -2,7 +2,7 @@ import {XmlComponent, Attributes} from "../xml-components";
import {Style} from "./style";
export class NumberProperties extends XmlComponent {
constructor() {
super("w:numPr");
this.root.push(new IndentLevel(0));

View File

@ -1,7 +1,7 @@
import {XmlComponent, Attributes} from "../xml-components";
export class Bold extends XmlComponent {
constructor() {
super("w:b");
this.root.push(new Attributes({
@ -20,7 +20,7 @@ export class Italics extends XmlComponent {
}
}
// needs work. add more types of underline
// TODO needs work. add more types of underline
export class Underline extends XmlComponent {
constructor() {
@ -121,7 +121,7 @@ export class Size extends XmlComponent {
}
}
// needs work. Add more types of vertical align
// TODO needs work. Add more types of vertical align
export class VerticalAlign extends XmlComponent {
constructor() {

View File

@ -4,7 +4,7 @@ import {Bold, Italics, Underline} from "./formatting";
export class Run extends XmlComponent {
private properties: RunProperties;
constructor() {
super("w:r");
@ -26,12 +26,12 @@ export class Run extends XmlComponent {
this.properties.push(new Underline());
return this;
}
break(): Run {
// TODO
return this;
}
tab(): Run {
// TODO
return this;

View File

@ -9,7 +9,7 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent {
super("_attr");
this.xmlKeys = xmlKeys;
this.root = properties
this.root = properties;
if (!properties) {
this.root = {};
@ -19,7 +19,7 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent {
replaceKey(): void {
if (this.root !== undefined) {
_.forOwn(this.root, (value, key) => {
var newKey = this.xmlKeys[key];
let newKey = this.xmlKeys[key];
this.root[newKey] = value;
delete this.root[key];
});

View File

@ -10,8 +10,8 @@ export abstract class XmlComponent extends BaseXmlComponent {
}
replaceKey(): void {
//console.log(this.rootKey);
//console.log(this.root);
// console.log(this.rootKey);
// console.log(this.root);
if (this.root !== undefined) {
this.root.forEach(root => {
if (root && root instanceof BaseXmlComponent) {

View File

@ -1,4 +1,4 @@
import {XmlComponent} from "./"
import {XmlComponent} from "./";
import {ParagraphProperties} from "../paragraph/properties";
import {RunProperties} from "../run/properties";
@ -42,7 +42,7 @@ export class MultiPropertyXmlComponent extends XmlComponent {
super(rootKey);
this.runProperties = new RunProperties();
this.root.push(this.runProperties);
this.paragraphProperties = new ParagraphProperties();
this.root.push(this.paragraphProperties);
}

View File

@ -6,8 +6,8 @@ export class Formatter {
format(input: any): Object {
input.clearVariables();
this.replaceKeys(input);
var newJson = this.clense(input);
//console.log(JSON.stringify(newJson, null, " "));
let newJson = this.clense(input);
// console.log(JSON.stringify(newJson, null, " "));
return newJson;
}
@ -18,7 +18,7 @@ export class Formatter {
}
private clense(input: any): Object {
var newJson = this.jsonify(input);
let newJson = this.jsonify(input);
this.deepTraverseJson(newJson, (parent, value, key) => {
if (key === "properties") {
@ -36,13 +36,13 @@ export class Formatter {
}
private jsonify(obj: Object): Object {
var stringifiedJson = JSON.stringify(obj);
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
private deepTraverseJson(json: Object, lambda: (json: any, value: any, key: any) => void): void {
_.forOwn(json, (value, key) => {
if (_.isObject(value) && key !== "xmlKeys" && key != "rootKey") {
if (_.isObject(value) && key !== "xmlKeys" && key !== "rootKey") {
this.deepTraverseJson(value, lambda);
}
lambda(json, value, key);

View File

@ -3,7 +3,7 @@ import * as fs from "fs";
import * as express from "express";
import {Document} from "../../docx/document";
import {Properties} from "../../properties";
import {DefaultStylesFactory} from "../../styles/factory"
import {DefaultStylesFactory} from "../../styles/factory";
import {Numbering} from "../../numbering";
export class ExpressPacker extends Packer {
@ -11,8 +11,8 @@ export class ExpressPacker extends Packer {
constructor(document: Document, res: express.Response, styles?: any, properties?: Properties, numbering?: Numbering) {
if (!styles) {
var stylesFactory = new DefaultStylesFactory();
styles = stylesFactory.newInstance()
let stylesFactory = new DefaultStylesFactory();
styles = stylesFactory.newInstance();
}
if (!properties) {
@ -22,7 +22,7 @@ export class ExpressPacker extends Packer {
lastModifiedBy: "Shan Fu"
});
}
if (!numbering) {
numbering = new Numbering();
}
@ -30,8 +30,8 @@ export class ExpressPacker extends Packer {
super(document, styles, properties, numbering);
this.res = res;
this.res.on('close', () => {
return res.status(200).send('OK').end();
this.res.on("close", () => {
return res.status(200).send("OK").end();
});
}

View File

@ -1,23 +1,23 @@
import {Packer} from "./packer";
import * as fs from 'fs';
import * as fs from "fs";
import {Document} from "../../docx/document";
import {Properties} from "../../properties";
import {Numbering} from "../../numbering";
export class LocalPacker extends Packer {
private stream: fs.WriteStream
private stream: fs.WriteStream;
constructor(document: Document, style: any, properties: Properties, path: string, numbering?: Numbering) {
if (!numbering) {
numbering = new Numbering();
}
super(document, style, properties, numbering);
this.stream = fs.createWriteStream(path);
}
pack(): void {
super.pack(this.stream);
}
pack(): void {
super.pack(this.stream);
}
}

View File

@ -7,7 +7,7 @@ import {Styles} from "../../styles";
import {Properties} from "../../properties";
import {Numbering} from "../../numbering";
var appRoot = require('app-root-path');
let appRoot = require("app-root-path");
export abstract class Packer {
protected archive: any;
@ -16,7 +16,7 @@ export abstract class Packer {
private style: Styles;
private properties: Properties;
private numbering: Numbering;
constructor(document: Document, style: any, properties: Properties, numbering: Numbering) {
this.formatter = new Formatter();
this.document = document;
@ -25,7 +25,7 @@ export abstract class Packer {
this.numbering = numbering;
this.archive = archiver.create("zip", {});
this.archive.on('error', (err) => {
this.archive.on("error", (err) => {
throw err;
});
}
@ -37,39 +37,39 @@ export abstract class Packer {
{
expand: true,
cwd: appRoot.path + "/template",
src: ['**', '**/.rels']
src: ["**", "**/.rels"]
}
]);
//this.archive.file(appRoot.path + "/template/[Content_Types].xml", { name: "[Content_Types].xml" });
//console.log(__dirname + "/packer.js");
//this.archive.file(__dirname + "/packer.js", { name: "/[Content_Types].xml" });
// this.archive.file(appRoot.path + "/template/[Content_Types].xml", { name: "[Content_Types].xml" });
// console.log(__dirname + "/packer.js");
// this.archive.file(__dirname + "/packer.js", { name: "/[Content_Types].xml" });
/*this.archive.directory(appRoot.path + "/template", {
name: "/root/g.txt",
prefix: "root"
});*/
var xmlDocument = xml(this.formatter.format(this.document));
var xmlStyles = xml(this.formatter.format(this.style));
var xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: 'yes', encoding: 'UTF-8' } });
var xmlNumbering = xml(this.formatter.format(this.numbering));
//console.log(JSON.stringify(this.numbering, null, " "));
console.log(xmlNumbering);
let xmlDocument = xml(this.formatter.format(this.document));
let xmlStyles = xml(this.formatter.format(this.style));
let xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: "yes", encoding: "UTF-8" } });
let xmlNumbering = xml(this.formatter.format(this.numbering));
// console.log(JSON.stringify(this.numbering, null, " "));
console.log(xmlNumbering);
this.archive.append(xmlDocument, {
name: 'word/document.xml'
name: "word/document.xml"
});
this.archive.append(xmlStyles, {
name: 'word/styles.xml'
name: "word/styles.xml"
});
this.archive.append(xmlProperties, {
name: 'docProps/core.xml'
name: "docProps/core.xml"
});
this.archive.append(xmlNumbering, {
name: 'word/numbering.xml'
})
name: "word/numbering.xml"
});
this.archive.finalize();
}

View File

@ -5,12 +5,12 @@ import {MultiLevelType} from "./multi-level-type";
import * as _ from "lodash";
interface AbstractNumberingAttributesProperties {
abstractNumId?: Number,
restartNumberingAfterBreak?: Number
abstractNumId?: number;
restartNumberingAfterBreak?: number;
}
class AbstractNumberingAttributes extends XmlAttributeComponent {
constructor(properties: AbstractNumberingAttributesProperties) {
super({
abstractNumId: "w:abstractNumId",
@ -29,11 +29,11 @@ export class AbstractNumbering extends XmlComponent {
}));
this.root.push(new MultiLevelType("hybridMultilevel"));
}
addLevel(level: Level): void {
this.root.push(level);
}
clearVariables() {
_.forEach(this.root, element => {
element.clearVariables();

View File

@ -1,12 +1,12 @@
import {XmlComponent, XmlAttributeComponent} from "../docx/xml-components";
interface IndentAttributesProperties {
left: number;
hanging: number;
left: number;
hanging: number;
}
class IndentAttributes extends XmlAttributeComponent {
constructor(properties: IndentAttributesProperties) {
super({
left: "w:left",
@ -16,7 +16,7 @@ class IndentAttributes extends XmlAttributeComponent {
}
export class Indent extends XmlComponent {
constructor(left: number, hanging: number) {
super("w:ind");
this.root.push(new IndentAttributes({

View File

@ -1,5 +1,5 @@
import {MultiPropertyXmlComponent} from "../docx/xml-components";
import {DocumentAttributes} from "../docx/document/document-attributes"
import {DocumentAttributes} from "../docx/document/document-attributes";
import {AbstractNumbering} from "./abstract-numbering";
import {Level} from "./level";
import {Indent} from "./indent";
@ -8,7 +8,7 @@ import {Num} from "./num";
import * as _ from "lodash";
export class Numbering extends MultiPropertyXmlComponent {
constructor() {
super("w:numbering");
this.root.push(new DocumentAttributes({
@ -30,58 +30,58 @@ export class Numbering extends MultiPropertyXmlComponent {
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
Ignorable: "w14 w15 wp14"
}));
var abstractNumbering = new AbstractNumbering(0);
var level0 = new Level(0, "bullet", "", "left");
let abstractNumbering = new AbstractNumbering(0);
let level0 = new Level(0, "bullet", "", "left");
level0.addParagraphProperty(new Indent(720, 360));
level0.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level0);
var level1 = new Level(1, "bullet", "o", "left");
let level1 = new Level(1, "bullet", "o", "left");
level1.addParagraphProperty(new Indent(1440, 360));
level1.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.addLevel(level1);
var level2 = new Level(2, "bullet", "", "left");
let level2 = new Level(2, "bullet", "", "left");
level2.addParagraphProperty(new Indent(2160, 360));
level2.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.addLevel(level2);
var level3 = new Level(3, "bullet", "", "left");
let level3 = new Level(3, "bullet", "", "left");
level3.addParagraphProperty(new Indent(2880, 360));
level3.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level3);
var level4 = new Level(4, "bullet", "o", "left");
let level4 = new Level(4, "bullet", "o", "left");
level4.addParagraphProperty(new Indent(3600, 360));
level4.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.addLevel(level4);
var level5 = new Level(5, "bullet", "", "left");
let level5 = new Level(5, "bullet", "", "left");
level5.addParagraphProperty(new Indent(4320, 360));
level5.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.addLevel(level5);
var level6 = new Level(6, "bullet", "", "left");
let level6 = new Level(6, "bullet", "", "left");
level6.addParagraphProperty(new Indent(5040, 360));
level6.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.addLevel(level6);
var level7 = new Level(4, "bullet", "o", "left");
let level7 = new Level(4, "bullet", "o", "left");
level7.addParagraphProperty(new Indent(5760, 360));
level7.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.addLevel(level7);
var level8 = new Level(5, "bullet", "", "left");
let level8 = new Level(5, "bullet", "", "left");
level8.addParagraphProperty(new Indent(6480, 360));
level8.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.addLevel(level8);
this.root.push(abstractNumbering);
this.root.push(new Num(1, 0));
}
clearVariables() {
super.clearVariables();
_.forEach(this.root, element => {

View File

@ -4,8 +4,8 @@ import {RunProperties} from "../docx/run/properties";
import {ParagraphProperties} from "../docx/paragraph/properties";
interface LevelAttributesProperties {
ilvl?: number,
tentative?: number
ilvl?: number;
tentative?: number;
}
class LevelAttributes extends XmlAttributeComponent {

View File

@ -1,7 +1,7 @@
import {XmlComponent, Attributes} from "../docx/xml-components";
export class MultiLevelType extends XmlComponent {
constructor(value: string) {
super("w:multiLevelType");
this.root.push(new Attributes({

View File

@ -1,7 +1,7 @@
import {XmlComponent, Attributes, XmlAttributeComponent} from "../docx/xml-components";
class AbstractNumId extends XmlComponent {
constructor(value: number) {
super("w:abstractNumId");
this.root.push(new Attributes({
@ -11,11 +11,11 @@ class AbstractNumId extends XmlComponent {
}
interface NumAttributesProperties {
numId: number
numId: number;
}
class NumAttributes extends XmlAttributeComponent {
constructor(properties: NumAttributesProperties) {
super({
numId: "w:numId"
@ -24,7 +24,7 @@ class NumAttributes extends XmlAttributeComponent {
}
export class Num extends XmlComponent {
constructor(numId: number, abstractNumId: number) {
super("w:num");
this.root.push(new NumAttributes({

View File

@ -1,13 +1,13 @@
import {XmlComponent, XmlAttributeComponent} from "../docx/xml-components";
interface RunFontAttributesProperties {
ascii: string;
hAnsi: string;
hint: string;
ascii: string;
hAnsi: string;
hint: string;
}
class RunFontAttributes extends XmlAttributeComponent {
constructor(properties: RunFontAttributesProperties) {
super({
left: "w:left",
@ -17,7 +17,7 @@ class RunFontAttributes extends XmlAttributeComponent {
}
export class RunFonts extends XmlComponent {
constructor(ascii: string, hint: string) {
super("w:ind");
this.root.push(new RunFontAttributes({

View File

@ -43,7 +43,7 @@ export class Description extends XmlUnitComponent {
}
export class LastModifiedBy extends XmlUnitComponent {
constructor(value: string) {
super("cp:lastModifiedBy");
this.root = value;
@ -54,22 +54,22 @@ export class Revision extends XmlUnitComponent {
constructor(value: string) {
super("cp:revision");
var revision = value;
let revision = value;
this.root = value;
}
}
abstract class DateComponent extends XmlComponent {
protected getCurrentDate(): any {
var date = new Date(),
let date = new Date(),
year = date.getFullYear(),
month = ('0' + (date.getMonth() + 1)).slice(-2),
day = ('0' + date.getDate()).slice(-2),
hours = ('0' + date.getHours()).slice(-2),
minutes = ('0' + date.getMinutes()).slice(-2),
seconds = ('0' + date.getSeconds()).slice(-2);
month = ("0" + (date.getMonth() + 1)).slice(-2),
day = ("0" + date.getDate()).slice(-2),
hours = ("0" + date.getHours()).slice(-2),
minutes = ("0" + date.getMinutes()).slice(-2),
seconds = ("0" + date.getSeconds()).slice(-2);
return year + '-' + month + '-' + day + 'T' + hours + ':' + minutes + ':' + seconds + 'Z';
return year + "-" + month + "-" + day + "T" + hours + ":" + minutes + ":" + seconds + "Z";
}
}

View File

@ -3,10 +3,10 @@ import {ParagraphPropertiesDefaults} from "./paragraph-properties";
import {RunPropertiesDefaults} from "./run-properties";
export class DocumentDefaults extends XmlComponent {
private runPropertiesDefaults: RunPropertiesDefaults;
private paragraphPropertiesDefaults: ParagraphPropertiesDefaults;
constructor() {
super("w:docDefaults");
this.runPropertiesDefaults = new RunPropertiesDefaults();
@ -14,7 +14,7 @@ export class DocumentDefaults extends XmlComponent {
this.root.push(this.runPropertiesDefaults);
this.root.push(this.paragraphPropertiesDefaults);
}
clearVariables(): void {
this.runPropertiesDefaults.clearVariables();
this.paragraphPropertiesDefaults.clearVariables();

View File

@ -5,6 +5,6 @@ export class RunPropertiesDefaults extends XmlComponent {
constructor() {
super("w:rPrDefault");
this.root.push(new RunProperties());
this.root.push(new RunProperties());
}
}

View File

@ -3,7 +3,7 @@ import {DocumentDefaults} from "./defaults";
import {ParagraphPropertiesDefaults} from "./defaults/paragraph-properties";
import {RunPropertiesDefaults} from "./defaults/run-properties";
import {Heading1Style, Heading2Style, TitleStyle, Heading3Style, Heading4Style, Heading5Style, Heading6Style, ListParagraph} from "./style";
//import {StyleAttributes} from "./style/attributes";
// import {StyleAttributes} from "./style/attributes";
import {ParagraphProperties} from "../docx/paragraph/properties";
import {RunProperties} from "../docx/run/properties";
import {Color, Size, Italics} from "../docx/run/formatting";
@ -11,46 +11,46 @@ import {Color, Size, Italics} from "../docx/run/formatting";
export class DefaultStylesFactory {
newInstance(): Styles {
var styles = new Styles();
let styles = new Styles();
styles.push(new DocumentDefaults());
var titleStyle = new TitleStyle();
let titleStyle = new TitleStyle();
titleStyle.addRunProperty(new Size(56));
styles.push(titleStyle);
var heading1Style = new Heading1Style();
let heading1Style = new Heading1Style();
heading1Style.addRunProperty(new Color("2E74B5"));
heading1Style.addRunProperty(new Size(32));
styles.push(heading1Style);
var heading2Style = new Heading2Style();
let heading2Style = new Heading2Style();
heading2Style.addRunProperty(new Color("2E74B5"));
heading2Style.addRunProperty(new Size(26));
styles.push(heading2Style);
var heading3Style = new Heading3Style();
let heading3Style = new Heading3Style();
heading3Style.addRunProperty(new Color("1F4D78"));
heading3Style.addRunProperty(new Size(24));
styles.push(heading3Style);
var heading4Style = new Heading4Style();
let heading4Style = new Heading4Style();
heading4Style.addRunProperty(new Color("2E74B5"));
heading4Style.addRunProperty(new Italics());
styles.push(heading4Style);
var heading5Style = new Heading5Style();
let heading5Style = new Heading5Style();
heading5Style.addRunProperty(new Color("2E74B5"));
styles.push(heading5Style);
var heading6Style = new Heading6Style();
let heading6Style = new Heading6Style();
heading6Style.addRunProperty(new Color("1F4D78"));
styles.push(heading6Style);
var listParagraph = new ListParagraph();
//listParagraph.addParagraphProperty();
let listParagraph = new ListParagraph();
// listParagraph.addParagraphProperty();
styles.push(listParagraph);
//console.log(JSON.stringify(styles, null, " "));
// console.log(JSON.stringify(styles, null, " "));
return styles;
}
}

View File

@ -1,5 +1,5 @@
import {XmlComponent} from "../docx/xml-components";
import {DocumentAttributes} from "../docx/document/document-attributes"
import {DocumentAttributes} from "../docx/document/document-attributes";
import {DocumentDefaults} from "./defaults";
import {LatentStyles} from "./latent-styles";
import {LatentStyleException} from "./latent-styles/exceptions";
@ -16,21 +16,21 @@ export class Styles extends XmlComponent {
w14: "http://schemas.microsoft.com/office/word/2010/wordml",
w15: "http://schemas.microsoft.com/office/word/2012/wordml",
Ignorable: "w14 w15"
}))
//var latentStyles = new LatentStyles();
//latentStyles.push(new LatentStyleException(new LatentStyleExceptionAttributes({
}));
// let latentStyles = new LatentStyles();
// latentStyles.push(new LatentStyleException(new LatentStyleExceptionAttributes({
// name: "Normal"
//})));
//this.root.push(latentStyles);
// })));
// this.root.push(latentStyles);
}
push(style: XmlComponent): void {
this.root.push(style);
}
clearVariables() {
this.root.forEach(element => {
element.clearVariables();
})
});
}
}

View File

@ -2,10 +2,10 @@ import {XmlComponent} from "../../../docx/xml-components";
interface LatentStyleExceptionAttributesProperties {
name?: string;
uiPriority?: string,
qFormat?: string,
semiHidden?: string,
unhideWhenUsed?: string
uiPriority?: string;
qFormat?: string;
semiHidden?: string;
unhideWhenUsed?: string;
}
export class LatentStyleExceptionAttributes extends XmlComponent {
@ -21,7 +21,7 @@ export class LatentStyleExceptionAttributes extends XmlComponent {
constructor(properties?: LatentStyleExceptionAttributesProperties) {
super("_attr");
this._attr = properties
this._attr = properties;
if (!properties) {
this._attr = {};

View File

@ -2,11 +2,11 @@ import {XmlComponent} from "../../docx/xml-components";
import {LatentStyleException} from "./exceptions";
export class LatentStyles extends XmlComponent {
constructor() {
super("w:latentStyles");
}
push(latentException: LatentStyleException): void {
this.root.push(latentException);
}

View File

@ -57,7 +57,7 @@ export class UnhideWhenUsed extends XmlComponent {
}
export class QuickFormat extends XmlComponent {
constructor() {
super("w:qFormat");
}

View File

@ -23,7 +23,7 @@ export class ParagraphStyle extends Style {
constructor(styleId: string) {
var attributes = new StyleAttributes({
let attributes = new StyleAttributes({
type: "paragraph",
styleId: styleId
});
@ -111,7 +111,7 @@ export class Heading6Style extends HeadingStyle {
}
export class ListParagraph extends ParagraphStyle {
constructor() {
super("ListParagraph");
this.root.push(new Name("List Paragraph"));

View File

@ -4,36 +4,36 @@ import {Attributes} from "../docx/xml-components";
import {assert} from "chai";
describe("Attribute", () => {
var attributes: Attributes;
let attributes: Attributes;
beforeEach(() => {
attributes = new Attributes();
});
describe('#constructor()', () => {
describe("#constructor()", () => {
it("should not add val with empty constructor", () => {
var newAttrs = new Attributes();
var stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson);
let newAttrs = new Attributes();
let stringifiedJson = JSON.stringify(newAttrs);
let newJson = JSON.parse(stringifiedJson);
assert.isUndefined(newJson.root.val);
});
it("should have val as defined with populated constructor", () => {
var newAttrs = new Attributes({
let newAttrs = new Attributes({
val: "test"
});
var stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson);
let stringifiedJson = JSON.stringify(newAttrs);
let newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.root.val, "test");
});
it("should have space value as defined with populated constructor", () => {
var newAttrs = new Attributes({
let newAttrs = new Attributes({
space: "spaceTest"
});
var stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson);
let stringifiedJson = JSON.stringify(newAttrs);
let newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.root.space, "spaceTest");
});
});

View File

@ -9,12 +9,12 @@ import {Columns} from "../docx/document/body/columns";
import {DocumentGrid} from "../docx/document/body/doc-grid";
function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj);
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Body", () => {
var body: Body;
let body: Body;
beforeEach(() => {
body = new Body();
@ -28,27 +28,27 @@ describe("Body", () => {
describe("#constructor()", () => {
it("should create the Section Properties", () => {
var newJson = jsonify(body);
let newJson = jsonify(body);
assert.equal(newJson.root[0].rootKey, "w:sectPr");
});
it("should create the Page Size", () => {
var newJson = jsonify(body);
let newJson = jsonify(body);
assert.equal(newJson.root[1].rootKey, "w:pgSz");
});
it("should create the Page Margin", () => {
var newJson = jsonify(body);
let newJson = jsonify(body);
assert.equal(newJson.root[2].rootKey, "w:pgMar");
});
it("should create the Columns", () => {
var newJson = jsonify(body);
let newJson = jsonify(body);
assert.equal(newJson.root[3].rootKey, "w:cols");
});
it("should create the Document Grid", () => {
var newJson = jsonify(body);
let newJson = jsonify(body);
assert.equal(newJson.root[4].rootKey, "w:docGrid");
});
});

View File

@ -4,7 +4,7 @@ import {ThematicBreak} from "../docx/paragraph/border";
import {assert} from "chai";
function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj);
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
@ -13,7 +13,7 @@ describe("Border", () => {
});
describe("ThematicBreak", () => {
var thematicBreak: ThematicBreak;
let thematicBreak: ThematicBreak;
beforeEach(() => {
thematicBreak = new ThematicBreak();
@ -21,8 +21,8 @@ describe("ThematicBreak", () => {
describe("#constructor()", () => {
it("should create a Thematic Break with correct border properties", () => {
var newJson = jsonify(thematicBreak);
var attributes = {
let newJson = jsonify(thematicBreak);
let attributes = {
color: "auto",
space: "1",
val: "single",
@ -30,5 +30,5 @@ describe("ThematicBreak", () => {
};
assert.equal(JSON.stringify(newJson.root[0].root[0].root), JSON.stringify(attributes));
});
})
});
});

View File

@ -4,18 +4,17 @@ import * as docx from "../docx";
import {assert} from "chai";
describe("Document", () => {
var document: docx.Document;
let document: docx.Document;
beforeEach(() => {
document = new docx.Document();
});
describe('#constructor()', () => {
describe("#constructor()", () => {
it("should create valid JSON", () => {
//console.log(JSON.stringify(document, null, " "));
var stringifiedJson = JSON.stringify(document);
var newJson;
let stringifiedJson = JSON.stringify(document);
let newJson;
try {
newJson = JSON.parse(stringifiedJson);

View File

@ -10,70 +10,70 @@ import {Properties} from "../properties";
import {assert} from "chai";
function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj);
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Formatter", () => {
var formatter: Formatter;
let formatter: Formatter;
beforeEach(() => {
formatter = new Formatter();
});
describe('#format()', () => {
describe("#format()", () => {
it("should format simple paragraph", () => {
var paragraph = new docx.Paragraph();
var newJson = formatter.format(paragraph);
let paragraph = new docx.Paragraph();
let newJson = formatter.format(paragraph);
newJson = jsonify(newJson);
assert.isDefined(newJson["w:p"]);
});
it("should remove xmlKeys", () => {
var paragraph = new docx.Paragraph();
var newJson = formatter.format(paragraph);
var stringifiedJson = JSON.stringify(newJson);
let paragraph = new docx.Paragraph();
let newJson = formatter.format(paragraph);
let stringifiedJson = JSON.stringify(newJson);
assert(stringifiedJson.indexOf("xmlKeys") < 0);
});
it("should format simple paragraph with bold text", () => {
var paragraph = new docx.Paragraph();
let paragraph = new docx.Paragraph();
paragraph.addText(new docx.TextRun("test").bold());
var newJson = formatter.format(paragraph);
let newJson = formatter.format(paragraph);
newJson = jsonify(newJson);
assert.isDefined(newJson["w:p"][1]["w:r"][0]["w:rPr"][0]["w:b"][0]["_attr"]["w:val"]);
});
it("should format attributes (rsidSect)", () => {
var attributes = new Attributes({
let attributes = new Attributes({
rsidSect: "test2"
});
var newJson = formatter.format(attributes);
let newJson = formatter.format(attributes);
newJson = jsonify(newJson);
assert.isDefined(newJson["_attr"]["w:rsidSect"]);
});
it("should format attributes (val)", () => {
var attributes = new Attributes({
let attributes = new Attributes({
val: "test"
});
var newJson = formatter.format(attributes);
let newJson = formatter.format(attributes);
newJson = jsonify(newJson);
assert.isDefined(newJson["_attr"]["w:val"]);
});
it("should should change 'p' tag into 'w:p' tag", () => {
var paragraph = new docx.Paragraph();
var newJson = formatter.format(paragraph);
let paragraph = new docx.Paragraph();
let newJson = formatter.format(paragraph);
assert.isDefined(newJson["w:p"]);
});
it("should format Properties object correctly", () => {
var properties = new Properties({
let properties = new Properties({
title: "test document",
creator: "Dolan"
});
var newJson = formatter.format(properties);
let newJson = formatter.format(properties);
newJson = jsonify(newJson);
assert.isDefined(newJson["cp:coreProperties"]);
});

View File

@ -5,35 +5,35 @@
import {LocalPacker} from "../export/packer/local";
import {assert} from "chai";
import {Document} from "../docx/document"
import {Properties} from "../properties"
import {DefaultStyle} from "../styles/sample"
import {Paragraph} from "../docx/paragraph"
import {DefaultStylesFactory} from "../styles/factory"
import {Document} from "../docx/document";
import {Properties} from "../properties";
import {DefaultStyle} from "../styles/sample";
import {Paragraph} from "../docx/paragraph";
import {DefaultStylesFactory} from "../styles/factory";
describe.only("Packer", () => {
var packer: LocalPacker;
var stylesFactory: DefaultStylesFactory;
let packer: LocalPacker;
let stylesFactory: DefaultStylesFactory;
beforeEach(() => {
var document = new Document();
var paragraph = new Paragraph("test text");
var heading = new Paragraph("Hello world").heading1();
let document = new Document();
let paragraph = new Paragraph("test text");
let heading = new Paragraph("Hello world").heading1();
document.addParagraph(new Paragraph("title").title());
document.addParagraph(heading);
document.addParagraph(new Paragraph("heading 2").heading2());
document.addParagraph(paragraph);
var properties = new Properties({
let properties = new Properties({
creator: "Shan Fu",
revision: "1",
lastModifiedBy: "Shan Fu"
});
stylesFactory = new DefaultStylesFactory();
packer = new LocalPacker(document, stylesFactory.newInstance(), properties, "build/tests/test.docx");
//packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.docx");
// packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.docx");
});
describe('#pack()', () => {
describe("#pack()", () => {
it("should create a standard docx file", (done) => {
packer.pack();

View File

@ -4,23 +4,23 @@ import {Style} from "../docx/paragraph/style";
import {assert} from "chai";
function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj);
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("ParagraphStyle", () => {
var style: Style;
let style: Style;
describe("#constructor()", () => {
it("should create a style with given value", () => {
style = new Style("test");
var newJson = jsonify(style);
let newJson = jsonify(style);
assert.equal(newJson.root[0].root.val, "test");
});
it("should create a style with blank val", () => {
style = new Style("");
var newJson = jsonify(style);
let newJson = jsonify(style);
assert.equal(newJson.root[0].root.val, "");
});
});

View File

@ -4,22 +4,22 @@ import * as docx from "../docx";
import {assert} from "chai";
function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj);
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Paragraph", () => {
var paragraph: docx.Paragraph;
let paragraph: docx.Paragraph;
beforeEach(() => {
paragraph = new docx.Paragraph();
});
describe('#constructor()', () => {
describe("#constructor()", () => {
it("should create valid JSON", () => {
var stringifiedJson = JSON.stringify(paragraph);
var newJson;
let stringifiedJson = JSON.stringify(paragraph);
let newJson;
try {
newJson = JSON.parse(stringifiedJson);
@ -30,8 +30,8 @@ describe("Paragraph", () => {
});
it("should create have valid properties", () => {
var stringifiedJson = JSON.stringify(paragraph);
var newJson = JSON.parse(stringifiedJson);
let stringifiedJson = JSON.stringify(paragraph);
let newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.root[0].rootKey, "w:pPr");
});
});
@ -39,7 +39,7 @@ describe("Paragraph", () => {
describe("#heading1()", () => {
it("should add heading style to JSON", () => {
paragraph.heading1();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading1");
});
});
@ -47,7 +47,7 @@ describe("Paragraph", () => {
describe("#heading2()", () => {
it("should add heading style to JSON", () => {
paragraph.heading2();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading2");
});
@ -56,7 +56,7 @@ describe("Paragraph", () => {
describe("#heading3()", () => {
it("should add heading style to JSON", () => {
paragraph.heading3();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "Heading3");
});
@ -65,7 +65,7 @@ describe("Paragraph", () => {
describe("#title()", () => {
it("should add title style to JSON", () => {
paragraph.title();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "Title");
});
@ -74,7 +74,7 @@ describe("Paragraph", () => {
describe("#center()", () => {
it("should add center alignment to JSON", () => {
paragraph.center();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "center");
});
@ -83,7 +83,7 @@ describe("Paragraph", () => {
describe("#thematicBreak()", () => {
it("should add thematic break to JSON", () => {
paragraph.thematicBreak();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].rootKey, "w:pBdr");
});
});
@ -91,13 +91,13 @@ describe("Paragraph", () => {
describe("#pageBreak()", () => {
it("should add page break to JSON", () => {
paragraph.pageBreak();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[1].rootKey, "w:br");
});
it("should add page break with 'page' type", () => {
paragraph.pageBreak();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[1].root[0].root.type, "page");
});
});
@ -105,13 +105,13 @@ describe("Paragraph", () => {
describe("#bullet()", () => {
it("should add list paragraph style to JSON", () => {
paragraph.bullet();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.equal(newJson.root[0].root[1].root[0].root.val, "ListParagraph");
});
it("it should add numbered properties", () => {
paragraph.bullet();
var newJson = jsonify(paragraph);
let newJson = jsonify(paragraph);
assert.isDefined(newJson.root[0].root[2]);
});
});

View File

@ -4,12 +4,12 @@ import {Properties} from "../properties";
import {assert} from "chai";
function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj);
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Properties", () => {
var properties: Properties;
let properties: Properties;
beforeEach(() => {
@ -20,8 +20,8 @@ describe("Properties", () => {
properties = new Properties({
title: "test document"
});
var newJson = jsonify(properties);
let newJson = jsonify(properties);
assert(newJson.root[1].root === "test document");
});
})
});
});

View File

@ -1,54 +1,54 @@
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />
import {Run} from "../docx/run";
import {TextRun} from "../docx//run/text-run"
import {TextRun} from "../docx//run/text-run";
import {assert} from "chai";
function jsonify(obj: Object) {
var stringifiedJson = JSON.stringify(obj);
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe("Run", () => {
var run: Run;
let run: Run;
beforeEach(() => {
run = new Run();
});
describe('#bold()', () => {
describe("#bold()", () => {
it("it should add bold to the properties", () => {
run.bold();
var newJson = jsonify(run);
let newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:b");
});
});
describe('#italic()', () => {
describe("#italic()", () => {
it("it should add italics to the properties", () => {
run.italic();
var newJson = jsonify(run);
let newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:i");
});
});
describe('#underline()', () => {
describe("#underline()", () => {
it("it should add underline to the properties", () => {
run.underline();
var newJson = jsonify(run);
let newJson = jsonify(run);
assert.equal(newJson.root[0].root[0].rootKey, "w:u");
});
});
});
describe('TextRun', () => {
var run: TextRun;
describe("TextRun", () => {
let run: TextRun;
describe('#constructor()', () => {
describe("#constructor()", () => {
it("should add text into run", () => {
run = new TextRun("test");
var newJson = jsonify(run);
let newJson = jsonify(run);
assert.equal(newJson.root[1].root, "test");
});
});

View File

@ -4,19 +4,19 @@ import {Styles} from "../styles";
import {assert} from "chai";
describe("Styles", () => {
var styles: Styles;
let styles: Styles;
beforeEach(() => {
styles = new Styles();
});
describe('#constructor()', () => {
describe("#constructor()", () => {
it("should create styles with correct rootKey", () => {
var styles = new Styles();
var stringifiedJson = JSON.stringify(styles);
var newJson = JSON.parse(stringifiedJson);
let styles = new Styles();
let stringifiedJson = JSON.stringify(styles);
let newJson = JSON.parse(stringifiedJson);
assert.equal(newJson.rootKey, "w:styles");
});
});