added run

This commit is contained in:
Dolan Miu
2016-03-30 03:50:53 +01:00
parent b749e42671
commit a0acb6d1a6
9 changed files with 48 additions and 23 deletions

View File

@ -1,7 +1,7 @@
import {XmlComponent, Attributes} from "../xml-components";
import {ThematicBreak} from "./border";
import {PageBreak} from "./page-break";
import {TextRun} from "./text-run";
import {TextRun} from "../run/text-run";
import {ParagraphProperties} from "./properties";
import {TabStop} from "../tab-stop";
import {Style} from "./style";

View File

@ -1,4 +1,5 @@
import {XmlComponent, Attributes, Run} from "../xml-components";
import {XmlComponent, Attributes} from "../xml-components";
import {Run} from "../run";
class Break implements XmlComponent {
private br: Array<XmlComponent>;

View File

@ -1,11 +0,0 @@
import {Run, Text} from "../xml-components";
import {ParagraphProperties} from "./properties";
export class TextRun extends Run {
constructor(text: string) {
super();
this.r.push(new ParagraphProperties());
this.r.push(new Text(text));
}
}

15
ts/docx/run/index.ts Normal file
View File

@ -0,0 +1,15 @@
import {XmlComponent, Attributes} from "../xml-components";
import {RunProperties} from "./properties";
export class Run implements XmlComponent {
protected r: Array<XmlComponent>;
private properties: RunProperties;
constructor() {
this.r = new Array<XmlComponent>();
this.properties = new RunProperties();
this.r.push(this.properties);
}
}

View File

@ -0,0 +1,9 @@
import {XmlComponent, Attributes} from "../xml-components";
export class RunProperties {
private rPr: Array<XmlComponent>;
constructor() {
this.rPr = new Array<XmlComponent>();
}
}

10
ts/docx/run/text-run.ts Normal file
View File

@ -0,0 +1,10 @@
import {Text} from "../xml-components";
import {Run} from "../run";
export class TextRun extends Run {
constructor(text: string) {
super();
this.r.push(new Text(text));
}
}

View File

@ -22,14 +22,6 @@ export class Attributes implements XmlComponent {
}
}
export class Run implements XmlComponent {
protected r: Array<XmlComponent>;
constructor() {
this.r = new Array<XmlComponent>();
}
}
export class Text implements XmlComponent {
private t: string;

View File

@ -27,5 +27,14 @@ describe('Attribute', () => {
var newJson = JSON.parse(stringifiedJson);
assert(newJson._attrs.val === "test");
});
it("should have space value as defined with populated constructor", () => {
var newAttrs = new Attributes({
space: "spaceTest"
});
var stringifiedJson = JSON.stringify(newAttrs);
var newJson = JSON.parse(stringifiedJson);
assert(newJson._attrs.space === "spaceTest");
});
});
});

View File

@ -90,13 +90,13 @@ describe('Paragraph', () => {
it("should add page break to JSON", () => {
paragraph.pageBreak();
var newJson = jsonify(paragraph);
assert.isDefined(newJson.p[1].pPr[1].r[0].br);
assert.isDefined(newJson.p[1].pPr[1].r[1].br);
});
it("should add page break with 'page' type", () => {
paragraph.pageBreak();
var newJson = jsonify(paragraph);
assert(newJson.p[1].pPr[1].r[0].br[0]._attrs.type === "page");
assert(newJson.p[1].pPr[1].r[1].br[0]._attrs.type === "page");
});
});