added bullet
This commit is contained in:
@ -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<XmlComponent>;
|
||||
|
||||
constructor(type: string) {
|
||||
this.pStyle = new Array<XmlComponent>();
|
||||
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<XmlComponent>;
|
||||
@ -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;
|
||||
}
|
||||
}
|
12
ts/docx/paragraph/style.ts
Normal file
12
ts/docx/paragraph/style.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
|
||||
export class Style implements XmlComponent {
|
||||
private pStyle: Array<XmlComponent>;
|
||||
|
||||
constructor(type: string) {
|
||||
this.pStyle = new Array<XmlComponent>();
|
||||
this.pStyle.push(new Attributes({
|
||||
val: type
|
||||
}));
|
||||
}
|
||||
}
|
34
ts/docx/paragraph/unordered-list.ts
Normal file
34
ts/docx/paragraph/unordered-list.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import {Style} from "./style";
|
||||
|
||||
export class NumberProperties implements XmlComponent {
|
||||
private numPr: Array<XmlComponent>;
|
||||
|
||||
constructor() {
|
||||
this.numPr = new Array<XmlComponent>();
|
||||
this.numPr.push(new IndentLevel(0));
|
||||
this.numPr.push(new NumberId(1));
|
||||
}
|
||||
}
|
||||
|
||||
export class IndentLevel implements XmlComponent {
|
||||
private ilvl: Array<XmlComponent>;
|
||||
|
||||
constructor(level: number) {
|
||||
this.ilvl = new Array<XmlComponent>();
|
||||
this.ilvl.push(new Attributes({
|
||||
val: level
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class NumberId implements XmlComponent {
|
||||
private ilvl: Array<XmlComponent>;
|
||||
|
||||
constructor(id: number) {
|
||||
this.ilvl = new Array<XmlComponent>();
|
||||
this.ilvl.push(new Attributes({
|
||||
val: id
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
export class TapStop {
|
||||
export class TabStop {
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ export interface XmlComponent {
|
||||
}
|
||||
|
||||
interface AttributesProperties {
|
||||
val?: string;
|
||||
val?: any;
|
||||
color?: string;
|
||||
space?: string;
|
||||
sz?: string;
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
28
ts/tests/styleTest.ts
Normal file
28
ts/tests/styleTest.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/chai/chai.d.ts" />
|
||||
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 === "");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user