From adb4e933ef951ff52ee0198ffcefd699a6d54c30 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Wed, 13 Jul 2016 00:59:53 +0100 Subject: [PATCH] added different types of underline --- ts/docx/run/formatting.ts | 11 --- ts/docx/run/index.ts | 3 +- ts/docx/run/underline.ts | 132 ++++++++++++++++++++++++++++ ts/tests/docx/run/runTest.ts | 2 +- ts/tests/docx/run/underlineTests.ts | 37 ++++++++ 5 files changed, 172 insertions(+), 13 deletions(-) create mode 100644 ts/docx/run/underline.ts create mode 100644 ts/tests/docx/run/underlineTests.ts diff --git a/ts/docx/run/formatting.ts b/ts/docx/run/formatting.ts index c113aa4188..8be2240f18 100644 --- a/ts/docx/run/formatting.ts +++ b/ts/docx/run/formatting.ts @@ -20,17 +20,6 @@ export class Italics extends XmlComponent { } } -// TODO needs work. add more types of underline -export class Underline extends XmlComponent { - - constructor() { - super("w:u"); - this.root.push(new Attributes({ - val: true - })); - } -} - export class Caps extends XmlComponent { constructor() { diff --git a/ts/docx/run/index.ts b/ts/docx/run/index.ts index b0b9b4096f..11c89c594f 100644 --- a/ts/docx/run/index.ts +++ b/ts/docx/run/index.ts @@ -1,11 +1,12 @@ import {XmlComponent, Attributes} from "../xml-components"; import {RunProperties} from "./properties"; -import {Bold, Italics, Underline} from "./formatting"; +import {Bold, Italics} from "./formatting"; import {Tab} from "./tab"; import {Break} from "./break"; import {SmallCaps, Caps} from "./caps"; import {Strike, DoubleStrike} from "./strike"; import {SubScript, SuperScript} from "./script"; +import {Underline} from "./underline" export class Run extends XmlComponent { private properties: RunProperties; diff --git a/ts/docx/run/underline.ts b/ts/docx/run/underline.ts new file mode 100644 index 0000000000..56df04aade --- /dev/null +++ b/ts/docx/run/underline.ts @@ -0,0 +1,132 @@ +import {XmlComponent, Attributes} from "../xml-components"; + +abstract class BaseUnderline extends XmlComponent { + + constructor(underlineType: string, color?: string) { + super("w:u"); + this.root.push(new Attributes({ + val: underlineType, + color: color + })); + } +} + +export class Underline extends BaseUnderline { + + constructor() { + super(""); + } +} + +export class DashUnderline extends BaseUnderline { + + constructor() { + super("dash"); + } +} + +export class DashDotDotHeavyUnderline extends BaseUnderline { + + constructor() { + super("dashDotDotHeavy"); + } +} + +export class DashDotHeavyUnderline extends BaseUnderline { + + constructor() { + super("dashDotHeavy"); + } +} + +export class DashLongUnderline extends BaseUnderline { + + constructor() { + super("dashLong"); + } +} + +export class DashLongHeavyUnderline extends BaseUnderline { + + constructor() { + super("dashLongHeavy"); + } +} + +export class DotDashUnderline extends BaseUnderline { + + constructor() { + super("dotDash"); + } +} + +export class DotDotDashUnderline extends BaseUnderline { + + constructor() { + super("dotDotDash"); + } +} + +export class DottedUnderline extends BaseUnderline { + + constructor() { + super("dotted"); + } +} + +export class DottedHeavyUnderline extends BaseUnderline { + + constructor() { + super("dottedHeavy"); + } +} + +export class DoubleUnderline extends BaseUnderline { + + constructor() { + super("double"); + } +} + + +export class SingleUnderline extends BaseUnderline { + + constructor() { + super("single"); + } +} + +export class ThickUnderline extends BaseUnderline { + + constructor() { + super("thick"); + } +} + +export class WaveUnderline extends BaseUnderline { + + constructor() { + super("wave"); + } +} + +export class WavyDoubleUnderline extends BaseUnderline { + + constructor() { + super("wavyDouble"); + } +} + +export class WavyHeavyUnderline extends BaseUnderline { + + constructor() { + super("wavyHeavy"); + } +} + +export class WordsUnderline extends BaseUnderline { + + constructor() { + super("words"); + } +} \ No newline at end of file diff --git a/ts/tests/docx/run/runTest.ts b/ts/tests/docx/run/runTest.ts index 1dd496c1f3..0a6154b9cf 100644 --- a/ts/tests/docx/run/runTest.ts +++ b/ts/tests/docx/run/runTest.ts @@ -10,7 +10,7 @@ function jsonify(obj: Object) { return JSON.parse(stringifiedJson); } -describe.only("Run", () => { +describe("Run", () => { let run: Run; beforeEach(() => { diff --git a/ts/tests/docx/run/underlineTests.ts b/ts/tests/docx/run/underlineTests.ts new file mode 100644 index 0000000000..fa5f6230db --- /dev/null +++ b/ts/tests/docx/run/underlineTests.ts @@ -0,0 +1,37 @@ +import * as u from "../../../docx/run/underline"; +import {TextRun} from "../../../docx/run/text-run"; +import {assert} from "chai"; + +function jsonify(obj: Object) { + let stringifiedJson = JSON.stringify(obj); + return JSON.parse(stringifiedJson); +} + +describe.only("Underline", () => { + + describe("#constructor()", () => { + + it("should create a new Underline object", () => { + let underline = new u.Underline(); + let newJson = jsonify(underline); + assert.equal(newJson.rootKey, "w:u"); + }); + }); +}); + +describe.only("Underline", () => { + + describe("#constructor()", () => { + it("should create a new Underline object", () => { + let underline = new u.DashDotDotHeavyUnderline(); + let newJson = jsonify(underline); + assert.equal(newJson.rootKey, "w:u"); + }); + + it("should put value in attribute", () => { + let underline = new u.DashDotDotHeavyUnderline(); + let newJson = jsonify(underline); + assert.equal(newJson.rootKey, "w:u"); + }); + }); +});