added border
This commit is contained in:
24
ts/docx/border.ts
Normal file
24
ts/docx/border.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import {P, Attributes} from "./xml-components";
|
||||
|
||||
class Border implements P {
|
||||
private bottom: Array<P>;
|
||||
|
||||
constructor() {
|
||||
this.bottom = new Array<P>();
|
||||
this.bottom.push(new Attributes({
|
||||
color: "auto",
|
||||
space: "1",
|
||||
val: "single",
|
||||
sz: "6"
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class ThematicBreak {
|
||||
private pBdr: Array<P>;
|
||||
|
||||
constructor() {
|
||||
this.pBdr = new Array<P>();
|
||||
this.pBdr.push(new Border());
|
||||
}
|
||||
}
|
@ -5,7 +5,9 @@ class Style {
|
||||
|
||||
constructor(type: string) {
|
||||
this.pStyle = new Array<P>();
|
||||
this.pStyle.push(new Attributes(type));
|
||||
this.pStyle.push(new Attributes({
|
||||
val: type
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +16,9 @@ class Alignment {
|
||||
|
||||
constructor(type: string) {
|
||||
this.jc = new Array<P>();
|
||||
this.jc.push(new Attributes(type));
|
||||
this.jc.push(new Attributes({
|
||||
val: type
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,22 @@ export interface P {
|
||||
|
||||
}
|
||||
|
||||
interface AttributesProperties {
|
||||
val?: string;
|
||||
color?: string;
|
||||
space?: string;
|
||||
sz?: string;
|
||||
}
|
||||
|
||||
export class Attributes implements P {
|
||||
private _attrs: Object;
|
||||
|
||||
constructor(value?: string) {
|
||||
this._attrs = {
|
||||
val: value
|
||||
};
|
||||
constructor(properties?: AttributesProperties) {
|
||||
this._attrs = properties
|
||||
|
||||
if (!properties) {
|
||||
this._attrs = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/chai/chai.d.ts" />
|
||||
import {Attributes} from "../docx/xml-components/p";
|
||||
import {Attributes} from "../docx/xml-components";
|
||||
import {assert} from "chai";
|
||||
|
||||
describe('Attribute', () => {
|
||||
@ -20,7 +20,9 @@ describe('Attribute', () => {
|
||||
});
|
||||
|
||||
it("should have val as defined with populated constructor", () => {
|
||||
var newAttrs = new Attributes("test");
|
||||
var newAttrs = new Attributes({
|
||||
val: "test"
|
||||
});
|
||||
var stringifiedJson = JSON.stringify(newAttrs);
|
||||
var newJson = JSON.parse(stringifiedJson);
|
||||
assert(newJson._attrs.val === "test");
|
||||
|
34
ts/tests/borderTest.ts
Normal file
34
ts/tests/borderTest.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/chai/chai.d.ts" />
|
||||
import {ThematicBreak} from "../docx/border";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
var stringifiedJson = JSON.stringify(obj);
|
||||
return JSON.parse(stringifiedJson);
|
||||
}
|
||||
|
||||
describe("Border", () => {
|
||||
|
||||
});
|
||||
|
||||
describe("ThematicBreak", () => {
|
||||
var thematicBreak: ThematicBreak;
|
||||
|
||||
beforeEach(() => {
|
||||
thematicBreak = new ThematicBreak();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Thematic Break with correct border properties", () => {
|
||||
var newJson = jsonify(thematicBreak);
|
||||
var attributes = {
|
||||
color: "auto",
|
||||
space: "1",
|
||||
val: "single",
|
||||
sz: "6"
|
||||
};
|
||||
assert(JSON.stringify(newJson.pBdr[0].bottom[0]._attrs) === JSON.stringify(attributes));
|
||||
});
|
||||
})
|
||||
});
|
@ -67,4 +67,13 @@ describe('Paragraph', () => {
|
||||
assert(newJson.p[1].pPr[1].pStyle[0]._attrs.val === "Title");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#center()", () => {
|
||||
it("should add center alignment to JSON", () => {
|
||||
paragraph.center();
|
||||
var newJson = jsonify(paragraph);
|
||||
|
||||
assert(newJson.p[1].pPr[1].jc[0]._attrs.val === "center");
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user