added optional name parameter to style constructor
This commit is contained in:
@ -26,9 +26,12 @@ class StyleAttributes extends XmlAttributeComponent {
|
|||||||
|
|
||||||
export class Style extends XmlComponent {
|
export class Style extends XmlComponent {
|
||||||
|
|
||||||
constructor(attributes: IStyleAttributes) {
|
constructor(attributes: IStyleAttributes, name?: string) {
|
||||||
super("w:style");
|
super("w:style");
|
||||||
this.root.push(new StyleAttributes(attributes));
|
this.root.push(new StyleAttributes(attributes));
|
||||||
|
if (name) {
|
||||||
|
this.root.push(new Name(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public push(styleSegment: XmlComponent): void {
|
public push(styleSegment: XmlComponent): void {
|
||||||
@ -41,8 +44,8 @@ export class ParagraphStyle extends Style {
|
|||||||
private paragraphProperties: ParagraphProperties;
|
private paragraphProperties: ParagraphProperties;
|
||||||
private runProperties: RunProperties;
|
private runProperties: RunProperties;
|
||||||
|
|
||||||
constructor(styleId: string) {
|
constructor(styleId: string, name?: string) {
|
||||||
super({type: "paragraph", styleId: styleId});
|
super({type: "paragraph", styleId: styleId}, name);
|
||||||
this.paragraphProperties = new ParagraphProperties();
|
this.paragraphProperties = new ParagraphProperties();
|
||||||
this.runProperties = new RunProperties();
|
this.runProperties = new RunProperties();
|
||||||
this.root.push(this.paragraphProperties);
|
this.root.push(this.paragraphProperties);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
import { Formatter } from "../export/formatter";
|
import { Formatter } from "../export/formatter";
|
||||||
import { Styles } from "../styles";
|
import { Styles } from "../styles";
|
||||||
import { Style } from "../styles/style";
|
import { ParagraphStyle, Style } from "../styles/style";
|
||||||
import * as components from "../styles/style/components";
|
import * as components from "../styles/style/components";
|
||||||
|
|
||||||
describe("Styles", () => {
|
describe("Styles", () => {
|
||||||
@ -34,6 +34,20 @@ describe("Style", () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should set the name of the style, if given", () => {
|
||||||
|
const style = new Style({
|
||||||
|
type: "paragraph",
|
||||||
|
styleId: "myStyleId",
|
||||||
|
}, "Style Name");
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
|
||||||
|
{"w:name": [{_attr: {"w:val": "Style Name"}}]},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -68,3 +82,33 @@ describe("Style components", () => {
|
|||||||
expect(tree).to.deep.equal({"w:uiPriority": [{_attr: {"w:val": "123"}}]});
|
expect(tree).to.deep.equal({"w:uiPriority": [{_attr: {"w:val": "123"}}]});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe("ParagraphStyle", () => {
|
||||||
|
describe("#constructor", () => {
|
||||||
|
it("should set the style type to paragraph and use the given style id", () => {
|
||||||
|
const style = new ParagraphStyle("myStyleId");
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
|
||||||
|
{"w:pPr": [{_attr: {}}]},
|
||||||
|
{"w:rPr": []},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set the name of the style, if given", () => {
|
||||||
|
const style = new ParagraphStyle("myStyleId", "Style Name");
|
||||||
|
const tree = new Formatter().format(style);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:style": [
|
||||||
|
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
|
||||||
|
{"w:name": [{_attr: {"w:val": "Style Name"}}]},
|
||||||
|
{"w:pPr": [{_attr: {}}]},
|
||||||
|
{"w:rPr": []},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user