Allow indent to use other options than left and hanging

This is a breaking change. Existing code using indent will break when padding in the number for left.
This commit is contained in:
Jacob Wright
2017-09-16 12:31:31 -06:00
parent 19b122684c
commit 3a7f9053b9
8 changed files with 26 additions and 23 deletions

View File

@ -3,22 +3,25 @@ import { XmlAttributeComponent, XmlComponent } from "../xml-components";
interface IIndentAttributesProperties {
left?: number;
hanging?: number;
firstLine?: number;
start?: number;
end?: number;
}
class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties> {
protected xmlKeys = {
left: "w:left",
hanging: "w:hanging",
firstLine: "w:firstLine",
start: "w:start",
end: "w:end",
};
}
export class Indent extends XmlComponent {
constructor(left: number, hanging?: number) {
constructor(attrs: object) {
super("w:ind");
this.root.push(new IndentAttributes({
left: left,
hanging: hanging,
}));
this.root.push(new IndentAttributes(attrs));
}
}

View File

@ -134,8 +134,8 @@ export class Paragraph extends XmlComponent {
return this;
}
public indent(start: number, hanging?: number): Paragraph {
this.properties.push(new Indent(start, hanging));
public indent(attrs: object): Paragraph {
this.properties.push(new Indent(attrs));
return this;
}

View File

@ -241,7 +241,7 @@ describe("Paragraph", () => {
describe("#indent", () => {
it("should set the paragraph indent to the given values", () => {
paragraph.indent(720);
paragraph.indent({ left: 720 });
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [