diff --git a/ts/docx/paragraph/index.ts b/ts/docx/paragraph/index.ts index 50b9d0a748..dc991b911b 100644 --- a/ts/docx/paragraph/index.ts +++ b/ts/docx/paragraph/index.ts @@ -3,17 +3,9 @@ import {ThematicBreak} from "./border"; import {PageBreak} from "./page-break"; import {TextRun} from "./text-run"; import {ParagraphProperties} from "./properties"; - -class Style { - private pStyle: Array; - - constructor(type: string) { - this.pStyle = new Array(); - this.pStyle.push(new Attributes({ - val: type - })); - } -} +import {TabStop} from "../tab-stop"; +import {Style} from "./style"; +import {NumberProperties} from "./unordered-list"; class Alignment { private jc: Array; @@ -102,4 +94,15 @@ export class Paragraph { this.properties.push(new PageBreak()); return this; } + + addTabStop(tabStop: TabStop) { + this.properties.push(tabStop); + return this; + } + + bullet() { + this.properties.push(new Style("ListParagraph")); + this.properties.push(new NumberProperties()); + return this; + } } \ No newline at end of file diff --git a/ts/docx/paragraph/style.ts b/ts/docx/paragraph/style.ts new file mode 100644 index 0000000000..fa1770c941 --- /dev/null +++ b/ts/docx/paragraph/style.ts @@ -0,0 +1,12 @@ +import {XmlComponent, Attributes} from "../xml-components"; + +export class Style implements XmlComponent { + private pStyle: Array; + + constructor(type: string) { + this.pStyle = new Array(); + this.pStyle.push(new Attributes({ + val: type + })); + } +} \ No newline at end of file diff --git a/ts/docx/paragraph/unordered-list.ts b/ts/docx/paragraph/unordered-list.ts new file mode 100644 index 0000000000..c2f52a5028 --- /dev/null +++ b/ts/docx/paragraph/unordered-list.ts @@ -0,0 +1,34 @@ +import {XmlComponent, Attributes} from "../xml-components"; +import {Style} from "./style"; + +export class NumberProperties implements XmlComponent { + private numPr: Array; + + constructor() { + this.numPr = new Array(); + this.numPr.push(new IndentLevel(0)); + this.numPr.push(new NumberId(1)); + } +} + +export class IndentLevel implements XmlComponent { + private ilvl: Array; + + constructor(level: number) { + this.ilvl = new Array(); + this.ilvl.push(new Attributes({ + val: level + })); + } +} + +export class NumberId implements XmlComponent { + private ilvl: Array; + + constructor(id: number) { + this.ilvl = new Array(); + this.ilvl.push(new Attributes({ + val: id + })); + } +} \ No newline at end of file diff --git a/ts/docx/tab-stop.ts b/ts/docx/tab-stop.ts index 565ecdb7b3..7b7e5de64d 100644 --- a/ts/docx/tab-stop.ts +++ b/ts/docx/tab-stop.ts @@ -1,3 +1,3 @@ - export class TapStop { - - } +export class TabStop { + +} diff --git a/ts/docx/xml-components/index.ts b/ts/docx/xml-components/index.ts index 3f074100ae..ccdea9d198 100644 --- a/ts/docx/xml-components/index.ts +++ b/ts/docx/xml-components/index.ts @@ -3,7 +3,7 @@ export interface XmlComponent { } interface AttributesProperties { - val?: string; + val?: any; color?: string; space?: string; sz?: string; diff --git a/ts/tests/paragraphTest.ts b/ts/tests/paragraphTest.ts index d4adb850d9..281958f9bd 100644 --- a/ts/tests/paragraphTest.ts +++ b/ts/tests/paragraphTest.ts @@ -99,4 +99,18 @@ describe('Paragraph', () => { assert(newJson.p[1].pPr[1].r[0].br[0]._attrs.type === "page"); }); }); + + describe("#bullet()", () => { + it("should add list paragraph style to JSON", () => { + paragraph.bullet(); + var newJson = jsonify(paragraph); + assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "ListParagraph"); + }); + + it("it should add numbered properties", () => { + paragraph.bullet(); + var newJson = jsonify(paragraph); + assert.isDefined(newJson.p[1].pPr[2].numPr); + }); + }); }); \ No newline at end of file diff --git a/ts/tests/styleTest.ts b/ts/tests/styleTest.ts new file mode 100644 index 0000000000..9f46c767a0 --- /dev/null +++ b/ts/tests/styleTest.ts @@ -0,0 +1,28 @@ +/// +/// +import {Style} from "../docx/paragraph/style"; +import {assert} from "chai"; + +function jsonify(obj: Object) { + var stringifiedJson = JSON.stringify(obj); + return JSON.parse(stringifiedJson); +} + +describe("Style", () => { + var style: Style; + + describe("#constructor()", () => { + it("should create a style with given value", () => { + style = new Style("test"); + var newJson = jsonify(style); + assert(newJson.pStyle[0]._attrs.val === "test"); + }); + + it("should create a style with blank val", () => { + style = new Style(""); + var newJson = jsonify(style); + assert(newJson.pStyle[0]._attrs.val === ""); + }); + }); + +}); \ No newline at end of file