added #createParagraphStyle method to Styles

This commit is contained in:
felipe
2017-03-09 13:27:40 +01:00
parent ac7799a875
commit d93432678b
2 changed files with 34 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import { DocumentDefaults } from "./defaults";
import { LatentStyles } from "./latent-styles";
import { LatentStyleException } from "./latent-styles/exceptions";
import { LatentStyleExceptionAttributes } from "./latent-styles/exceptions/attributes";
import { ParagraphStyle } from "./style";
export class Styles extends XmlComponent {
@ -34,4 +35,10 @@ export class Styles extends XmlComponent {
element.clearVariables();
});
}
public createParagraphStyle(styleId: string, name?: string): ParagraphStyle {
const para = new ParagraphStyle(styleId, name);
this.push(para);
return para;
}
}

View File

@ -17,6 +17,33 @@ describe("Styles", () => {
assert.equal(newJson.rootKey, "w:styles");
});
});
describe("#createParagraphStyle", () => {
it("should create a new paragraph style and push it onto this collection", () => {
const ps = styles.createParagraphStyle("pStyleId");
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
expect(tree).to.deep.equal([{
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}},
{"w:pPr": [{_attr: {}}]},
{"w:rPr": []},
],
}]);
});
it("should set the paragraph name if given", () => {
const ps = styles.createParagraphStyle("pStyleId", "Paragraph Style");
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
expect(tree).to.deep.equal([{
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}},
{"w:name": [{_attr: {"w:val": "Paragraph Style"}}]},
{"w:pPr": [{_attr: {}}]},
{"w:rPr": []},
],
}]);
});
});
});
describe("Style", () => {