From df8ba1e8b8ab6361926f5e85e8c019926303bf85 Mon Sep 17 00:00:00 2001 From: felipe Date: Sun, 12 Mar 2017 21:40:01 +0100 Subject: [PATCH] added alignment methods to paragraph style --- ts/styles/style/index.ts | 20 ++++++++++++++ ts/tests/stylesTest.ts | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/ts/styles/style/index.ts b/ts/styles/style/index.ts index db4b1c1924..41493c9188 100644 --- a/ts/styles/style/index.ts +++ b/ts/styles/style/index.ts @@ -136,6 +136,26 @@ export class ParagraphStyle extends Style { // --------------------- Paragraph formatting ------------------------ // + public center(): ParagraphStyle { + this.addParagraphProperty(new paragraph.Alignment("center")); + return this; + } + + public left(): ParagraphStyle { + this.addParagraphProperty(new paragraph.Alignment("left")); + return this; + } + + public right(): ParagraphStyle { + this.addParagraphProperty(new paragraph.Alignment("right")); + return this; + } + + public justified(): ParagraphStyle { + this.addParagraphProperty(new paragraph.Alignment("both")); + return this; + } + public indent(left: number, hanging?: number): ParagraphStyle { this.addParagraphProperty(new paragraph.Indent(left, hanging)); return this; diff --git a/ts/tests/stylesTest.ts b/ts/tests/stylesTest.ts index 4180d182fd..68eeb6915d 100644 --- a/ts/tests/stylesTest.ts +++ b/ts/tests/stylesTest.ts @@ -212,6 +212,66 @@ describe("ParagraphStyle", () => { ], }); }); + + it("#center", () => { + const style = new ParagraphStyle("myStyleId") + .center(); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": [ + {"w:jc": [{_attr: {"w:val": "center"}}]}, + ]}, + {"w:rPr": []}, + ], + }); + }); + + it("#left", () => { + const style = new ParagraphStyle("myStyleId") + .left(); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": [ + {"w:jc": [{_attr: {"w:val": "left"}}]}, + ]}, + {"w:rPr": []}, + ], + }); + }); + + it("#right", () => { + const style = new ParagraphStyle("myStyleId") + .right(); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": [ + {"w:jc": [{_attr: {"w:val": "right"}}]}, + ]}, + {"w:rPr": []}, + ], + }); + }); + + it("#justified", () => { + const style = new ParagraphStyle("myStyleId") + .justified(); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": [ + {"w:jc": [{_attr: {"w:val": "both"}}]}, + ]}, + {"w:rPr": []}, + ], + }); + }); }); describe("formatting methods: run properties", () => {